Comments (3)
I'm not quite sure the reason why you are using groups in this example here. Why do you want to group subcommands?
In my opinion, the commands themselves act like groups, especially in this example. You can achieve what you're looking for if you instead just use the commands and not involve groups:
type Cmd1 struct {
Opt1 string `long:"opt1" description:"first opt" required:"true"`
Opt2 int `long:"opt2" description:"second opt" default:"10"`
}
type Cmd2 struct {
OptA string `long:"optA" description:"opt a" default:":8080"`
OptB string `long:"optB" description:"opt b" default:"debug"`
}
type MainCmd struct {
CmdA Cmd1 `command:"cmd1"`
CmdB Cmd2 `command:"cmd2"`
}
Even simpler:
type MainCmd struct {
Cmd1 struct {
Opt1 string `long:"opt1" description:"first opt" required:"true"`
Opt2 int `long:"opt2" description:"second opt" default:"10"`
} `command:"cmd1"`
Cmd2 struct {
OptA string `long:"optA" description:"opt a" default:":8080"`
OptB string `long:"optB" description:"opt b" default:"debug"`
} `command:"cmd2"`
}
Let me know if this helps.
from go-flags.
Thanks for the help. I tried the suggested approach; however, it did not give me the expected output. The help message I have is :
Available commands:
cmd1
cmd2
The example I provided is just a simple piece of workable code to demonstrate my basic need. I think there are many reasons people want to group or categorize subcommands, especially for organizing the help message better. For example, in some system setting related commands, we may want the help message organize the commands as follows:
Troubleshooting and Debugging Commands:
describe Show details
logs Print the logs
exec Execute a commandSettings Commands:
label Update the labels
annotate Update the annotations
Hope this can answer your concerns.
from go-flags.
Hello !
I'm allowing myself to redirect you to the last comment I posted in this issue: #380 .
It advertises a project I did work on a lot, and by which you might be interested.
The problem you have here is solved by the advertised project, and much more.
from go-flags.
Related Issues (20)
- Add a working completion example for 'zsh' shell
- Add a man generator for markup (ronn-style)
- Need proper documentation on how to correctly handle errors HOT 13
- Can flags be used to parse command line arguments from 'go test' ? HOT 2
- Is this an abandoned project?
- Is this an abandoned project? HOT 21
- Program description
- A little leverage
- help format default posix in windows, I don't want to use -tags=forceposix, let them use -tags=forcewindows HOT 2
- Fix CVE-2022-29526 vulnerability caused by golang.org/x/sys? HOT 2
- Is it possible to have dynamically generated help descriptions?
- Passing options as argument to other options without using positional-args HOT 1
- custom type positional argument ValueValidator implementation is ignored
- How do I add a flag and pass the value there?
- Multiple short options are not detected with `IgnoreUnknown` flag.
- Support unicode chars in WriteHelp
- Manage unset flag/environment variable HOT 3
- group.go mixed left quote (`) with single quote (') HOT 1
- Is this the best (or only) way to figure out which subcommands have been used?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-flags.