Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cbeust/jcommander
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.81
Choose a base ref
...
head repository: cbeust/jcommander
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.82
Choose a head ref
  • 19 commits
  • 12 files changed
  • 4 contributors

Commits on Mar 3, 2021

  1. Fix username look up

    cbeust committed Mar 3, 2021
    Copy the full SHA
    caf8326 View commit details
  2. Build minor fixes

    cbeust committed Mar 3, 2021
    Copy the full SHA
    d473f2c View commit details

Commits on Mar 5, 2021

  1. Update JCommander.java

    Added option to replace the Parameterized parsing with the DefaultParamertizedParser.
    tgallagher2017 authored Mar 5, 2021
    Copy the full SHA
    3ec68b6 View commit details
  2. Add files via upload

    Add a default parameterized parser that replicates the original parsing because it was pulled from JCommander's original source.
    tgallagher2017 authored Mar 5, 2021
    Copy the full SHA
    f27ad9c View commit details
  3. Update DefaultParameterizedParser.java

    Added comments.
    tgallagher2017 authored Mar 5, 2021
    Copy the full SHA
    3ca80bc View commit details
  4. Add files via upload

    Added the interface that allows replacement of Parameterized parser at runtime.
    tgallagher2017 authored Mar 5, 2021
    Copy the full SHA
    0015283 View commit details
  5. Update IParameterizedParser.java

    Added more comments on why this interface was created.
    tgallagher2017 authored Mar 5, 2021
    Copy the full SHA
    b4b2c05 View commit details

Commits on Mar 23, 2021

  1. Copy the full SHA
    b7b0d1d View commit details
  2. Merge pull request #512 from mkarg/hide-command-section

    usage() hides 'Comments:' header when ONLY hidden commands exist
    cbeust authored Mar 23, 2021
    Copy the full SHA
    947cd54 View commit details

Commits on Nov 17, 2021

  1. Update IParameterizedParser.java

    Update typo in description
    tgallagher2017 authored Nov 17, 2021
    Copy the full SHA
    9ade05e View commit details
  2. Update IParameterizedParser.java

    Correct typo in description
    tgallagher2017 authored Nov 17, 2021
    Copy the full SHA
    c39b341 View commit details
  3. Create MyDelegate.java

    Added testing supporting file.
    tgallagher2017 authored Nov 17, 2021
    Copy the full SHA
    be131cb View commit details
  4. Added testing modules

    Added main testing module plus supporting classes that are only used in testing.
    tgallagher2017 authored Nov 17, 2021
    Copy the full SHA
    9683c42 View commit details
  5. Copy the full SHA
    d621f11 View commit details
  6. Update JCommander.java

    Removed unnecessary "this."
    tgallagher2017 authored Nov 17, 2021
    Copy the full SHA
    f77fdd8 View commit details

Commits on Dec 8, 2021

  1. RemoveUnnecessaryFinal

    Based on developer comments, removed 'final' where not necessary.
    tgallagher2017 authored Dec 8, 2021
    Copy the full SHA
    2c0ddfd View commit details

Commits on Jan 11, 2022

  1. Merge pull request #511 from tgallagher2017/master

    Add capability to set Parameterized Parser at runtime.
    cbeust authored Jan 11, 2022
    Copy the full SHA
    f109a8e View commit details
  2. Fix build

    cbeust committed Jan 11, 2022
    Copy the full SHA
    8e610d4 View commit details
  3. Bump version and publish

    cbeust committed Jan 11, 2022
    Copy the full SHA
    dc0c1bf View commit details
21 changes: 14 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


