Package com.beust.jcommander

Examples of com.beust.jcommander.JCommander


  }

    @Test
    public void hiddenCommandTest() {
        CommandMain cm = new CommandMain();
        JCommander jc = new JCommander(cm);
        CommandAdd add = new CommandAdd();
        jc.addCommand("add", add);
        CommandHidden hidden = new CommandHidden();
        jc.addCommand("hidden", hidden);
        jc.parse("hidden", "-i", "A.java");

        Assert.assertEquals(jc.getParsedCommand(), "hidden");
        Assert.assertEquals(hidden.interactive.booleanValue(), true);
        Assert.assertEquals(hidden.patterns, Arrays.asList("A.java"));

        jc.setProgramName("TestCommander");
        StringBuilder out = new StringBuilder();
        jc.usage(out);

        Assert.assertTrue(out.toString().contains("add      Add file contents to the index"));
        Assert.assertFalse(out.toString().contains("hidden      Hidden command to add file contents to the index"));
    }
View Full Code Here


*/
public class CommandAliasTest {
  @Test
  public void oneCommandWithSingleAlias() {
    CommandMain cm = new CommandMain();
    JCommander jc = new JCommander(cm);
    CommandAdd add = new CommandAdd();
    jc.addCommand("add", add, "a");
    jc.parse("a", "-i", "A.java");

    Assert.assertEquals(jc.getParsedCommand(), "add");
    Assert.assertEquals(jc.getParsedAlias(), "a");
    Assert.assertEquals(add.interactive.booleanValue(), true);
    Assert.assertEquals(add.patterns, Arrays.asList("A.java"));
  }
View Full Code Here

    testCommitWithAlias("cmt");
  }

  private void testCommitWithAlias(String alias) {
    CommandMain cm = new CommandMain();
    JCommander jc = new JCommander(cm);
    CommandCommit commit = new CommandCommit();
    jc.addCommand("commit", commit, "ci", "cmt");
    jc.parse(alias, "--amend", "--author", "jack", "file1.txt");

    Assert.assertEquals(jc.getParsedCommand(), "commit");
    Assert.assertEquals(jc.getParsedAlias(), alias);
    Assert.assertEquals(commit.amend.booleanValue(), true);
    Assert.assertEquals(commit.author, "jack");
    Assert.assertEquals(commit.files, Arrays.asList("file1.txt"));
  }
View Full Code Here

  }

  @Test
  public void twoCommandsWithAliases() {
    CommandMain cm = new CommandMain();
    JCommander jc = new JCommander(cm);
    CommandAdd add = new CommandAdd();
    jc.addCommand("add", add, "a");
    CommandCommit commit = new CommandCommit();
    jc.addCommand("commit", commit, "ci", "cmt");
    jc.parse("a", "-i", "A.java");

    Assert.assertEquals(jc.getParsedCommand(), "add");
    Assert.assertEquals(add.interactive.booleanValue(), true);
    Assert.assertEquals(add.patterns, Arrays.asList("A.java"));
  }
View Full Code Here

  }

  @Test
  public void clashingAliasesAreNotAllowed() {
    CommandMain cm = new CommandMain();
    JCommander jc = new JCommander(cm);
    CommandAdd add = new CommandAdd();
    jc.addCommand("add", add, "xx");
    CommandCommit commit = new CommandCommit();
    try {
      jc.addCommand("commit", commit, "ci", "xx");
      Assert.fail("Should not be able to register clashing alias 'xx'");
    } catch (ParameterException pe) {
      //Make sure the message mentions that "xx" aliases is already
      //defined for "add" command
      Assert.assertTrue(pe.getMessage().contains("xx"));
View Full Code Here

  }

  @Test
  public void mainCommandReturnsNullsForGetCommandAndGetParsedAlias() {
    CommandMain cm = new CommandMain();
    JCommander jc = new JCommander(cm);
    Assert.assertNull(jc.getParsedCommand());
    Assert.assertNull(jc.getParsedAlias());
  }
View Full Code Here

  }

  @Test
  public void usageCanBeRetrievedWithBothCommandAndAlias() {
    CommandMain cm = new CommandMain();
    JCommander jc = new JCommander(cm);
    CommandCommit commit = new CommandCommit();
    jc.addCommand("commit", commit, "ci", "cmt");
    StringBuilder out = new StringBuilder();
    jc.usage("commit", out);
    patternMatchesTimes("commit\\(ci,cmt\\)", out.toString(), 1);

    out = new StringBuilder();
    jc.usage("ci", out);
    patternMatchesTimes("commit\\(ci,cmt\\)", out.toString(), 1);

    out = new StringBuilder();
    jc.usage("cmt", out);
    patternMatchesTimes("commit\\(ci,cmt\\)", out.toString(), 1);
  }
View Full Code Here

  }

  @Test
  public void usageDisplaysCommandWithAliasesOnlyOnce() {
    CommandMain cm = new CommandMain();
    JCommander jc = new JCommander(cm);
    CommandCommit commit = new CommandCommit();
    jc.addCommand("commit", commit, "ci", "cmt");
    StringBuilder out = new StringBuilder();
    jc.usage(out);
    // The usage should display this string twice: one as the command name
    // and one after Usage:
    patternMatchesTimes("commit\\(ci,cmt\\)", out.toString(), 2);
  }
View Full Code Here

   * Visually test the formatting for "prettiness"
   */
  @Test(enabled = false, description = "TODO: test the output instead of displaying it")
  public void formattingLooksNice(){
    CommandMain cm = new CommandMain();
    JCommander jc = new JCommander(cm);
    CommandAdd add = new CommandAdd();
    jc.addCommand("add", add, "a");
    CommandCommit commit = new CommandCommit();
    jc.addCommand("commit", commit, "ci", "cmt");
    StringBuilder sb = new StringBuilder();
    jc.usage(sb);
    System.out.println("--- usage() formatting ---");
    System.out.println(sb.toString());

    sb = new StringBuilder();
    jc.usage("commit", sb);
    System.out.println("--- usage('commit') formatting ---");
    System.out.println(sb.toString());
  }
View Full Code Here

  }

  public static StartupParameters setupParameters(String[] args) {
    StartupParameters params = new StartupParameters(args);
    try {
      new JCommander(params, args);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    Utils.setStartupParameters(params);
View Full Code Here

TOP

Related Classes of com.beust.jcommander.JCommander

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.