Problem
main.go passes os.Args straight to urfave/cli v1 (cmd/clickhouse-backup/main.go:918):
if err := cliapp.Run(os.Args); err != nil {
urfave/cli v1 stops flag parsing at the first positional argument. So:
clickhouse-backup download my_backup --tables db.huge_table
silently ignores --tables and downloads the whole backup. Same for every command flag placed after the positional arg (upload x --delete-source, restore x --rm, etc.). Nothing warns the user; with download this can mean pulling multi-TiB instead of one table — a costly and confusing failure mode, and a very natural way for a human to type the command.
Proposal
Normalize argv before handing it to cli v1: normalizeArgs reorders arguments so recognized flags (with their values) come before positional args, per-command:
- knows which flags are boolean (via
collectBoolFlagNames over the command's flag set) so it doesn't wrongly consume a positional as a flag value,
- handles
--flag=value, --flag value, short flags, and the -- terminator,
- idempotent: when flags already come first (current documented usage), argv is unchanged,
- unknown tokens are left in place, so behavior for invalid input is unchanged.
I have a PR ready to submit with a table-driven test covering the orderings.
Problem
main.gopassesos.Argsstraight to urfave/cli v1 (cmd/clickhouse-backup/main.go:918):urfave/cli v1 stops flag parsing at the first positional argument. So:
silently ignores
--tablesand downloads the whole backup. Same for every command flag placed after the positional arg (upload x --delete-source,restore x --rm, etc.). Nothing warns the user; withdownloadthis can mean pulling multi-TiB instead of one table — a costly and confusing failure mode, and a very natural way for a human to type the command.Proposal
Normalize argv before handing it to cli v1:
normalizeArgsreorders arguments so recognized flags (with their values) come before positional args, per-command:collectBoolFlagNamesover the command's flag set) so it doesn't wrongly consume a positional as a flag value,--flag=value,--flag value, short flags, and the--terminator,I have a PR ready to submit with a table-driven test covering the orderings.