object This {
val version = "1.81"
val version = "1.82"
val artifactId = "jcommander"
val groupId = "com.beust"
val description = "Command line parsing library for Java"
@@ -59,14 +59,21 @@ plugins {
}

dependencies {
listOf("org.testng:testng:7.0.0")
.forEach { testCompile(it) }
listOf("org.testng:testng:7.0.0", "com.fasterxml.jackson.core:jackson-core:2.13.1",
"com.fasterxml.jackson.core:jackson-annotations:2.13.1")
.forEach { testImplementation(it) }
}

//
// Releases:
// ./gradlew bintrayUpload (to JCenter)
// ./gradlew publish (to Sonatype, then go to https://oss.sonatype.org/index.html#stagingRepositories to publish)
// Make sure that ~/.gradle/gradle.properties:
// signing.keyId=XXXXXXXX
// signing.password=
// signing.secretKeyRingFile=../../.gnupg/secring.gpg
// lists a key that's listed in the keyring
// (gpg --list-keys, last eight digits of the key)
//

bintray {
@@ -111,6 +118,7 @@ with(publishing) {
afterEvaluate {
from(components["java"])
}
suppressAllPomMetadataWarnings()
artifact(sourcesJar)
artifact(javadocJar)
pom {
@@ -120,7 +128,7 @@ with(publishing) {
licenses {
license {
name.set("Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
issueManagement {
@@ -143,15 +151,14 @@ with(publishing) {
}

repositories {
mavenLocal()
maven {
name = "sonatype"
url = if (This.version.contains("SNAPSHOT"))
uri("https://oss.sonatype.org/content/repositories/snapshots/") else
uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.findProperty("sonatypeUser") as? String
password = project.findProperty("sonatypePassword") as? String
username = project.findProperty("sonatypeUser")?.toString() ?: System.getenv("SONATYPE_USER")
password = project.findProperty("sonatypePassword")?.toString() ?: System.getenv("SONATYPE_PASSWORD")
}
}
maven {
12 changes: 12 additions & 0 deletions src/main/java/com/beust/jcommander/DefaultUsageFormatter.java
Original file line number Diff line number Diff line change
@@ -244,6 +244,18 @@ public void appendAllParametersDetails(StringBuilder out, int indentCount, Strin
* @param indent the indentation
*/
public void appendCommands(StringBuilder out, int indentCount, int descriptionIndent, String indent) {
boolean hasOnlyHiddenCommands = true;
for (Map.Entry<JCommander.ProgramName, JCommander> commands : commander.getRawCommands().entrySet()) {
Object arg = commands.getValue().getObjects().get(0);
Parameters p = arg.getClass().getAnnotation(Parameters.class);

if (p == null || !p.hidden())
hasOnlyHiddenCommands = false;
}

if (hasOnlyHiddenCommands)
return;

out.append(indent + " Commands:\n");

// The magic value 3 is the number of spaces between the name of the option and its description
24 changes: 24 additions & 0 deletions src/main/java/com/beust/jcommander/IParameterizedParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.beust.jcommander;

import java.util.List;

/**
* Thin interface allows the Parameterized parsing mechanism, which reflects an object to find the
* JCommander annotations, to be replaced at runtime for cases where the source code cannot
* be directly annotated with JCommander annotations, but may have other annotations such as
* JSON annotations that can be used to reflect as JCommander parameters.
*
* @author Tim Gallagher
*/
public interface IParameterizedParser {

/**
* Parses the given object for any command line related annotations and returns the list of
* JCommander Parameterized definitions.
*
* @param annotatedObj the object that contains the annotations.
* @return non-null List but may be empty
*/
List<Parameterized> parseArg(Object annotatedObj);

}
9 changes: 8 additions & 1 deletion src/main/java/com/beust/jcommander/JCommander.java
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@

package com.beust.jcommander;

import com.beust.jcommander.parser.DefaultParameterizedParser;
import com.beust.jcommander.FuzzyMap.IKey;
import com.beust.jcommander.converters.*;
import com.beust.jcommander.internal.*;
@@ -46,6 +47,8 @@
*/
public class JCommander {
public static final String DEBUG_PROPERTY = "jcommander.debug";

protected IParameterizedParser parameterizedParser = new DefaultParameterizedParser();

/**
* A map to look up parameter description per option name.
@@ -264,6 +267,10 @@ public JCommander(Object object, String... args) {
parse(args);
}

public void setParameterizedParser(IParameterizedParser parameterizedParser) {
this.parameterizedParser = parameterizedParser;
}

/**
* Disables expanding {@code @file}.
*
@@ -598,7 +605,7 @@ public void createDescriptions() {
private void addDescription(Object object) {
Class<?> cls = object.getClass();

List<Parameterized> parameterizeds = Parameterized.parseArg(object);
List<Parameterized> parameterizeds = parameterizedParser.parseArg(object);
for (Parameterized parameterized : parameterizeds) {
WrappedParameter wp = parameterized.getWrappedParameter();
if (wp != null && wp.getParameter() != null) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.beust.jcommander.parser;

import com.beust.jcommander.IParameterizedParser;
import com.beust.jcommander.Parameterized;
import java.util.List;

/**
* Pulled from the JCommander where is reflects the object to determine the Parameter annotations.
*
* @author Tim Gallagher
*/
public class DefaultParameterizedParser implements IParameterizedParser {

/**
* Wraps the default parser.
*
* @param annotatedObj an instance of the object with Parameter related annotations.
*
* @author Tim Gallagher
*/
@Override
public List<Parameterized> parseArg(Object annotatedObj) {
return Parameterized.parseArg(annotatedObj);
}

}
Loading