Skip to content

flags after positional args are silently ignored (urfave/cli v1) — e.g. 'download backup --tables db.t' downloads everything #1459

Description

@minguyen9988

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions