ArgEngine

This project is abandoned and its default file will likely not work with the most recent version of Minecraft. Whether this project is out of date or its author has marked it as abandoned, this project is no longer maintained.

ArgEngine

Introduction

Hello developers, you may know GetOpt from the glibc. A useful framework which provides the CLI parameter parsing. Now with ArgEngine this tool meets Bukkit. For users which already have used GetOpt I shall say that it works very different.

How to use it?

First you have to configure the general parsing options.

OptionsSheet mySheet = new OptionsSheet();  // This is used to hold your configuration
mySheet.exceptionOnUnknown = false;  // Set the options as you need them
OptionsSheetEntry newEntry = mySheet.new OptionsSheetEntry();  // Create a new entry
newEntry.name = "block";  // Set a name for this option
newEntry.type = OptionType.KEY_VALUE_PAIR;  // Set a type
newEntry.required = true;  // Set this option to reqiured
testSheet.addEntry(newEntry);  // Add the option to your Sheet

The exceptionOnUnkown switch and the other fields are documented in the source code which you can also download from here. I won't explain every option here.
If you don't want to set the configuration up like this you can create an OptionsSheet from a file.

OptionsSheet mySheet = new OptionsSheet();
mySheet.load(new FileReader("path/to/file"));

Check Configuration for details.
Now you have a setup which you can use to use the parser.

public boolean onCommand(CommandSender cSender, Command cmd, String label, String args[]) {
    try {
        Options result = ArgEngine.process(args, mySheet);   // Pass your arguments and parser setup
        result.getString("block");   // Get the value for this option
    } catch (RequirementUnsatisfiedException | TooManyArgumentsException exc) {
        // Handle as you like
    }
    return true;
}

Also check Source and Eclipse if you use Eclipse.

Features

+ Option types: BOOLEAN, KEY_VALUE_PAIR, SELECTION, SETTING, ANY
+ A string like

--message "Hello you!" -other

will see Hello you! as 1 argument not as 2
+ Throwing exceptions on specific argument faults.
+ An option set to "yes" and read as boolean will return true (no => false)
+ An OptionsSheet can be loaded from a file or string

How does the user use it?

There are two parsing options. You can select one of them by setting the linuxLike option in you OptionsSheet

  1. like the getopt parser (will be implemented later)
  2. with my special method (default)

My special method

User entryInterpretationOptionType
+opt
The key opt is set to trueBOOLEAN
-opt
The key opt is set to falseBOOLEAN
--opt value
The key opt is set to "value"KEY_VALUE_PAIR or SELECTION
opt
The key opt is setANY
--opt=value
The key opt is set to "value"KEY_VALUE_PAIR or SELECTION

Comments

Posts Quoted:
Reply
Clear All Quotes

About This Project

Categories

Members

Recent Files