-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished docs on case sensitivity (#9), and add some examples.
- Loading branch information
1 parent
8dd32f5
commit ad406a6
Showing
4 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
picocli-examples/src/main/java/picocli/examples/casesensitivity/CaseInsensitiveDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package picocli.examples.casesensitivity; | ||
|
||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
@Command(name = "Case Insensitive Demo") | ||
public class CaseInsensitiveDemo implements Runnable { | ||
|
||
@Option(names = {"-n", "--name"}, required = false, defaultValue = "User") | ||
String name; | ||
|
||
@Command(name = "greet") | ||
public int greet() { | ||
System.out.println("Have a nice day!"); | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
System.out.println("Hi, Your name is " + name); | ||
} | ||
|
||
public static void main(String... args){ | ||
new CommandLine(new CaseInsensitiveDemo()) | ||
.setOptionsCaseInsensitive(true) // accepts `-H`, `--nAmE` | ||
.setSubcommandsCaseInsensitive(true) // accepts `gREET`, `GREET` | ||
.execute(args); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
picocli-examples/src/main/java/picocli/examples/casesensitivity/POSIXOptionResembleDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package picocli.examples.casesensitivity; | ||
|
||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
@Command(name = "POSIX Option Resemble Demo", | ||
description = "This shows what will happen if multiple POSIX options resemble a long option") | ||
public class POSIXOptionResembleDemo implements Runnable { | ||
|
||
@Option(names = "-a", required = false) | ||
boolean a; | ||
|
||
@Option(names = "-b", required = false) | ||
boolean b; | ||
|
||
@Option(names = "-c", required = false) | ||
boolean c; | ||
|
||
@Option(names = "-abc", required = false) | ||
boolean abc; | ||
|
||
@Override | ||
public void run() { | ||
System.out.println("a is " + a + "\n" + | ||
"b is " + b + "\n" + | ||
"c is " + c + "\n" + | ||
"abc is " + abc); | ||
} | ||
|
||
public static void main(String... args){ | ||
new CommandLine(new POSIXOptionResembleDemo()) | ||
.setOptionsCaseInsensitive(true) | ||
.execute(args); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...li-examples/src/main/java/picocli/examples/casesensitivity/ScopedCaseSensitivityDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package picocli.examples.casesensitivity; | ||
|
||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
@Command(name = "Scoped Case Sensitivity Demo") | ||
public class ScopedCaseSensitivityDemo implements Runnable { | ||
|
||
@Option(names = {"-n", "--name"}, required = false, defaultValue = "User") | ||
String name; | ||
|
||
@Command(name = "greet") | ||
public int greet() { | ||
System.out.println("Have a nice day!"); | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
System.out.println("Hi, Your name is " + name); | ||
} | ||
|
||
public static void main(String... args){ | ||
CommandLine commandLine = new CommandLine(new ScopedCaseSensitivityDemo()); | ||
commandLine.addSubcommand("strict", new StrictGreet()); | ||
// globally case insensitive | ||
commandLine.setOptionsCaseInsensitive(true); | ||
commandLine.setSubcommandsCaseInsensitive(true); | ||
// specifically case sensitive | ||
// accepts `strict GrEET` | ||
// rejects `strict greet`, `strict GREET`... | ||
commandLine.getSubcommands().get("strict").setSubcommandsCaseInsensitive(false); | ||
commandLine.execute(args); | ||
} | ||
} | ||
|
||
@Command(name = "Strict Greet") | ||
class StrictGreet implements Callable<Integer>{ | ||
|
||
@Command(name = "GrEET") | ||
public int greet() { | ||
System.out.println("I will only GrEET if the case is correct!"); | ||
return 0; | ||
} | ||
|
||
@Override | ||
public Integer call() { | ||
System.out.println("Entering strict zone..."); | ||
return 0; | ||
} | ||
} |