diff --git a/README.md b/README.md index d67a137..70195ee 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ memberstack whoami ## Usage ```bash -memberstack [options] +memberstack [subcommand] [params] [options] ``` ## Install Agent Skill (Optional) diff --git a/src/commands/apps.ts b/src/commands/apps.ts index b7b6915..f01e9d1 100644 --- a/src/commands/apps.ts +++ b/src/commands/apps.ts @@ -37,7 +37,9 @@ const APP_FIELDS = ` allowMemberSelfDelete `; -export const appsCommand = new Command("apps").description("Manage apps"); +export const appsCommand = new Command("apps") + .usage(" [options]") + .description("Manage apps"); appsCommand .command("current") diff --git a/src/commands/auth.ts b/src/commands/auth.ts index e54065c..420f896 100644 --- a/src/commands/auth.ts +++ b/src/commands/auth.ts @@ -110,9 +110,9 @@ const findAvailablePort = (): Promise => server.on("error", reject); }); -export const authCommand = new Command("auth").description( - "Manage OAuth authentication" -); +export const authCommand = new Command("auth") + .usage(" [options]") + .description("Manage OAuth authentication"); authCommand .command("login") diff --git a/src/commands/custom-fields.ts b/src/commands/custom-fields.ts index 464a1da..fad47af 100644 --- a/src/commands/custom-fields.ts +++ b/src/commands/custom-fields.ts @@ -32,9 +32,9 @@ const CUSTOM_FIELD_FIELDS = ` tableOrder `; -export const customFieldsCommand = new Command("custom-fields").description( - "Manage custom fields" -); +export const customFieldsCommand = new Command("custom-fields") + .usage(" [options]") + .description("Manage custom fields"); customFieldsCommand .command("list") diff --git a/src/commands/members.ts b/src/commands/members.ts index e3e1eec..c94968f 100644 --- a/src/commands/members.ts +++ b/src/commands/members.ts @@ -194,9 +194,9 @@ const collect = (value: string, previous: string[]): string[] => [ value, ]; -export const membersCommand = new Command("members").description( - "Manage members" -); +export const membersCommand = new Command("members") + .usage(" [options]") + .description("Manage members"); membersCommand .command("list") diff --git a/src/commands/plans.ts b/src/commands/plans.ts index f3ba5b9..246635c 100644 --- a/src/commands/plans.ts +++ b/src/commands/plans.ts @@ -140,7 +140,9 @@ const parseRedirects = (entries: string[]): Record => { return redirects; }; -export const plansCommand = new Command("plans").description("Manage plans"); +export const plansCommand = new Command("plans") + .usage(" [options]") + .description("Manage plans"); plansCommand .command("list") diff --git a/src/commands/records.ts b/src/commands/records.ts index fffd602..bd373ec 100644 --- a/src/commands/records.ts +++ b/src/commands/records.ts @@ -72,9 +72,9 @@ const resolveTableId = async (tableKey: string): Promise => { return result.dataTable.id; }; -export const recordsCommand = new Command("records").description( - "Manage data table records" -); +export const recordsCommand = new Command("records") + .usage(" [options]") + .description("Manage data table records"); recordsCommand .command("create") diff --git a/src/commands/skills.ts b/src/commands/skills.ts index f54fe7c..ccbb04c 100644 --- a/src/commands/skills.ts +++ b/src/commands/skills.ts @@ -12,9 +12,9 @@ const runSkillsCommand = async (args: string[]): Promise => { await execAsync(`npx skills ${args.join(" ")}`); }; -export const skillsCommand = new Command("skills").description( - "Manage Memberstack skills" -); +export const skillsCommand = new Command("skills") + .usage(" [options]") + .description("Manage Memberstack skills"); skillsCommand .command("add") diff --git a/src/commands/tables.ts b/src/commands/tables.ts index 5a60ce6..dfa8918 100644 --- a/src/commands/tables.ts +++ b/src/commands/tables.ts @@ -61,9 +61,9 @@ const TABLE_FIELDS = ` } `; -export const tablesCommand = new Command("tables").description( - "Manage data tables" -); +export const tablesCommand = new Command("tables") + .usage(" [options]") + .description("Manage data tables"); tablesCommand .command("list") diff --git a/src/lib/program.ts b/src/lib/program.ts index e17fd0d..7d5d0b1 100644 --- a/src/lib/program.ts +++ b/src/lib/program.ts @@ -1,10 +1,24 @@ import { Command } from "commander"; +declare const __VERSION__: string | undefined; +const version = typeof __VERSION__ !== "undefined" ? __VERSION__ : "dev"; + export const program = new Command(); program - .name("Memberstack CLI") + .name("memberstack") + .usage(" [subcommand] [params] [options]") .description("Manage your Memberstack account from the terminal.") - .version("0.0.0") + .version(version) .option("-j, --json", "Output raw JSON instead of formatted tables") - .option("--live", "Use live environment instead of sandbox"); + .option("--live", "Use live environment instead of sandbox") + .addHelpText( + "after", + ` +Examples: + $ memberstack auth login + $ memberstack members list --json + $ memberstack plans create --name "Pro Plan" + $ memberstack records find users --where "status equals active" + $ memberstack skills add memberstack-cli` + ); diff --git a/tsup.config.ts b/tsup.config.ts index b571195..dd87bd0 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -1,5 +1,8 @@ +import { readFileSync } from "node:fs"; import { defineConfig } from "tsup"; +const pkg = JSON.parse(readFileSync("./package.json", "utf-8")); + export default defineConfig({ entry: ["src/index.ts"], format: ["esm"], @@ -7,4 +10,7 @@ export default defineConfig({ js: "#!/usr/bin/env node", }, clean: true, + define: { + __VERSION__: JSON.stringify(pkg.version), + }, });