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

Dynamic collection of command names #18

Closed
MadBomber opened this issue Aug 21, 2023 · 1 comment
Closed

Dynamic collection of command names #18

MadBomber opened this issue Aug 21, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@MadBomber
Copy link

MadBomber commented Aug 21, 2023

Describe the problem

I have a nested architecture where there is a common set of parameters that are shared with multiple commands. In my usage statement I want to see something like this:
Usage: app [one|two] [options]

class Common
  include TTY::Option
  # ... common params for all commands
end

class One < Common
  # ... parameters unique for one
end

class Two < common
  # ... parameters unique to two
end

How would the new feature work?

app --help
Returns a usage report for only the common parameters and gives the command name and command description that are available.

app one --help
Gives a usage report showing the common parameters and the unique parameters for command one.

Drawbacks

Could get lost in ObjectSpace ...

I tried using a class variable at the base class level; but, command is executed at elaboration time. This does not allow for the dynamic assignment of content.

Bottom line: as is, I can statically assign command "[one|two]" in the base class; but, when I add or remove command classes I have to remember to change that static text. I'd rather the computer do it for me like this:

command '[' +
  ObjectSpace
    .each_object(Class)
    .select { |klass| klass < App::Command }
    .map{|k| k.name.downcase.split('::').last}
    .join('|') +
  ']'

DSL by its nature is executed at elaboration. What I'm wanting has to be done AFTER elaboration. That means that the DSL needs to be lazy.

I am still trying.

@MadBomber MadBomber added the enhancement New feature or request label Aug 21, 2023
@piotrmurach
Copy link
Owner

Hi Dewayne 👋

Thanks for taking an interest in tty-option and providing your thoughts on handling multiple commands.

However, this issue is not related to this repository, so I'll close it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants