Skip to content

Commit

Permalink
Merge pull request #747 from rsteube/add-actionpositional
Browse files Browse the repository at this point in the history
added ActionPositional
  • Loading branch information
rsteube authored Mar 31, 2023
2 parents a831835 + ed857ac commit 5d6bf9f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions defaultActions.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,26 @@ func manDescriptions(c Context) (descriptions map[string]string) {
}
return
}

// ActionPositional completes positional arguments for given command ignoring `--` (dash).
// TODO: experimental - likely gives issues with preinvoke (does not have the full args)
//
// carapace.Gen(cmd).DashAnyCompletion(
// carapace.ActionPositional(cmd),
// )
func ActionPositional(cmd *cobra.Command) Action {
return ActionCallback(func(c Context) Action {
if cmd.ArgsLenAtDash() < 0 {
return ActionMessage("only allowed for dash arguments [ActionPositional]")
}

c.Args = cmd.Flags().Args()
entry := storage.get(cmd)

a := entry.positionalAny
if index := len(c.Args); index < len(entry.positional) {
a = entry.positional[len(c.Args)]
}
return a.Invoke(c).ToA()
})
}

0 comments on commit 5d6bf9f

Please sign in to comment.