Comments (5)
Actually there is one solution that works now:
type CreateUpdateOptions struct {
CPU float64
Memory int
Instances int
Name string
Build string
Revision string
Extension string
User string
}
func NewCreateUpdateOptions(cmd *kingpin.CmdClause) *CreateUpdateOptions {
options := &CreateUpdateOptions{}
cmd.Flag("cpu", "cpu share").Short('c').Required().FloatVar(&options.CPU)
cmd.Flag("mem", "mem share (integer MB)").Short('m').Required().IntVar(&options.Memory)
cmd.Flag("instances", "instance count").Short('i').Required().IntVar(&options.Instances)
cmd.Arg("app_name", "application name").Required().StringVar(&options.Name)
cmd.Arg("app_build", "application build").Required().StringVar(&options.Build)
cmd.Arg("app_revision", "application revision name").Required().StringVar(&options.Revision)
cmd.Arg("app_extension", "application file extension").Required().StringVar(&options.Extension)
cmd.Arg("app_run_as", "application run as user").Required().StringVar(&options.User)
return options
}
var (
app = kingpin.New("myapp", "help")
create = app.Command("create", "initial create/deploy of an app")
createOptions = NewCreateUpdateOptions(create)
update = app.Command("update", "update definition of an app (automatically deploys new definition)")
updateOptions = NewCreateUpdateOptions(update)
)
from kingpin.
I could change them from sub-commands to a single command with a --comand flag...
It would clean up the implementation (greatly) but would not improve the user experience (which is clearly ugly enough as it stands...)
from kingpin.
Hmm, yes. I've pondered how to do bundles of flags backed by a struct, which this would be a good use case for, but I haven't come up with an elegant solution. Any ideas?
The other option is to restructure your commands so there is a parent command, eg. "apply":
apply = app.Command("apply", "apply changes to an app")
create_cpu = apply.Flag("cpu", "cpu share").Short('c').Required().Float()
create_mem = apply.Flag("mem", "mem share (integer MB)").Short('m').Required().Int()
create_instances = apply.Flag("instances", "instance count").Short('i').Required().Int()
create_app_name = apply.Arg("app_name", "application name").Required().String()
create_app_build = apply.Arg("app_build", "application build").Required().String()
create_app_revision = apply.Arg("app_revision", "application revision name").Required().String()
create_app_extension = apply.Arg("app_extension", "application file extension").Required().String()
create_app_run_as = apply.Arg("app_run_as", "application run as user").Required().String()
create = apply.Command("create", "initial create/deploy of an app")
update = apply.Command("update", "update definition of an app (automatically deploys new definition)")
It's not great though :\
from kingpin.
Actually sorry, that only works for flags anyway :(
from kingpin.
Thank you!
from kingpin.
Related Issues (20)
- help don't show all default values HOT 2
- Unexpected "doubling" behavior when trying to test output HOT 1
- gmake: *** [Makefile.common:193: common-unused] Error 1 HOT 1
- Wishlist: release guesswidth as its own separate package HOT 3
- postitive integers HOT 1
- get list of values in flag HOT 1
- Readme uses `OverrideDefaultFromEnvar` which is deprecated
- Documentation of public methods on private structs is hidden HOT 2
- HintAction can break the argument order HOT 1
- "Argument list too long " The flag length limit? HOT 1
- There is a problem with flag and kingpin colleagues
- Bad boolean Flag value is interpreted as Argument HOT 1
- (Contributions only) updated
- Expand DurationVar to support days and weeks
- [bug]bool parameter, the default is true, always true,Cannot be controlled by parameters HOT 1
- Create a new tag please? HOT 4
- Regression in parsing Duration flag HOT 5
- values.go:142:25: undefined: str2duration.Str2Duration HOT 6
- Dependency Dashboard
- Enums() type doesn't tab complete
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 kingpin.