Giter VIP home page Giter VIP logo

Comments (5)

alecthomas avatar alecthomas commented on July 25, 2024 1

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.

wwalker avatar wwalker commented on July 25, 2024

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.

alecthomas avatar alecthomas commented on July 25, 2024

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.

alecthomas avatar alecthomas commented on July 25, 2024

Actually sorry, that only works for flags anyway :(

from kingpin.

wwalker avatar wwalker commented on July 25, 2024

Thank you!

from kingpin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.