Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
much better help and descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Mar 29, 2024
1 parent 6c9e001 commit 793243c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 34 deletions.
Binary file modified bun.lockb
Binary file not shown.
132 changes: 99 additions & 33 deletions lib/get-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,63 +21,85 @@ import * as CMDFN from "lib/cmd-fns"
// | /package_examples/create | Create a new package example |

export const getProgram = (ctx: AppContext) => {
const cmd = new Command("tsci")
const cmd = new Command("tsci").description(
"Develop, test and manage tscircuit packages"
)

const authCmd = cmd.command("auth")
authCmd.command("login").action((args) => CMDFN.authLogin(ctx, args))
authCmd.command("logout").action((args) => CMDFN.authLogout(ctx, args))
cmd

const authCmd = cmd.command("auth").description("Login/logout")
authCmd
.command("login")
.description("Authenticate CLI, login to registry")
.action((args) => CMDFN.authLogin(ctx, args))
authCmd
.command("logout")
.description("Clear local authentication")
.action((args) => CMDFN.authLogout(ctx, args))

const configCmd = cmd.command("config")
const configCmd = cmd
.command("config")
.description("Manage the local tsci configuration")

configCmd
.command("reveal-location")
.description("Log the location of the config file")
.action((args) => CMDFN.configRevealLocation(ctx, args))
configCmd
.command("set-registry")
.description("Set the registry API url")
.requiredOption("--server <server>", "Registry URL")
.action((args) => CMDFN.configSetRegistry(ctx, args))
configCmd
.command("set-session")
.description("Set the session token manually")
.requiredOption("--session-token <session_token>", "Session Token")
.action((args) => CMDFN.configSetSession(ctx, args))
configCmd
.command("set-runtime")
.description("Set runtime to use, bun or node")
.requiredOption(
"--runtime <runtime>",
"Bun or node. Setting to bun generally doubles soupification speed."
)
.action((args) => CMDFN.configSetRuntime(ctx, args))
configCmd
.command("set-log-requests")
.description("Set whether to log requests to registry (noisy)")
.requiredOption("--log-requests", "Should log requests to registry")
.action((args) => CMDFN.configSetLogRequests(ctx, args))
configCmd
.command("print-config")
.description("Print the current config")
.action((args) => CMDFN.configPrintConfig(ctx, args))
configCmd.command("clear").action((args) => CMDFN.configClear(ctx, args))
configCmd
.command("clear")

const authSessionsCmd = authCmd.command("sessions")
.action((args) => CMDFN.configClear(ctx, args))

authSessionsCmd
.command("create")
.action((args) => CMDFN.authSessionsCreate(ctx, args))
authSessionsCmd
.command("list")
.action((args) => CMDFN.authSessionsList(ctx, args))
authSessionsCmd
.command("get")
.action((args) => CMDFN.authSessionsGet(ctx, args))
// const authSessionsCmd = authCmd.command("sessions")
// authSessionsCmd
// .command("create")
// .action((args) => CMDFN.authSessionsCreate(ctx, args))
// authSessionsCmd
// .command("list")
// .action((args) => CMDFN.authSessionsList(ctx, args))
// authSessionsCmd
// .command("get")
// .action((args) => CMDFN.authSessionsGet(ctx, args))

const packagesCmd = cmd.command("packages")
const packagesCmd = cmd.command("packages").description("Manage packages")

packagesCmd.command("list").action((args) => CMDFN.packagesList(ctx, args))
packagesCmd
.command("get")
.description("Get information about a package")
.option("--package-id <package_id>", "Package Id")
.option("--name <name>", "Package name")
.action((args) => CMDFN.packagesGet(ctx, args))
packagesCmd
.command("create")
.description("Create a new package")
.requiredOption("--name <name>", "Package name")
.option("--author-id <author_account_id>", "Author Id")
.option("--description <description>", "Package description")
Expand All @@ -87,14 +109,17 @@ export const getProgram = (ctx: AppContext) => {

packageReleases
.command("list")
.description("List all package releases for a package")
.requiredOption("--package-name <package_name>", "Package name")
.option("--verbose", "Verbose objects (includes uuids)")
.action((args) => CMDFN.packageReleasesList(ctx, args))
packageReleases
.command("get")
.action((args) => CMDFN.packageReleasesGet(ctx, args))
// packageReleases
// .command("get")
// .description("Get information about a package release")
// .action((args) => CMDFN.packageReleasesGet(ctx, args))
packageReleases
.command("create")
.description("Create a new package release")
.option(
"-p, --package-name-with-version <package_name_with_version>",
"Package name and version"
Expand All @@ -104,6 +129,7 @@ export const getProgram = (ctx: AppContext) => {
.action((args) => CMDFN.packageReleasesCreate(ctx, args))
packageReleases
.command("update")
.description("Update a package release")
.option(
"-p, --package-name-with-version <package_name_with_version>",
"Package name and version"
Expand All @@ -112,10 +138,13 @@ export const getProgram = (ctx: AppContext) => {
.option("--is-locked", "Lock the release")
.action((args) => CMDFN.packageReleasesUpdate(ctx, args))

const packageFiles = cmd.command("package_files")
const packageFiles = cmd
.command("package_files")
.description("Manage package release files")

packageFiles
.command("list")
.description("List all files for a package release")
.option(
"--package-name-with-version <package_name_with_version>",
"Package name with version"
Expand All @@ -126,9 +155,10 @@ export const getProgram = (ctx: AppContext) => {
)
.option("--package-release-id <package_release_id>", "Package Release Id")
.action((args) => CMDFN.packageFilesList(ctx, args))
packageFiles.command("get").action((args) => CMDFN.packageFilesGet(ctx, args))
// packageFiles.command("get").action((args) => CMDFN.packageFilesGet(ctx, args))
packageFiles
.command("download")
.description("Download a file from a package release")
.requiredOption(
"--package-name-with-version <package_name_with_version>",
"Package name and version"
Expand All @@ -141,6 +171,7 @@ export const getProgram = (ctx: AppContext) => {
.action((args) => CMDFN.packageFilesDownload(ctx, args))
packageFiles
.command("create")
.description("Create/upload a new package file")
.option(
"-p, --package-release-id <package_release_id>",
"Package Release Id"
Expand All @@ -152,42 +183,59 @@ export const getProgram = (ctx: AppContext) => {
.requiredOption("--file <file>", "File to upload")
.action((args) => CMDFN.packageFilesCreate(ctx, args))

packageFiles
.command("upload-directory")
.requiredOption("--dir <dir>", "Directory to upload")
.action((args) => CMDFN.packageFilesUploadDirectory(ctx, args))
// packageFiles
// .command("upload-directory")
// .description("Upload a directory of files to a package release")
// .requiredOption("--dir <dir>", "Directory to upload")
// .action((args) => CMDFN.packageFilesUploadDirectory(ctx, args))

const packageExamples = cmd.command("package_examples")
const packageExamples = cmd
.command("package_examples")
.description("Manage package release examples")

packageExamples
.command("list")
.description("List all examples for a package")
.requiredOption("--package-name-with-version <package_name_with_version>")
.action((args) => CMDFN.packageExamplesList(ctx, args))
packageExamples
.command("get")
.description("Get information about a package example")
.requiredOption("--package-example-id <package_example_id>")
.action((args) => CMDFN.packageExamplesGet(ctx, args))
packageExamples
.command("create")
.description("Create a new package example")
.requiredOption("--package-name-with-version <package_name_with_version>")
.requiredOption("--file <file>")
.option("--export <export>", "Name of export to soupify")
.action((args) => CMDFN.packageExamplesCreate(ctx, args))

cmd
.command("publish")
.option("--increment", "Increase patch version")
.description("Publish a package release to the tscircuit registry")
.option("--increment", "Increase patch version", true)
.option("--patch", "Increase patch version")
.option("--lock", "Lock the release after publishing to prevent changes")
.action((args) => CMDFN.publish(ctx, args))

cmd.command("version").action((args) => CMDFN.version(ctx, args))
cmd
.command("version")
.description("Print current version")
.action((args) => CMDFN.version(ctx, args))

cmd.command("login").action((args) => CMDFN.authLogin(ctx, args))
cmd.command("logout").action((args) => CMDFN.authLogout(ctx, args))
cmd
.command("login")
.description("Authenticate CLI, login to registry")
.action((args) => CMDFN.authLogin(ctx, args))
cmd
.command("logout")
.description("Clear your local authentication")
.action((args) => CMDFN.authLogout(ctx, args))

cmd
.command("soupify")
.description("Convert an example file to tscircuit soup")
.requiredOption("--file <file>", "Input example files")
.option(
"--export <export_name>",
Expand All @@ -197,12 +245,14 @@ export const getProgram = (ctx: AppContext) => {

cmd
.command("dev")
.description("Run development server in current directory")
.option("--cwd <cwd>", "Current working directory")
.option("--port <port>", "Port to run dev server on")
.action((args) => CMDFN.dev(ctx, args))

cmd
.command("init")
.description("Initialize a new tscircuit project")
.option("--name <name>", "Name of the project")
.option(
"--runtime <runtime>",
Expand All @@ -216,6 +266,7 @@ export const getProgram = (ctx: AppContext) => {

cmd
.command("add")
.description("Add a package from the tscircuit registry")
.argument(
"<packages...>",
"Packages to install from registry.tscircuit.com, optionally with version"
Expand All @@ -225,11 +276,13 @@ export const getProgram = (ctx: AppContext) => {

cmd
.command("remove")
.description("Remove/uninstall a package")
.argument("<packages...>", "Packages to remove")
.action((packages, flags) => CMDFN.remove(ctx, { packages, flags }))

cmd
.command("install")
.description("Install a package from the tscircuit registry")
.argument(
"<packages...>",
"Packages to install from registry.tscircuit.com, optionally with version"
Expand All @@ -239,13 +292,17 @@ export const getProgram = (ctx: AppContext) => {

cmd
.command("uninstall")
.description("Uninstall a package")
.argument("<packages...>", "Packages to uninstall")
.action((packages, flags) => CMDFN.install(ctx, { packages, flags }))

const devServerCmd = cmd.command("dev-server")
const devServerCmd = cmd
.command("dev-server")
.description("(Advanced) Manage the development server")

devServerCmd
.command("upload")
.description("Upload a directory to the dev server")
.option(
"--dir <dir>",
"Directory to upload (defaults to current directory)"
Expand All @@ -254,7 +311,16 @@ export const getProgram = (ctx: AppContext) => {
.option("-p, --port", "Port dev server is running on (default: 3020)")
.action((args) => CMDFN.devServerUpload(ctx, args))

cmd.command("open").action((args) => CMDFN.open(ctx, args))
cmd
.command("open")
.description("Open browser to package on tscircuit registry")
.action((args) => CMDFN.open(ctx, args))

function recursiveUnhelp(cmd: Command) {
cmd.helpCommand(false)
cmd.commands.forEach((c) => recursiveUnhelp(c))
}
recursiveUnhelp(cmd)

return cmd
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"minimist": "^1.2.8",
"node-persist": "^4.0.1",
"open": "^10.1.0",
"perfect-cli": "^1.0.19",
"perfect-cli": "1.0.20",
"prompts": "^2.4.2",
"react": "^18.2.0",
"semver": "^7.6.0",
Expand Down

0 comments on commit 793243c

Please sign in to comment.