git-like-cli icon indicating copy to clipboard operation
git-like-cli copied to clipboard

Allow commands to access the Cli class

Open grkvlt opened this issue 13 years ago • 2 comments

The command should be able to either access the Cli instance to allow them to either cause the help/usage text to be displayed, or to cause the program to exit with a specific message and status.

grkvlt avatar May 15 '12 15:05 grkvlt

The design of the CLI ends at once the command line is parsed and the command object is created. I chose this line because everyone seems to have a different idea of how actual execution should occur (especially around output messages and exit codes).

Using the current design your command objects could implement an interface with a method like this:

  int run(CLI cli);

As for help specifically, your commands can add a field @Inject Help help to get a reference to the help system.

Does this design work for you?

dain avatar May 15 '12 17:05 dain

I hadn't noticed the @Inject Help help; reference before, that should do what I need.

grkvlt avatar May 16 '12 10:05 grkvlt