View Javadoc
1   /*
2     Licensed to the Apache Software Foundation (ASF) under one or more
3     contributor license agreements.  See the NOTICE file distributed with
4     this work for additional information regarding copyright ownership.
5     The ASF licenses this file to You under the Apache License, Version 2.0
6     (the "License"); you may not use this file except in compliance with
7     the License.  You may obtain a copy of the License at
8   
9         http://www.apache.org/licenses/LICENSE-2.0
10  
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16   */
17  
18  package org.apache.commons.cli;
19  
20  /**
21   * A class that implements the {@code CommandLineParser} interface can parse a String array according to the
22   * {@link Options} specified and return a {@link CommandLine}.
23   */
24  public interface CommandLineParser {
25  
26      /**
27       * Parses the arguments according to the specified options.
28       *
29       * @param options the specified Options
30       * @param arguments the command line arguments
31       * @return the list of atomic option and value tokens
32       *
33       * @throws ParseException if there are any problems encountered while parsing the command line tokens.
34       */
35      CommandLine parse(Options options, String[] arguments) throws ParseException;
36  
37      /**
38       * Parses the arguments according to the specified options and properties.
39       *
40       * @param options the specified Options
41       * @param arguments the command line arguments
42       * @param properties command line option name-value pairs
43       * @return the list of atomic option and value tokens
44       *
45       * @throws ParseException if there are any problems encountered while parsing the command line tokens.
46       */
47      /*
48       * To maintain binary compatibility, this is commented out. It is still in the abstract Parser class, so most users will
49       * still reap the benefit. CommandLine parse(Options options, String[] arguments, Properties properties) throws
50       * ParseException;
51       */
52  
53      /**
54       * Parses the arguments according to the specified options.
55       *
56       * @param options the specified Options
57       * @param arguments the command line arguments
58       * @param stopAtNonOption if {@code true} an unrecognized argument stops the parsing and the remaining arguments
59       *        are added to the {@link CommandLine}s args list. If {@code false} an unrecognized argument triggers a
60       *        ParseException.
61       *
62       * @return the list of atomic option and value tokens
63       * @throws ParseException if there are any problems encountered while parsing the command line tokens.
64       */
65      CommandLine parse(Options options, String[] arguments, boolean stopAtNonOption) throws ParseException;
66  
67      /**
68       * Parses the arguments according to the specified options and properties.
69       *
70       * @param options the specified Options
71       * @param arguments the command line arguments
72       * @param properties command line option name-value pairs
73       * @param stopAtNonOption if {@code true} an unrecognized argument stops the parsing and the remaining arguments
74       *        are added to the {@link CommandLine}s args list. If {@code false} an unrecognized argument triggers a
75       *        ParseException.
76       *
77       * @return the list of atomic option and value tokens
78       * @throws ParseException if there are any problems encountered while parsing the command line tokens.
79       */
80      /*
81       * To maintain binary compatibility, this is commented out. It is still in the abstract Parser class, so most users will
82       * still reap the benefit. CommandLine parse(Options options, String[] arguments, Properties properties, boolean
83       * stopAtNonOption) throws ParseException;
84       */
85  }