GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - cbeust/jcommander: Command line parsing framework for Java

BranchesTags
Open more actions menu

Latest commit

 

History

1,178 Commits
1,178 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
docs
docs
 
 
gradle
gradle
 
 
kobalt
kobalt
 
 
lib
lib
 
 
src
src
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
README.markdown
README.markdown
 
 
README.publish
README.publish
 
 
SECURITY.md
SECURITY.md
 
 
build.gradle.kts
build.gradle.kts
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
kobaltw
kobaltw
 
 
license.txt
license.txt
 
 
misc.xml
misc.xml
 
 
module-info.java
module-info.java
 
 
notice.md
notice.md
 
 
release
release
 
 
upload
upload
 
 

Repository files navigation

JCommander

This is an annotation based parameter parsing framework for Java 8 (JCommander 1.x), 11 (JCommander 2.x), 17 (JCommander 3.x) and 21 (JCommander 4.x).

Here is a quick example:

public class JCommanderTest {
    @Parameter
    public List<String> parameters = Lists.newArrayList();
 
    @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
    public Integer verbose = 1;
 
    @Parameter(names = "-groups", description = "Comma-separated list of group names to be run"
                    placeholder = "<group1>,<group2>...")
    public String groups;
 
    @Parameter(names = "-debug", description = "Debug mode")
    public boolean debug = false;

    @DynamicParameter(names = "-D", description = "Dynamic parameters go here")
    public Map<String, String> dynamicParams = new HashMap<String, String>();

}

and how you use it:

JCommanderTest jct = new JCommanderTest();
String[] argv = { "-log", "2", "-groups", "unit1,unit2,unit3",
                    "-debug", "-Doption=value", "a", "b", "c" };
JCommander.newBuilder()
  .addObject(jct)
  .build()
  .parse(argv);

Assert.assertEquals(2, jct.verbose.intValue());
Assert.assertEquals("unit1,unit2,unit3", jct.groups);
Assert.assertEquals(true, jct.debug);
Assert.assertEquals("value", jct.dynamicParams.get("option"));
Assert.assertEquals(List.of("a", "b", "c"), jct.parameters);

The full doc is available at https://jcommander.org.

Building JCommander

./gradlew assemble

About

Command line parsing framework for Java

Resources

Readme
Apache-2.0 license

Security policy

Security policy
Activity

Stars

2.0k stars

Watchers

58 watching

Forks

344 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.