Skip to content

Commit

Permalink
Method to add a single command
Browse files Browse the repository at this point in the history
  • Loading branch information
sangupta committed Nov 6, 2016
1 parent 3d13f76 commit 90c4798
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/com/sangupta/outline/Outline.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ public Outline withDefaultCommand(Class<?> defaultCommand) {
return this;
}

@Override
public Outline withCommand(Class<?> command) {
super.withCommand(command);

return this;
}

@Override
public Outline withCommands(Class<?>... commands) {
if(this.singleCommandMode) {
Expand Down Expand Up @@ -177,5 +184,9 @@ public Outline withHelpOnIncorrectArguments(boolean helpOnIncorrectArguments) {
this.helpOnIncorrectArguments = helpOnIncorrectArguments;
return this;
}


public boolean isSingleCommandMode() {
return this.singleCommandMode;
}

}
13 changes: 13 additions & 0 deletions src/main/java/com/sangupta/outline/OutlineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ public OutlineBase withDefaultCommand(Class<?> defaultCommand) {
return this;
}

public OutlineBase withCommand(Class<?> command) {
if(this.singleCommandMode) {
throw new IllegalStateException("Cannot add commands in single-command mode.");
}

if(command == null) {
return this;
}

this.commands.add(command);
return this;
}

public OutlineBase withCommands(Class<?>... commands) {
if(this.singleCommandMode) {
throw new IllegalStateException("Cannot add commands in single-command mode.");
Expand Down

0 comments on commit 90c4798

Please sign in to comment.