Package com.martiansoftware.jsap

Examples of com.martiansoftware.jsap.JSAP


   * @param args the command line.
   * @throws Exception for reasons made clear later in the manual.
   */
  // @@snip:Manual_HelloWorld_5@@
  public static void main(String[] args) throws Exception {
    JSAP jsap = new JSAP();
   
    FlaggedOption opt1 = new FlaggedOption("count")
                .setStringParser(JSAP.INTEGER_PARSER)
                .setDefault("1")
                .setRequired(true)
                .setShortFlag('n')
                .setLongFlag(JSAP.NO_LONGFLAG);
   
    jsap.registerParameter(opt1);
   
    Switch sw1 = new Switch("verbose")
            .setShortFlag('v')
            .setLongFlag("verbose");
   
    jsap.registerParameter(sw1);
   
    UnflaggedOption opt2 = new UnflaggedOption("name")
                .setStringParser(JSAP.STRING_PARSER)
                .setDefault("World")
                .setRequired(true)
                .setGreedy(true);
               
    jsap.registerParameter(opt2);
   
    JSAPResult config = jsap.parse(args)

    // check whether the command line was valid, and if it wasn't,
    // display usage information and exit.
    if (!config.success()) {
      System.err.println();
      System.err.println("Usage: java "
                + Manual_HelloWorld_5.class.getName());
      System.err.println("                "
                + jsap.getUsage());
      System.err.println();
      System.exit(1);
    }
   
    String[] names = config.getStringArray("name");
View Full Code Here


   * @param args the command line.
   * @throws Exception for reasons made clear later in the manual.
   */
  // @@snip:Manual_HelloWorld_3@@
  public static void main(String[] args) throws Exception {
    JSAP jsap = new JSAP();
   
    FlaggedOption opt1 = new FlaggedOption("count")
                .setStringParser(JSAP.INTEGER_PARSER)
                .setDefault("1")
                .setRequired(true)
                .setShortFlag('n')
                .setLongFlag(JSAP.NO_LONGFLAG);
   
    jsap.registerParameter(opt1);
   
    // create a switch we'll access using the id "verbose".
    // it has the short flag "-v" and the long flag "--verbose"
    // this will govern whether we say "Hi" or "Hello".
    Switch sw1 = new Switch("verbose")
            .setShortFlag('v')
            .setLongFlag("verbose");
   
    jsap.registerParameter(sw1);
   
    JSAPResult config = jsap.parse(args)

    for (int i = 0; i < config.getInt("count"); ++i) {
      System.out.println((config.getBoolean("verbose") ? "Hello" : "Hi")
                + ", World!");
    }
View Full Code Here

   * @param args the command line.
   * @throws Exception for reasons made clear later in the manual.
   */
  // @@snip:Manual_HelloWorld_7@@
  public static void main(String[] args) throws Exception {
    JSAP jsap = new JSAP();
   
    FlaggedOption opt1 = new FlaggedOption("count")
                .setStringParser(JSAP.INTEGER_PARSER)
                .setDefault("1")
                .setRequired(true)
                .setShortFlag('n')
                .setLongFlag(JSAP.NO_LONGFLAG);

    opt1.setHelp("The number of times to say hello.");
    jsap.registerParameter(opt1);
   
    Switch sw1 = new Switch("verbose")
            .setShortFlag('v')
            .setLongFlag("verbose");
   
    sw1.setHelp("Requests verbose output.");
    jsap.registerParameter(sw1);
   
    UnflaggedOption opt2 = new UnflaggedOption("name")
                .setStringParser(JSAP.STRING_PARSER)
                .setDefault("World")
                .setRequired(true)
                .setGreedy(true);
   
    opt2.setHelp("One or more names of people you would like to greet.");
    jsap.registerParameter(opt2);
   
    JSAPResult config = jsap.parse(args)

    if (!config.success()) {
     
      System.err.println();

      // print out specific error messages describing the problems
      // with the command line, THEN print usage, THEN print full
      // help.  This is called "beating the user with a clue stick."
      for (java.util.Iterator errs = config.getErrorMessageIterator();
          errs.hasNext();) {
        System.err.println("Error: " + errs.next());
      }
     
      System.err.println();
      System.err.println("Usage: java "
                + Manual_HelloWorld_7.class.getName());
      System.err.println("                "
                + jsap.getUsage());
      System.err.println();
      System.err.println(jsap.getHelp());
      System.exit(1);
    }
   
    String[] names = config.getStringArray("name");
    for (int i = 0; i < config.getInt("count"); ++i) {
View Full Code Here

*/
public class Manual_HelloWorld_9 {

  // @@snip:Manual_HelloWorld_9@@
  public static void main(String[] args) throws Exception {
    JSAP jsap = new JSAP(Manual_HelloWorld_9.class.getResource("Manual_HelloWorld_9.jsap"));
   
    JSAPResult config = jsap.parse(args)

    if (!config.success()) {
     
      System.err.println();

      // print out specific error messages describing the problems
      // with the command line, THEN print usage, THEN print full
      // help.  This is called "beating the user with a clue stick."
      for (java.util.Iterator errs = config.getErrorMessageIterator();
          errs.hasNext();) {
        System.err.println("Error: " + errs.next());
      }
     
      System.err.println();
      System.err.println("Usage: java "
                + Manual_HelloWorld_9.class.getName());
      System.err.println("                "
                + jsap.getUsage());
      System.err.println();
      System.err.println(jsap.getHelp());
      System.exit(1);
    }
   
    String[] names = config.getStringArray("name");
    String[] languages = config.getStringArray("verbose");
View Full Code Here

     * will be written.
     * @throws JSAPException if there are any problems with the specified
     * configuration.
     */
    private void buildJSAP() throws JSAPException {
        JSAP jsap = new JSAP();
        for (Enumeration e = parameterConfigs.elements();
            e.hasMoreElements();
            ) {

            ParameterConfiguration pc =
                (ParameterConfiguration) e.nextElement();

            if (pc.hasProperties()) {
                hasProperties = true;
            }
            jsap.registerParameter(pc.getParameter());
        }
    }
View Full Code Here

* @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
*/
public class TryLoadXML {

  public static void main(String[] args) throws Exception {
    JSAP jsap = new JSAP("com/martiansoftware/jsap/xml/silly-example.xml");
    System.out.println(jsap.getHelp());
  }
View Full Code Here

      System.exit( 0 ); // NOPMD
   }

   static boolean areCommandLineOptionsCorrect( final String[] args ) throws JSAPException
   {
      final JSAP jsap = new JSAP();
      config = parseCommandLineArguments( args,
                                          jsap );

      if ( !config.success() )
      {
         LOGGER.log( Level.SEVERE,
                     "Usage: java "
                           + FlexPMD.class.getName() + " " + jsap.getUsage() );
      }

      return config.success();
   }
View Full Code Here

      System.exit( 0 ); // NOPMD
   }

   static boolean areCommandLineOptionsCorrect( final String[] args ) throws JSAPException
   {
      final JSAP jsap = new JSAP();
      config = parseCommandLineArguments( args,
                                          jsap );

      if ( !config.success() )
      {
         LOGGER.log( Level.SEVERE,
                     "Usage: java "
                           + FlexCPD.class.getName() + " " + jsap.getUsage() );
      }

      return config.success();
   }
View Full Code Here

   }

   @Test
   public void testRegisterParameter() throws JSAPException
   {
      final JSAP jsap = new JSAP();

      CommandLineUtils.registerParameter( jsap,
                                          new ICommandLineOptions()
                                          {
                                             @Override
                                             public String toString()
                                             {
                                                return "name";
                                             }
                                          },
                                          true );

      assertTrue( jsap.getByShortFlag( 'n' ) != null );
      assertNull( jsap.getByShortFlag( 'm' ) );
   }
View Full Code Here

      System.exit( 0 ); // NOPMD
   }

   static boolean areCommandLineOptionsCorrect( final String[] args ) throws JSAPException
   {
      final JSAP jsap = new JSAP();
      config = parseCommandLineArguments( args,
                                          jsap );

      if ( !config.success() )
      {
         LOGGER.log( Level.SEVERE,
                     "Usage: java "
                           + FlexMetrics.class.getName() + " " + jsap.getUsage() );
      }

      return config.success();
   }
View Full Code Here

TOP

Related Classes of com.martiansoftware.jsap.JSAP

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.