Skip to content

Support concatenated short flag syntax (-c100) #17

@mfridman

Description

@mfridman

Currently, short flag aliases only support -c 100 and -c=100 syntax. The concatenated form -c100 (no space or equals) fails with:

error: command "rewrap": flag provided but not defined: -c100

This is because short aliases are registered as regular flags in a flag.FlagSet via combineFlags(), and Go's flag.FlagSet.Parse() does not support the concatenated form.

Feasibility

This is doable with a small arg-rewriting pass in xflag.ParseToEnd. The FlagSet is already available there, so the approach would be:

  1. Scan args for patterns like -X<value> where X is a known single-letter flag that expects a value
  2. Expand -c100 into -c 100 before passing to flag.Parse()
  3. Use the FlagSet to distinguish -c100 (short flag c with value 100) from -verbose (long flag named verbose) by checking if a single-char flag exists
  4. Skip boolean flags since they don't take values (and -vn style combining is out of scope)

The scope is contained -- mostly changes to xflag/parse.go with maybe a small helper.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions