Skip to content

Commit

Permalink
Format with Google style
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaqi committed Feb 7, 2018
1 parent 4f9e1ce commit 9f2da75
Show file tree
Hide file tree
Showing 35 changed files with 1,065 additions and 1,232 deletions.
48 changes: 24 additions & 24 deletions src/main/java/org/cyclopsgroup/jcli/ArgumentProcessorFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@
*
* @author <a href="mailto:[email protected]">Jiaqi Guo</a>
*/
public abstract class ArgumentProcessorFactory
{
/**
* @return Instance of ArgumentProcessorFactory. The implementation is determined by {@link ServiceLoader}
*/
static ArgumentProcessorFactory getInstance()
{
Iterator<ArgumentProcessorFactory> factories = ServiceLoader.load( ArgumentProcessorFactory.class ).iterator();
if ( factories.hasNext() )
{
return factories.next();
}
throw new AssertionError( "Can't find an implementation of " + ArgumentProcessorFactory.class.getName()
+ " from service loader" );
public abstract class ArgumentProcessorFactory {
/**
* @return Instance of ArgumentProcessorFactory. The implementation is determined by
* {@link ServiceLoader}
*/
static ArgumentProcessorFactory getInstance() {
Iterator<ArgumentProcessorFactory> factories =
ServiceLoader.load(ArgumentProcessorFactory.class).iterator();
if (factories.hasNext()) {
return factories.next();
}
throw new AssertionError("Can't find an implementation of "
+ ArgumentProcessorFactory.class.getName() + " from service loader");
}

/**
* Create new instance of {@link ArgumentProcessor}. The implementation of factory needs to implement this method to
* create customized argument processor
*
* @param <T> Type of bean to process
* @param beanType Type of bean to process
* @param parser Command line parser that is aware of command line syntax
* @return Instance of argument processor implementation
*/
protected abstract <T> ArgumentProcessor<T> newProcessor( Class<? extends T> beanType, CommandLineParser parser );
/**
* Create new instance of {@link ArgumentProcessor}. The implementation of factory needs to
* implement this method to create customized argument processor
*
* @param <T> Type of bean to process
* @param beanType Type of bean to process
* @param parser Command line parser that is aware of command line syntax
* @return Instance of argument processor implementation
*/
protected abstract <T> ArgumentProcessor<T> newProcessor(Class<? extends T> beanType,
CommandLineParser parser);
}
33 changes: 16 additions & 17 deletions src/main/java/org/cyclopsgroup/jcli/AutoCompletable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@
*
* @author <a href="mailto:[email protected]">Jiaqi Guo</a>
*/
public interface AutoCompletable
{
/**
* Suggest candidates for an option with given partial input
*
* @param optionName Name of option
* @param partialOption Given partial input
* @return List of candidates or NULL if it can't figure out
*/
List<String> suggestOption( String optionName, String partialOption );
public interface AutoCompletable {
/**
* Suggest candidates for an option with given partial input
*
* @param optionName Name of option
* @param partialOption Given partial input
* @return List of candidates or NULL if it can't figure out
*/
List<String> suggestOption(String optionName, String partialOption);

/**
* Suggest candidates for argument with given partial input
*
* @param partialArgument Partial argument input
* @return List of candidates or NULL if it can't figure out
*/
List<String> suggestArgument( String partialArgument );
/**
* Suggest candidates for argument with given partial input
*
* @param partialArgument Partial argument input
* @return List of candidates or NULL if it can't figure out
*/
List<String> suggestArgument(String partialArgument);
}
157 changes: 70 additions & 87 deletions src/main/java/org/cyclopsgroup/jcli/ValidationResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,111 +9,94 @@
/**
* Argument validation result coming from {@link ArgumentProcessor#validate(String[])}
*/
public final class ValidationResult
{
/**
* A violation indicating required argument is missing
*/
public static final class ArgumentMissing
extends Violation
{
}

/**
* Type of violation where a required option is missing
*/
public static final class OptionMissing
extends Violation
{
private final String optionName;
public final class ValidationResult {
/**
* A violation indicating required argument is missing
*/
public static final class ArgumentMissing extends Violation {
}

/**
* @param optionName Name of missing option
*/
public OptionMissing( String optionName )
{
Validate.notNull( optionName, "Name of missing option can't be NULL" );
this.optionName = optionName;
}

/**
* Get name of missing option
*
* @return optionName Name of option missed
*/
public String getOptionName()
{
return optionName;
}
}
/**
* Type of violation where a required option is missing
*/
public static final class OptionMissing extends Violation {
private final String optionName;

/**
* Violation where an unexpected option value is found
* @param optionName Name of missing option
*/
public static final class UnexpectedOption
extends Violation
{
private final String optionName;

/**
* @param optionName Name of unexpected option
*/
public UnexpectedOption( String optionName )
{
Validate.notNull( optionName, "Name of missing option can't be NULL" );
this.optionName = optionName;
}

/**
* Get name of missing option
*
* @return optionName Name of option missed
*/
public String getOptionName()
{
return optionName;
}
public OptionMissing(String optionName) {
Validate.notNull(optionName, "Name of missing option can't be NULL");
this.optionName = optionName;
}

/**
* A validation violation
* Get name of missing option
*
* @return optionName Name of option missed
*/
public static abstract class Violation
{
Violation()
{
}
public String getOptionName() {
return optionName;
}
}

private final List<Violation> violations = new ArrayList<Violation>();
/**
* Violation where an unexpected option value is found
*/
public static final class UnexpectedOption extends Violation {
private final String optionName;

/**
* Add a new violation to validation result
*
* @param <T> Type of validation violation
* @param violation Violation
* @param optionName Name of unexpected option
*/
public <T extends Violation> void addViolation( T violation )
{
violations.add( violation );
public UnexpectedOption(String optionName) {
Validate.notNull(optionName, "Name of missing option can't be NULL");
this.optionName = optionName;
}

/**
* Get list of violations in result
* Get name of missing option
*
* @return List of violations in result
* @return optionName Name of option missed
*/
public List<Violation> getViolations()
{
return Collections.unmodifiableList( violations );

public String getOptionName() {
return optionName;
}
}

/**
* @return True if there is not violation
*/
public boolean isValid()
{
return violations.isEmpty();
}
/**
* A validation violation
*/
public static abstract class Violation {
Violation() {}
}

private final List<Violation> violations = new ArrayList<Violation>();

/**
* Add a new violation to validation result
*
* @param <T> Type of validation violation
* @param violation Violation
*/
public <T extends Violation> void addViolation(T violation) {
violations.add(violation);
}

/**
* Get list of violations in result
*
* @return List of violations in result
*/
public List<Violation> getViolations() {
return Collections.unmodifiableList(violations);

}

/**
* @return True if there is not violation
*/
public boolean isValid() {
return violations.isEmpty();
}
}
27 changes: 13 additions & 14 deletions src/main/java/org/cyclopsgroup/jcli/annotation/Argument.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@
import java.lang.annotation.Target;

/**
* This annotation marks a property as non-option argument or arguments. Type of this property can be array, List or
* single value.
* This annotation marks a property as non-option argument or arguments. Type of this property can
* be array, List or single value.
*
* @author <a href="mailto:[email protected]">Jiaqi Guo</a>
*/
@Documented
@Target( { ElementType.METHOD, ElementType.FIELD } )
@Retention( RetentionPolicy.RUNTIME )
public @interface Argument
{
/**
* @return String description of argument which will be displayed in usage
*/
String description() default "";
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Argument {
/**
* @return String description of argument which will be displayed in usage
*/
String description() default "";

/**
* @return Name of argument displayed in usage
*/
String displayName() default "arg";
/**
* @return Name of argument displayed in usage
*/
String displayName() default "arg";
}
39 changes: 19 additions & 20 deletions src/main/java/org/cyclopsgroup/jcli/annotation/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,26 @@
* @author <a href="mailto:[email protected]">Jiaqi Guo</a>
*/
@Documented
@Target( ElementType.TYPE )
@Retention( RetentionPolicy.RUNTIME )
public @interface Cli
{
/**
* @return String description of command
*/
String description() default "";
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface Cli {
/**
* @return String description of command
*/
String description() default "";

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

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

/**
* @return True if unexpected option or argument is expected to cause error
*/
boolean restrict() default true;
/**
* @return True if unexpected option or argument is expected to cause error
*/
boolean restrict() default true;
}
Loading

0 comments on commit 9f2da75

Please sign in to comment.