hi,
> Command
> + isValid(options: Options):boolean
> + getDescription():String
> + execute(options:Options):void
> + getPrimaryOption():Option
>
> Each command has a primaryOption which uniquely identifies the command from
> the command line. For example, if you have a command which scales images,
> then it might be identified by the --scale option.
i implemented a 'shell like' interactive console. each 'command'
defines it's own options and arguments. so eg a: "rm -r files "
behaves different as a "mv files dst".
the commands are then assembled by the main app into one option group
and CLI2 just works perfect.
Example of a simple 'rm' command:
protected Command createCommand() {
return new CommandBuilder()
.withName("rm")
.withDescription(getShortDescription())
.withChildren(new GroupBuilder()
.withName("Options:")
.withOption(optRecursive = new DefaultOptionBuilder()
.withShortName("r")
.withDescription("remove the directory
recursively")
.create())
.withOption(argPath = new ArgumentBuilder()
.withName("path")
.withDescription("path of the file or
directory")
.withMinimum(1)
.withMaximum(1)
.create()
)
.create()
)
.create();
}
> The main application is responsible for discovering and loading all plugins
> at runtime (using the SPI mechanism), determining which plugin to execute,
> and printing out help information. It also invokes the command by first
> invoking the command's isValid method to validate the input before invoking
> its execute method.
IMO the validation is not really needed - the 'execute' of the command
can always throw a IllegalArgumentException so there is not need to
validating it first.
> I'm curious if other people are using CLI in a similar manner, or if people
> create separate CLI applications for each piece of functionality? If this
> usage pattern is common, should CLI2 incorporate that usage pattern more
> formally into its design?
i think this is not really needed - since CLI2 already offers a very
smart way of implementing exactly this.
regards, toby
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]