For a project at school, I needed to refactor an old code parsing almost 30 command line arguments. I needed to add some more arguments and change some old args, but the old code was not maintainable at all. So I decided to use a library to make the parsing. of the args. I chose Apache Commons CLI. This is a really simple library to make that parsing. It's not perfect, but it makes the work I needed and is powerful to do that job. With this API, you have to declare an Options instance. This class is used to describe the command line arguments of the program. Options constructor don't take any arguments. ```java Options options = new Options(); ``` Then you have to use the addOption methods to add some arguments to the application. There is three versions of the methods : We need some explanations here. The short opt is used to define an arg with a simple dash (-shortopt) and the long opt is defined with double dash (--longopt). The hasArg indicate if the parameter accepts an argument. The description is, like its name indicates, the description of the option. It's used to print the help of the program. Using Option instances you can configure all the properties of an option using the setters and the constructor. Here is all the setters that can be used to configure the option : There is also an other way to create Option instance, using the OptionBuilder class. It's a little weird because all the methods are static and the method returns a reference to the builder. And then you make a call to the builder instance using the static method. The method are equivalent with the methods of the Option class with different names (withXXX, hasXXX, ...). When you have configured the option, you have to call one of the create methods to create the instance and reset the OptionBuilder. Once you filled the Options instance with the arguments of the program, you can use it. You have to use a CommandLineParser to parse the Options. There is three implementation of this interface : A simple example using the GnuParser : ```java CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); ``` You receive a CommandLine object representing all the arguments. The parse() method can throw a ParseException if the given arguments are not valid. With that object, you can get the options that have been passed to the application. For that, you can use the given methods : With this API, you can also generate the help of the program : ```java HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "program", options); ``` With that, you display the list of arguments taken by the program. With that example, we've seen the main features of this library. For more information, you consult the Apache Commons CLI website.