org.pz.platypus
Class CommandLineArgs

java.lang.Object
  extended by org.pz.platypus.CommandLineArgs

public class CommandLineArgs
extends java.lang.Object

Uses apache commons CLI to parse the command line.

Author:
alb, atul - moved the command line parsing to apache commons CLI

Field Summary
private  org.apache.commons.cli.CommandLine line
           
private  org.apache.commons.cli.Options options
           
private  org.apache.commons.cli.CommandLineParser parser
           
 
Constructor Summary
CommandLineArgs(java.lang.String[] args)
          Configures the CLI parser with a list of valid Options.
 
Method Summary
private  java.lang.String appendFormatExtension(java.lang.String ret)
           
 java.lang.String createCommandLine(java.lang.String[] args)
          Creates a single string from all the args specified by the user on the command line
private static boolean doesOptionHaveArg(java.lang.String arg)
           
private  java.lang.String generateOutputFile()
           
private  java.lang.String getFormatExtension()
           
private  java.lang.String getNameMinusExtension(java.lang.String str)
           
private  org.apache.commons.cli.Option[] getSupportedOptions()
          All valid supported options are here.
private  void initOptions()
           
private static boolean isArgAnOption(java.lang.String arg)
           
 java.lang.String lookup(java.lang.String argToFind)
          Determines whether an item was specified on the command-line.
private  void parseArguments(java.lang.String[] args)
           
static java.lang.String[] preProcessCommandLine(java.lang.String[] args)
          Injects the -inputFile and -outputFile options before correct barewords The algorithm first checks if we have encountered an option with zero or one argument.
 void process(GDD gdd)
          Processes some command-line options
private  void processFontListOption(GDD gdd)
           
private  void processHelpOption(GDD gdd)
           
private  void processVerboseOption(GDD gdd)
           
private  void processVeryVerboseOption(GDD gdd)
           
private  boolean shouldGenerateOutputOption(java.lang.String argStr)
           
private  void showUsageIfZeroArgs(GDD gdd)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

options

private org.apache.commons.cli.Options options

parser

private org.apache.commons.cli.CommandLineParser parser

line

private org.apache.commons.cli.CommandLine line
Constructor Detail

CommandLineArgs

public CommandLineArgs(java.lang.String[] args)
Configures the CLI parser with a list of valid Options. And parses the command line args.

Parameters:
args - command-line args passed to main()
Method Detail

parseArguments

private void parseArguments(java.lang.String[] args)

initOptions

private void initOptions()

getSupportedOptions

private org.apache.commons.cli.Option[] getSupportedOptions()
All valid supported options are here.

Returns:
a list of such options.

createCommandLine

public java.lang.String createCommandLine(java.lang.String[] args)
Creates a single string from all the args specified by the user on the command line

Parameters:
args - the user-specified args
Returns:
the command line as one string. If there were no args, a single space is returned.

lookup

public java.lang.String lookup(java.lang.String argToFind)
Determines whether an item was specified on the command-line. And if so, what any argument for it is.

Parameters:
argToFind - argument to lookup
Returns:
null if the item was not specified; "" if the item was specified but had no argument, and the argument if item was specified and has an argument.

generateOutputFile

private java.lang.String generateOutputFile()

appendFormatExtension

private java.lang.String appendFormatExtension(java.lang.String ret)

getFormatExtension

private java.lang.String getFormatExtension()

getNameMinusExtension

private java.lang.String getNameMinusExtension(java.lang.String str)

shouldGenerateOutputOption

private boolean shouldGenerateOutputOption(java.lang.String argStr)

process

public void process(GDD gdd)
             throws HelpMessagePrinted
Processes some command-line options

Parameters:
gdd - GDD that will hold the state of some switches (such as verbosity)
Throws:
HelpMessagePrinted - if no command-line args specified

processFontListOption

private void processFontListOption(GDD gdd)
                            throws HelpMessagePrinted
Throws:
HelpMessagePrinted

processVeryVerboseOption

private void processVeryVerboseOption(GDD gdd)

processVerboseOption

private void processVerboseOption(GDD gdd)

processHelpOption

private void processHelpOption(GDD gdd)
                        throws HelpMessagePrinted
Throws:
HelpMessagePrinted

showUsageIfZeroArgs

private void showUsageIfZeroArgs(GDD gdd)

preProcessCommandLine

public static java.lang.String[] preProcessCommandLine(java.lang.String[] args)
Injects the -inputFile and -outputFile options before correct barewords The algorithm first checks if we have encountered an option with zero or one argument. If so, it copies the elements to the result array. Else, it injects -inputFile before the first bareword and -outputFile after the second bareword.

Parameters:
args -
Returns:
correctly injects -inputFile and -outputFile before the barewords...

doesOptionHaveArg

private static boolean doesOptionHaveArg(java.lang.String arg)

isArgAnOption

private static boolean isArgAnOption(java.lang.String arg)


Copyright © 2008-10 Pacific Data Works LLC