Skip to content

Commit

Permalink
Disallow excess arguments in CLI (#30631)
Browse files Browse the repository at this point in the history
Disallow excess argument in the CLI to prevent accidental misuse and make it possible to deprecate options in the future. I noticed this when I tried to use arguments with `npx convex dev --run "messages:list" '{"arg": 1}'` and they were ignored; I was using the command wrong, we should help out with that.

We'll want to call this out in upgrade notes.

GitOrigin-RevId: f6b18bdee1ffabf556172488b909714689b5aaf8
  • Loading branch information
thomasballinger authored and Convex, Inc. committed Oct 11, 2024
1 parent 1bc09f8 commit cf94a38
Show file tree
Hide file tree
Showing 19 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const codegen = new Command("codegen")
.description(
"Generate types in `convex/_generated/` based on the current contents of `convex/`.",
)
.allowExcessArguments(false)
.option(
"--dry-run",
"Print out the generated configuration to stdout instead of writing to convex directory",
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/convexExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const convexExport = new Command("export")
"Export data, and optionally file storage, from your Convex deployment to a ZIP file.\n" +
"By default, this exports from your dev deployment.",
)
.allowExcessArguments(false)
.requiredOption(
"--path <zipFilePath>",
"Exports data into a ZIP file at this path, which may be a directory or unoccupied .zip path",
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/convexImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const convexImport = new Command("import")
" For a single table: `npx convex import --table tableName file.json`\n\n" +
"By default, this imports into your dev deployment.",
)
.allowExcessArguments(false)
.addOption(
new Option(
"--table <table>",
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const DASHBOARD_HOST = process.env.CONVEX_PROVISION_HOST

export const dashboard = new Command("dashboard")
.description("Open the dashboard in the browser")
.allowExcessArguments(false)
.option(
"--no-open",
"Don't automatically open the dashboard in the default browser",
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const data = new Command("data")
" List documents in a table: `npx convex data tableName`\n\n" +
"By default, this inspects your dev deployment.",
)
.allowExcessArguments(false)
.argument("[table]", "If specified, list documents in this table.")
.addOption(
new Option(
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const deploy = new Command("deploy")
"Deploy to your deployment. By default, this deploys to your prod deployment.\n\n" +
"Deploys to a preview deployment if the `CONVEX_DEPLOY_KEY` environment variable is set to a Preview Deploy Key.",
)
.allowExcessArguments(false)
.option("-v, --verbose", "Show full listing of changes")
.option(
"--dry-run",
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Deployment = {

export const deployments = new Command("deployments")
.description("List deployments associated with a project")
.allowExcessArguments(false)
.action(async () => {
const ctx = oneoffContext();
const { projectConfig: config } = await readProjectConfig(ctx);
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const dev = new Command("dev")
" 3. Runs the provided function (if `--run` is used)\n" +
" 4. Watches for file changes, and repeats step 2\n",
)
.allowExcessArguments(false)
.option("-v, --verbose", "Show full listing of changes")
.addOption(
new Option(
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { bigBrainFetch, deprecationCheckWarning } from "./lib/utils/utils.js";

export const docs = new Command("docs")
.description("Open the docs in the browser")
.allowExcessArguments(false)
.option("--no-open", "Print docs URL instead of opening it in your browser")
.action(async (options) => {
const ctx = oneoffContext();
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/functionSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const functionSpec = new Command("function-spec")
"List argument and return values to your Convex functions.\n\n" +
"By default, this inspects your dev deployment.",
)
.allowExcessArguments(false)
.addOption(new Option("--file", "Output as JSON to a file."))
.addDeploymentSelectionOptions(
actionDescription("Read function metadata from"),
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const cwd = path.basename(process.cwd());
// `npx convex dev --once --configure=new` replaces it.
export const init = new Command("init")
.description("Initialize a new Convex project in the current directory")
.allowExcessArguments(false)
.addOption(
new Option(
"--project <name>",
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { checkAuthorization, performLogin } from "./lib/login.js";

export const login = new Command("login")
.description("Login to Convex")
.allowExcessArguments(false)
.option(
"--device-name <name>",
"Provide a name for the device being authorized",
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { recursivelyDelete } from "./lib/fsUtils.js";

export const logout = new Command("logout")
.description("Log out of Convex on this machine")
.allowExcessArguments(false)
.action(async () => {
const ctx = oneoffContext();

Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const logs = new Command("logs")
.description(
"Stream function logs from your Convex deployment.\nBy default, this streams from your project's dev deployment.",
)
.allowExcessArguments(false)
.option(
"--history [n]",
"Show `n` most recent logs. Defaults to showing all available logs.",
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/network_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const ipFamilyNames = { 4: "ipv4", 6: "ipv6", 0: "auto" } as const;

export const networkTest = new Command("network-test")
.description("Run a network test to Convex's servers")
.allowExcessArguments(false)
.addOption(
new Option(
"--timeout <timeout>",
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/reinit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const reinit = new Command("reinit")
.description(
"Reinitialize a Convex project in the local directory if you've lost your convex.json file",
)
.allowExcessArguments(false)
.addOption(
new Option(
"--team <team_slug>",
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ensureHasConvexDependency } from "./lib/utils/utils.js";

export const run = new Command("run")
.description("Run a function (query, mutation, or action) on your deployment")
.allowExcessArguments(false)
.argument(
"functionName",
"identifier of the function to run, like `listMessages` or `dir/file:myFunction`",
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/typecheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const typecheck = new Command("typecheck")
.description(
"Run TypeScript typechecking on your Convex functions with `tsc --noEmit`.",
)
.allowExcessArguments(false)
.action(async () => {
const ctx = oneoffContext();
const { configPath, config: localConfig } = await readConfig(ctx, false);
Expand Down
1 change: 1 addition & 0 deletions npm-packages/convex/src/cli/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { loadPackageJson } from "./lib/utils/utils.js";

export const update = new Command("update")
.description("Print instructions for updating the convex package")
.allowExcessArguments(false)
.action(async () => {
const ctx = oneoffContext();
let updateInstructions = "npm install convex@latest\n";
Expand Down

0 comments on commit cf94a38

Please sign in to comment.