Java opt arg parsing
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Stephen Cochrane 147a82c65c Added script to help with authoring releases 7 months ago
scripts Added script to help with authoring releases 7 months ago
src Small tweak to usage output 10 months ago
.build.yml init 1 year ago
.gitignore Small tweak to usage output 10 months ago
LICENSE License change 1 year ago
README.md Updated pom and readme 11 months ago
pom.xml Added script to help with authoring releases 7 months ago
run.sh Good progress 1 year ago

README.md

jopts

Simple opt args for java

Installing

Too make use of this lib, follow the instructions found here.

Alternatively, you can download the latest jar directly.

Usage

JOpts constructor takes 2 arguments, an opt string, and the arguments passed to the program (in that order)

The opt string has a specic format:

  • A semi colon seperated list of comma seperated values.
  • The comma seperated values all map to the same opt arg
  • The comma seperated values all begin with an implicit -
    • This means that the opt string 'v' maps to '-v', and '-v' maps to '--v' and so on

An example progra is shown below, notice how the opt string is

v, -value MAPPING TO -v, --value on the command line

h, -help MAPPING TO -h, --help on the command line

import xyz.skiqqy.jopts.JOpts;

public class Test {
	public static void main(String... argv) {
		JOpts jo = new JOpts("v,-value:;h,-help", argv); // Construct + parse

		String value = jo.getElse("-value", "Default Value");
		boolean help = jo.is("h");

		System.out.print(help + ", ");
		System.out.println(value);

		// Command line: $ JOpts --help # prints: true, Default Value
		// Command line: $ JOpts -h # prints: true, Default Value

		// Command line: $ JOpts -v test # prints: false, test 
		// Command line: $ JOpts --value test # prints: false, test 

		// Command line: $ JOpts --value # Throws an exception

		// Command line: $ JOpts --value test -h # prints: true, test
		// Command line: $ JOpts -v test -h # prints: true, test
		// Command line: $ JOpts -h -v test # prints: true, test
	}
}

Notes

License: