Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub-command options that are dynamically enabled depending on a parent command option #329

Closed
nchammas opened this issue Apr 17, 2015 · 1 comment

Comments

@nchammas
Copy link
Contributor

I'm writing a tool that launches clusters in a choice of different cloud providers like AWS EC2 and Google Compute Engine. Each cloud provider has options specific to it, but there are also options not specific to any provider.

To illustrate, here's a rough example of what I'm imagining the --help text for the tool will look like:

Usage:
    acme-launcher [--version]
                  [--help]
                  [--config <path>]
                  [--provider <name>]
                  <command> [<args>]

<command>:
    launch          <cluster-name>

                    # Shared options.
                    [--slaves <num>]
                    [--install-ganglia|--no-install-ganglia]
                    [--identity-file <path>]

                    # EC2-specific options.
                    [--ec2-key-name <name>]
                    [--ec2-instance-initiated-shutdown-behavior <type>]
                    [--ec2-iam-role <name>]

                    # GCE-specific options.
                    [--gce-machine-type <type>]
                    [--gce-disk-auto-delete <type>]
                    [--gce-target-pool <name>]

    destroy         <cluster-name>

Basically, acme-launcher has some top-level options. Then, depending on what --provider is chosen -- ec2 or gce -- different options for the launch sub-command become available. As noted earlier, there are some options like --install-ganglia that apply regardless of the chosen provider.

I'm thinking the launch command will map to a Python function which will process some of the top-level options like --provider. Then, depending on the chosen provider, it will dispatch to the appropriate sub-command function (launch_ec2, launch_gce, etc.) to continue the job.

From a command-line UI perspective, I think this is roughly how Docker Machine works. Docker Machine will launch any kind of resource you specify -- a VM, EC2 instance, GCE instance, etc. -- and, depending on the chosen resource provider, accept additional options.

Is this kind of CLI design a good idea for this situation? And, more to the point of this project, can it be done in Click?

@nchammas
Copy link
Contributor Author

I ended up just exposing all the provider-specific options all the time, and just doing run-time checks to ignore or error out when the wrong options are used.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant