Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.cyclopsgroup</groupId>
<artifactId>cyclopsgroup-java-parent</artifactId>
<version>0.7.3</version>
<version>0.8.0</version>
</parent>
<artifactId>jcli</artifactId>
<name>jcli</name>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/cyclopsgroup/jcli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public static <T> ArgumentProcessor<T> newInstance(Class<T> beanType) {
return forType(beanType);
}

/** @return Implementation of parsing context */
/**
* @return Implementation of parsing context
*/
public abstract ParsingContext createParsingContext();

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/cyclopsgroup/jcli/GnuParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import org.cyclopsgroup.jcli.spi.Option;
import org.cyclopsgroup.jcli.spi.ParsingContext;

/** @author <a href="mailto:jiaqi@cyclopsgroup.org">Jiaqi Guo</a> */
/**
* @author <a href="mailto:jiaqi@cyclopsgroup.org">Jiaqi Guo</a>
*/
public class GnuParser implements CommandLineParser {
@Override
public CommandLine parse(List<String> arguments, ParsingContext context) {
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/cyclopsgroup/jcli/ValidationResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public static final class ArgumentMissing extends Violation {}
public static final class OptionMissing extends Violation {
private final String optionName;

/** @param optionName Name of missing option */
/**
* @param optionName Name of missing option
*/
public OptionMissing(String optionName) {
this.optionName =
Preconditions.checkNotNull(optionName, "Name of missing option can't be null.");
Expand All @@ -34,7 +36,9 @@ public String getOptionName() {
public static final class UnexpectedOption extends Violation {
private final String optionName;

/** @param optionName Name of unexpected option */
/**
* @param optionName Name of unexpected option
*/
public UnexpectedOption(String optionName) {
this.optionName =
Preconditions.checkNotNull(optionName, "Name of missing option can't be null.");
Expand Down Expand Up @@ -76,7 +80,9 @@ public List<Violation> getViolations() {
return Collections.unmodifiableList(violations);
}

/** @return True if there is not violation */
/**
* @return True if there is not violation
*/
public boolean isValid() {
return violations.isEmpty();
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/cyclopsgroup/jcli/annotation/Argument.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Argument {
/** @return String description of argument which will be displayed in usage */
/**
* @return String description of argument which will be displayed in usage
*/
String description() default "";

/** @return Name of argument displayed in usage */
/**
* @return Name of argument displayed in usage
*/
String displayName() default "arg";
}
16 changes: 12 additions & 4 deletions src/main/java/org/cyclopsgroup/jcli/annotation/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Cli {
/** @return String description of command */
/**
* @return String description of command
*/
String description() default "";

/** @return Name of command */
/**
* @return Name of command
*/
String name();

/** @return Note displayed as footer */
/**
* @return Note displayed as footer
*/
String note() default "";

/** @return True if unexpected option or argument is expected to cause error */
/**
* @return True if unexpected option or argument is expected to cause error
*/
boolean restrict() default true;
}
16 changes: 12 additions & 4 deletions src/main/java/org/cyclopsgroup/jcli/annotation/MultiValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MultiValue {
/** @return Type of list that contains values */
/**
* @return Type of list that contains values
*/
Class<?> listType() default ArrayList.class;

/** @return Max number of values in list. By default it's -1 that means unlimited */
/**
* @return Max number of values in list. By default it's -1 that means unlimited
*/
int maxValues() default -1;

/** @return Minimal number of values in list. By default it's 0 */
/**
* @return Minimal number of values in list. By default it's 0
*/
int minValues() default 0;

/** @return Type of value in list */
/**
* @return Type of value in list
*/
Class<?> valueType() default String.class;
}
24 changes: 18 additions & 6 deletions src/main/java/org/cyclopsgroup/jcli/annotation/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,33 @@
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Option {
/** @return Default value of option */
/**
* @return Default value of option
*/
String defaultValue() default "";

/** @return String description of option which is displayed in usage */
/**
* @return String description of option which is displayed in usage
*/
String description() default "";

/** @return Display name of option */
/**
* @return Display name of option
*/
String displayName() default "value";

/** @return Long option name specified with double dash */
/**
* @return Long option name specified with double dash
*/
String longName() default "";

/** @return Short option name specified with single dash */
/**
* @return Short option name specified with single dash
*/
String name();

/** @return True if option has to be specified explicitly */
/**
* @return True if option has to be specified explicitly
*/
boolean required() default false;
}
36 changes: 27 additions & 9 deletions src/main/java/org/cyclopsgroup/jcli/example/UserControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,64 @@ public class UserControl {

private List<String> userNames;

/** @return Enum field example */
/**
* @return Enum field example
*/
@Option(name = "a", longName = "action", description = "Action to perform")
public final UserControlAction getAction() {
return action;
}

/** @return A date example that needs customized conversion rule */
/**
* @return A date example that needs customized conversion rule
*/
@DateField(format = "yyyyMMdd")
@Option(name = "d", longName = "date", description = "Start date")
public Date getCreationDate() {
return creationDate;
}

/** @return A meaningless integer value */
/**
* @return A meaningless integer value
*/
@Option(name = "l", longName = "level", description = "A meaningless integer value")
public final int getIntValue() {
return intValue;
}

/** @return Multi value string field example */
/**
* @return Multi value string field example
*/
@MultiValue
@Argument(description = "User account name")
public final List<String> getUserNames() {
return userNames;
}

/** @param action Enum example */
/**
* @param action Enum example
*/
public final void setAction(UserControlAction action) {
this.action = action;
}

/** @param creationDate A date example that needs customized conversion rule */
/**
* @param creationDate A date example that needs customized conversion rule
*/
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}

/** @param intValue A meaningless integer value */
/**
* @param intValue A meaningless integer value
*/
public final void setIntValue(int intValue) {
this.intValue = intValue;
}

/** @param userNames Multi value string field example */
/**
* @param userNames Multi value string field example
*/
public final void setUserNames(List<String> userNames) {
this.userNames = userNames;
}
Expand All @@ -80,7 +96,9 @@ public String toString() {
.toString();
}

/** @param args Command line arguments */
/**
* @param args Command line arguments
*/
public static void main(String[] args) {
UserControl control = new UserControl();
ArgumentProcessor.forType(UserControl.class).process(args, control);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
class AnnotationArgument implements org.cyclopsgroup.jcli.spi.Argument {
private Argument argument;

/** @param argument Argument annotation */
/**
* @param argument Argument annotation
*/
AnnotationArgument(Argument argument) {
this.argument = argument;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/cyclopsgroup/jcli/impl/AnnotationCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class AnnotationCli implements org.cyclopsgroup.jcli.spi.Cli {

private final boolean undefined;

/** @param cli Annotation cli */
/**
* @param cli Annotation cli
*/
AnnotationCli(Cli cli) {
this.cli = cli;
this.undefined = cli == null;
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/cyclopsgroup/jcli/impl/OptionHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public class OptionHelp {
this.option = option;
}

/** @return Description of option */
/**
* @return Description of option
*/
@FixLengthField(start = 30, length = 220)
public String getDescription() {
String desc = option.getDescription();
Expand All @@ -28,19 +30,25 @@ public String getDescription() {
return desc;
}

/** @return Name of option value */
/**
* @return Name of option value
*/
@FixLengthField(start = 20, length = 9)
public String getDisplayName() {
return option.isFlag() ? null : "<" + option.getDisplayName() + ">";
}

/** @return Long name of option */
/**
* @return Long name of option
*/
@FixLengthField(start = 3, length = 16)
public String getLongName() {
return Strings.isNullOrEmpty(option.getLongName()) ? null : "--" + option.getLongName();
}

/** @return Short name of option */
/**
* @return Short name of option
*/
@FixLengthField(start = 0, length = 2)
public String getName() {
return "-" + option.getName();
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/org/cyclopsgroup/jcli/jline/ArgumentsInspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ class ArgumentsInspector {

private ArgumentsInspectorState state = ArgumentsInspectorState.READY;

/** @param context Parsing context */
/**
* @param context Parsing context
*/
ArgumentsInspector(ParsingContext context) {
this.context = context;
remainingOptions = new HashSet<Option>(context.options());
}

/** @param argument Argument to consume */
/**
* @param argument Argument to consume
*/
void consume(String argument) {
if (argument.startsWith("--")) {
state = ArgumentsInspectorState.LONG_OPTION;
Expand Down Expand Up @@ -89,22 +93,30 @@ void end() {
currentValue = null;
}

/** @return The option being processed currently */
/**
* @return The option being processed currently
*/
Option getCurrentOption() {
return currentOption;
}

/** @return Current value */
/**
* @return Current value
*/
String getCurrentValue() {
return currentValue;
}

/** @return Set of remaining options */
/**
* @return Set of remaining options
*/
Set<Option> getRemainingOptions() {
return Collections.unmodifiableSet(remainingOptions);
}

/** @return Current parsing state */
/**
* @return Current parsing state
*/
ArgumentsInspectorState getState() {
return state;
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/cyclopsgroup/jcli/spi/Argument.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
* @author <a href="mailto:jiaqi@cyclopsgroup.org">Jiaqi Guo</a>
*/
public interface Argument {
/** @return Description of arguments */
/**
* @return Description of arguments
*/
String getDescription();

/** @return Displayable argument name in help page */
/**
* @return Displayable argument name in help page
*/
String getDisplayName();
}
Loading