Skip to content

novastosha/BetterArguments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BetterArguments

A simple, yet useful argument parser that uses builders.

Usage

Create your argument parser supplied with your raw string arguments

ArgumentParser parser = new ArgumentParser(args);

Create an argument

Argument<String> name = Argument.Builder.create("name", String.class)
                // Set the aliases
                .withAliases(new String[]{"n","ln"})
                // Add a description
                .withDescription("Your name.")
                // Handle the argument conversion manually (in the case of numbers or strings, it is unnecessary but possible)
                .withValueConverter(new Argument.ValueConverterr<String>() {
                      public String convert(String raw) {
                          return raw.equalsIgnoreCase("jojo") ? "JOJO" : raw;
                      }
                })
                // Build the argument
                .build(parser);

NOTE: Adding value converters is necessary in other object types

Adding a help argument (optional)

parser.addHelpArgument();

Now, to parse the arguments, call

parser.parse();

Checking argument presence

if(parser.hasArgument("name")) {
  System.out.println("Hello, "+name.get());
}else{
  System.out.println("You didn't input your name, how sad ;-;");
}

About

A simple, yet useful argument parser.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages