Declaring Arguments and Parameters

Let's set some preconditions, which will be of importance in the following chapters.

  • we will put the command into the package
  • the actual java implementation of the packager are found in

Therefore, the first lines of out Command class look like this:






public class SipCommand implements Command{

After importing the necessary packages, let's dive into the declaration of the Arguments. This is almost necessarily the first step when you want to reuse arguments. Good practise is to always follow this pattern, so you don't have to completely rework the declaration sometime. In short, we will work above definition from bottom up.

You will note that all Arguments, Parameters and Syntaxes will be declared as static. This is needed because of the inner workings of the Command Line Completion, which has to have access to a static HELP_INFO field providing all necessary informations.

static StringArgument ARG_PASSWORD = new StringArgument("password", "the password for the sipfile");

static FileArgument ARG_SIPFILE = new FileArgument("sipfile", "the sipfile to perform the operation on");

static FileArgument ARG_FILE = new FileArgument("file", "if given, only includes the files in this list", Argument.MULTI);

Now we can declare the Parameters, beginning with the ones taking no Arguments.

Note: all Parameters are optional by default!

// Those two are mandatory, as we will define the two distinct syntaxes given above

static Parameter PARAM_COMPRESS = new Parameter(

"c", "compress directory contents to a sipfile", Parameter.MANDATORY);

static Parameter PARAM_EXTRACT = new Parameter(

"x", "extract a sipfile", Parameter.MANDATORY);

static Parameter PARAM_RECURSE = new Parameter(

"r", "recurse through subdirectories");

static Parameter PARAM_PASSWORD = new Parameter(

"password", "use a password to en-/decrypt the file", ARG_PASSWORD);

// here come our two anonymous Parameters used to pass the files

static Parameter PARAM_SIPFILE = new Parameter(


static Parameter PARAM_FILE = new Parameter(



There is something special about the second Syntax, the extract one. The command line completion for this one will fail, as it will try to suggest files that are in the current directory, not in the sipfile we want to extract from. We will need a special type of Argument to provide a convenient completion, along with an extra Parameter which uses it.

I18N in Commands

could be useful a Base or Utility Class to manage Text Strings outside of the Command sources (for ex. in an external properties or xml file ?), at least for descriptions ?.

These files could be bundled inside the jar of the command itself, or better we could have one big jar (1 for the default locale, and 1 for any other language that I could install later) containing all the i18n related text, something like the Language Packs in Windows 2000 .
Useful at least for the Base System (Commands, Applications,etc.).