Commons CLI

コンポーネント レポジトリ

Sandboxコンポーネント

日本語訳 (Translations)

オリジナル

Creating a Parser

The newParser method on CommandLineParserFactory is used to create command line parser instances.

// create a command line parser
CommandLineParser parser = CommandLineParserFactory.newParser();


The right tool for the job

Different applications may require different parsing implementation strategies. CLI ships with two implementations: PosixParser and GnuParser. Both of these implement the CommandLineParser interface.

// parser is a PosixParser
CommandLineParser parser = CommandLineParserFactory.newParser();

// parser is a GnuParser 
parser = CommandLineParserFactory.newParser( "org.apache.commons.cli.GnuParser" );
      


Parse the command line

Now that a parser has been created the command line tokens can be parsed. The two parse methods on CommandLineParser perform this task.

public static void main( String[] args ) {
    // create the options
    Options options = ...;

    // create the parser
    CommandLine parser = ...;

    // parse the command line tokens
    CommandLine cmd = parser.parse( options, args );
}



Copyright © 1999-2007, Apache Software Foundation
Translated into Japanese by Tetsuya Kitahata , powered by Terra-International, Inc.
Original English Page would be found from HERE     --    ApacheNews    ASF プロジェクト一覧
Terra-International, Inc. -- テラ・インターナショナル
Special Thanks -- 【お問い合わせ/テキスト広告】