|
1 | 1 | This is the java version of the Args program described in: http://butunclebob.com/ArticleS.UncleBob.CleanCodeArgs |
2 | 2 |
|
| 3 | + |
| 4 | +---------------------Following parts are updated----------------------- |
| 5 | +package com.cleancoder.args; |
| 6 | + |
3 | 7 | public class ArgsMain { |
| 8 | + |
4 | 9 | public static void main(String[] args) { |
5 | | - try { |
6 | | - Args arg = new Args("l,p#,d*", args); |
7 | | - boolean logging = arg.getBoolean('l'); |
8 | | - int port = arg.getInt('p'); |
9 | | - String directory = arg.getString('d'); |
10 | | - executeApplication(logging, port, directory); |
11 | | - } catch (ArgsException e) { |
12 | | - System.out.printf("Argument error: %s\n", e.errorMessage()); |
13 | | - } |
| 10 | + if(args[0].equals("-h")) { |
| 11 | + helpFunction(); |
| 12 | + return; |
| 13 | + } |
| 14 | + |
| 15 | + try { |
| 16 | + Args arg = new Args("f,p#,s*,n#,a##,d[*]", args); |
| 17 | + arg.getAllParameters(); |
| 18 | + } catch (ArgsException e) { |
| 19 | + System.out.printf("Argument error: %s\n", e.errorMessage()); |
| 20 | + } |
14 | 21 | } |
15 | 22 |
|
16 | | - private static void executeApplication(boolean logging, int port, String directory) { |
17 | | - System.out.printf("logging is %s, port:%d, directory:%s\n",logging, port, directory); |
| 23 | + //Function to print the help content |
| 24 | + private static void helpFunction() { |
| 25 | + System.out.printf("Following are the options : \n"); |
| 26 | + System.out.printf("Schema: \n - char - Boolean arg.\n - char* - String arg.\n - char# - Integer arg.\n - char## - double arg.\n - char[*] - one element of a string array.\n\n"); |
| 27 | + System.out.printf("Example schema: (f,p#,s*,n#,a##,d[*])\n\n"); |
| 28 | + System.out.printf("Corresponding command line: -f -s Bob -n 1 -a 3.2 -p 22 -d /home/users/\n"); |
18 | 29 | } |
19 | 30 | } |
20 | | - |
21 | 31 | Schema: |
22 | 32 | - char - Boolean arg. |
23 | 33 | - char* - String arg. |
24 | 34 | - char# - Integer arg. |
25 | 35 | - char## - double arg. |
26 | 36 | - char[*] - one element of a string array. |
27 | 37 |
|
28 | | -Example schema: (f,s*,n#,a##,p[*]) |
29 | | -Coresponding command line: "-f -s Bob -n 1 -a 3.2 -p e1 -p e2 -p e3 |
| 38 | +Example schema: (f,p#,s*,n#,a##,d[*]) |
| 39 | +Corresponding command line: "-f -s Bob -n 1 -a 3.2 -p 22 -d /home/users/ |
| 40 | + |
| 41 | +Code documentation updated |
| 42 | + |
| 43 | +Edited the main to add the schema for what all arguments types. |
| 44 | +Added help function and can be used by -h option when running the program. |
| 45 | + |
| 46 | +For Boolean type |
| 47 | +-Doesnt need a value(you just have to specify the argument name) |
| 48 | +-Only flag is enough to change to true |
| 49 | + |
| 50 | +Added double and string array code for parsing |
30 | 51 |
|
| 52 | +String array and map updated to take the value as argument |
0 commit comments