Passing options as argument to other options without using positional-args
Closed this issue · 1 comments
delay-lama commented
Is it possible to achieve something like pacman package manager syntax (pacman -S -y -u
), where options consist of top-level option (-S) and context (-y -u)?
I tried to create separate struct for context and do nested parsing in function callback of top-level option:
actions_s.Sync = func(context_sl []string) {
args_sl, err := flags.ParseArgs(&context_s, context_sl)
if err == nil || err == flags.ErrHelp {
fmt.Println(args_sl)
} else {
fmt.Println(err)
}
}
But this didn't work, any options after the first top-level option were treated like separate top-level options, not like the context for the first one. As I understand, positional-args field enforces specific order on options, but I need that context can be specified in any order, so -S -y -u
will be equal to -S -u -y
.
delay-lama commented
Nvm, I have read the manual and figured out that I overcomplicated the task, and used subcommands