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

Dynamically generate subcommands list #23

Open
macunha1 opened this issue Apr 7, 2022 · 0 comments
Open

Dynamically generate subcommands list #23

macunha1 opened this issue Apr 7, 2022 · 0 comments

Comments

@macunha1
Copy link

macunha1 commented Apr 7, 2022

Context: (If I got it right) the current implementation expects a centralized definition of commands and subcommands. When implementing CLI with multiple nested commands; like these AWS or GCP CLI tools (e.g.: gcloud compute instances describe [...]), that file can become HUGE.

I would love to have each command defined in its own configuration YAML file and then feed these configurations back to slap parse through some multi-valued option like --subcommand_config_path. Giving me the opportunity of structuring the repository according to commands and sub-commands like:

.
└── compute
    ├── instances
    │   ├── create
    │   │   └── slap.yaml
    │   ├── delete
    │   │   └── slap.yaml
    │   ├── describe
    │   │   └── slap.yaml
    │   └── slap.yaml
    └── slap.yaml

Then:

# when running `gcloud compute`
cat ./compute/slap.yaml | slap parse bash _ --subcommand_config_path=./compute/instances/slap.yaml -- "$@"

# when running `gcloud compute instances`
cat ./compute/instances/slap.yaml | slap parse bash _ --subcommand_config_path=./compute/instances/{create,delete,describe}/slap.yaml -- "$@"

So that high-level commands would be simply "routers", looking as simple as:

name: mycommand
version: "1.0"
author: Kevin K. <kbknapp@gmail.com>
about: Does awesome things

global_settings:
  - ColoredHelp

and each nested command would have its own small and concise configuration:

# Example taken from: https://github.com/agnipau/slap/blob/74219a0/examples/simple.yml
# Sub-commands field removed

name: mysubcommand
version: "1.0"
author: Kevin K. <kbknapp@gmail.com>
about: Does awesome things

global_settings:
  - ColoredHelp

args:
  - config:
      short: c
      long: config
      value_name: FILE
      help: Sets a custom config file
      takes_value: true
  - INPUT:
      help: Sets the input file to use
      required: true
      index: 1
  - verbose:
      short: v
      multiple: true
      help: Sets the level of verbosity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant