Skip to content

CLI: an option value such as --name -g is parsed as the mode flag #422

Closed

Description

@runkids

Found while reviewing #421; pre-existing argument parsing shared by several commands, not changed there.

Problem

skillshare link <path> --name <value> (and other commands that go through parseModeArgs first, see loadLinkScope in cmd/skillshare/link.go) run the mode-flag parser over the whole argument list before the command parses its own options. A --name value that looks like a mode flag is therefore consumed as the mode:

skillshare link ~/code/dev-skills --name -g
# -g is taken as "global mode"; --name is left without a value (or takes the next argument)

The same happens for -p. -- only protects arguments after it, so --name -- -g does not help either because --name then has no value.

Expected

A value that follows --name (or any option that takes a value) is never interpreted as a mode flag. Either parseModeArgs must skip the value slot of value-taking options, or commands must parse their own options before extracting the mode flags.

Where

  • cmd/skillshare/link.go loadLinkScope → parseModeArgs
  • any other command that calls parseModeArgs on the raw argument list before its own option loop (rg -n "parseModeArgs(" cmd/skillshare)

Acceptance

  • skillshare link <path> --name -g creates a link named -g in the mode chosen by the real mode flag (or auto mode), and skillshare unlink -- -g removes it.
  • A CLI test per affected command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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