com.cloudbees.sdk.cli
Class AbstractCommand

java.lang.Object
  extended by com.cloudbees.sdk.cli.ACommand
      extended by com.cloudbees.sdk.cli.AbstractCommand

public abstract class AbstractCommand
extends ACommand

Partial implementation of ACommand that provides more integration between argument parsing and dependency injections.

To encourage commonality between various commands and simplify the development of new commands, this subtype handles argument processing via args4j. Primarily this means you'll be defining your command line options as annotated fields or setter methods on subtypes. See Option and Argument for more details.

In addition to annotating setters and fields, the argument parsing code also looks for any injected fields whose type has HasOptions marker interface. There are several injectable option fragment components (such as Verbose) that contains this marker interface, and whatever options that these components define also becomes a part of the recognizable options.

By sharing and reusing such option fragment components, users will see consistent user interfaces and command developers are freed from lower-level option parsing.

Author:
Kohsuke Kawaguchi

Constructor Summary
AbstractCommand()
           
 
Method Summary
protected  org.kohsuke.args4j.CmdLineParser createParser()
           
protected  String getUsageMessage()
           
abstract  int main()
           
 void printHelp(List<String> args)
          Print out the detailed help of this command.
 int run(List<String> args)
          Executes this command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCommand

public AbstractCommand()
Method Detail

main

public abstract int main()
                  throws Exception
Throws:
Exception

run

public int run(List<String> args)
        throws Exception
Description copied from class: ACommand
Executes this command.

Specified by:
run in class ACommand
Parameters:
args - Never empty, never null. The first argument is the command name itself, followed by arguments
Returns:
The exit code of the command. 99 is apparently used for something special that I haven't figured out.
Throws:
Exception

createParser

protected org.kohsuke.args4j.CmdLineParser createParser()

printHelp

public void printHelp(List<String> args)
Description copied from class: ACommand
Print out the detailed help of this command.

Specified by:
printHelp in class ACommand
Parameters:
args - For backward compatibility, this method receives the full argument list (where the first token is the command name for which the help is requested.)

getUsageMessage

protected String getUsageMessage()


Copyright © 2011-2013. All Rights Reserved.