Skip to content

Support short flag batches that take args for external completions #5923

Closed

Description

@drbrain

Related problem

With an extern completion for git commit:

module completions {
  export extern "git commit" [
    -a
    -m: string
  ]
}

use completions *

I want to make a fixup commit that I will git rebase -i into the proper location on my branch.

nushell complains that "Batches of short flags can't take arguments."

❯ git commit -amf
Error: nu::parser::short_flag_arg_cant_take_arg (link)

  × Batches of short flags can't take arguments.
   ╭─[entry #441:1:1]
 1 │ git commit -amf
   ·              ┬
   ·              ╰── short flag batches can't take args
   ╰────

But ^git allows this:

❯ ^git commit -amf
[drbrain/some-branch abcdef01] f
 1 file changed, 1 insertion(+)

Describe the solution you'd like

When a short flag is in trailing position it accepts arguments as git does, or sort(1) does:

❯ echo "a 2\nb 1" | ^sort -hk2
b 1
a 2
❯ echo "a 2\nb 1" | ^sort -hk1
a 2
b 1

Describe alternatives you've considered

I can work around this by adding a space between m and my message ("f")

Additional context and details

No response

Activity

  1. meskill commented on Dec 23, 2022

    @meskill
    Contributor

    Is nushell team going to implement this? Or it's still in discussion phase.

  2. sholderbach commented on Dec 23, 2022

    @sholderbach
    Member

    We recently landed #7527 that passes unknown flag combinations through to the underlying external properly. So this should work with git and friends in the next release.

    For commands defined in nushell directly we don't have a clear strategy yet but would be open to discussion!

  3. MariaSolOs commented on Apr 7, 2023

    @MariaSolOs
    Contributor

    @sholderbach Could I work on a PR that doesn't error if the batch of short flags has a single flag that requires an argument? :)

  4. sholderbach commented on Apr 7, 2023

    @sholderbach
    Member

    Could I work on a PR that doesn't error if the batch of short flags has a single flag that requires an argument? :)

    This sounds like a great place to improve Quality-of-life! So we are happy if you give this a go. Our flag story is certainly not trivial as we have to support both flexibility in externs and our typed signatures.

    From your mentioned scope and the minimal example in the issue description it sounds self-contained and implementable with the information we have at parse time.

    What I am unsure about: Is there a reason why @kubouch has added a test (https://github.com/nushell/nushell/pull/7527/files#diff-36b8362d860bbb63b9805d1d0bbbcb5db404419d6f4e657f82a4dd8f3cadb211R42-R48) that documents the rejection of batched flags with an argument value.

  5. MariaSolOs commented on Apr 7, 2023

    @MariaSolOs
    Contributor

    Amazing, thanks @sholderbach! And yes, it would be insightful to know more about why this was explicitly disallowed.

  6. kubouch commented on Apr 9, 2023

    @kubouch
    Contributor

    I added the test just to cover the way it used to work, it can be changed.

  7. added this to the v0.79.0 milestone on Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

category:enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions