Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/djcopley/argparse
A java argument parser
https://github.com/djcopley/argparse
argument-parser command-line java library
Last synced: about 2 months ago
JSON representation
A java argument parser
- Host: GitHub
- URL: https://github.com/djcopley/argparse
- Owner: djcopley
- License: gpl-3.0
- Created: 2018-12-11T21:36:08.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-19T15:52:00.000Z (4 months ago)
- Last Synced: 2024-10-11T19:12:20.039Z (2 months ago)
- Topics: argument-parser, command-line, java, library
- Language: Java
- Size: 92.8 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# A Java Argument Parser
Parse command line arguments easily.
### Usage example
import argparse.*;
import argparse.arguments.*;public class Main {
public static void main(String[] args) {
ArgumentParser parser = new ArgumentParser("Test program", args);
PositionalArgument arg1 = new PositionalArgument("file", "Enter the output filename");
FlagInputArgument arg2 = new FlagInputArgument("--file", "-f", "The input file path");
FlagArgument arg3 = new FlagArgument("--verbose", "-v", "Display verbose options");
parser.addArgument(arg1);
parser.addArgument(arg2);
parser.addArgument(arg3);
parser.parseArguments();
// Prints true if arg1 is specified in args (PositionalArguments are required, this will always be true)
System.out.println(arg1.isPassed());
// Prints arg1's input
System.out.println(arg1.getInput());
// Prints true if arg2 is specified in args
System.out.println(arg2.isPassed());
// Prints text arg2's input. Example: {"-f", "hello"} -> hello
System.out.println(arg2.getInput());
// Prints if arg3 is specified in args. Arg 3 is a FlagArgument and has no input. If getInput method is called, null is returned.
System.out.println(arg3.isPassed());
}
}