Exemplo n.º 1
0
  @Test
  public void testVersionComponents() throws IOException {
    // @formatter:off
    SingleCommand<ArgsVersion2> command = singleCommand(ArgsVersion2.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new CliCommandUsageGenerator()
        .usage(null, null, "test", command.getCommandMetadata(), null, out);
    testStringAssert(
        new String(out.toByteArray(), utf8),
        "NAME\n"
            + "        test - Multiple component versions\n"
            + "\n"
            + "SYNOPSIS\n"
            + "        test\n"
            + "\n"
            + "VERSION\n"
            + "            Component: Airline Test\n"
            + "            Version: 1.2.3\n"
            + "            Build: 12345abcde\n"
            + "\n"
            + "            Component: Foo\n"
            + "            Build: 789\n"
            + "            Build Date: Feb 2016\n"
            + "            Author: Mr Foo\n"
            + "\n"
            + "            Component: Bar\n"
            + "            Version: 1.0.7\n"
            + "            Built With: Oracle JDK 1.7\n"
            + "            Author: Mrs Bar\n");
    // @formatter:on
  }
Exemplo n.º 2
0
  @Test
  public void testArgsAllowedValues() throws IOException {
    // @formatter:off
    SingleCommand<ArgsAllowedValues> command = singleCommand(ArgsAllowedValues.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new CliCommandUsageGenerator()
        .usage(
            "test",
            null,
            command.getCommandMetadata().getName(),
            command.getCommandMetadata(),
            null,
            out);
    assertEquals(
        new String(out.toByteArray(), utf8),
        "NAME\n"
            + "        test ArgsAllowedValues - ArgsAllowedValues description\n"
            + "\n"
            + "SYNOPSIS\n"
            + "        test ArgsAllowedValues [ -mode <mode> ]\n"
            + "\n"
            + "OPTIONS\n"
            + "        -mode <mode>\n"
            + "            A string from a restricted set of values\n"
            + "\n"
            + "            This options value is restricted to the following set of values:\n"
            + "                a\n"
            + "                b\n"
            + "                c\n"
            + "\n");

    // @formatter:on
  }
Exemplo n.º 3
0
  public void testExamples() throws IOException {
    SingleCommand<ArgsExamples> cmd = singleCommand(ArgsExamples.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Help.help(cmd.getCommandMetadata(), out);
    // @formatter:off
    testStringAssert(
        new String(out.toByteArray(), utf8),
        "NAME\n"
            + "        ArgsExamples -\n"
            + "\n"
            + "SYNOPSIS\n"
            + "        ArgsExamples\n"
            + "\n"
            + "EXAMPLES\n"
            + "        ArgsExample\n"
            + "\n"
            + "            Does nothing\n"
            + "\n"
            + "        ArgsExample foo bar\n"
            + "\n"
            + "            Foos a bar\n"
            + "\n");
    // @formatter:on
  }
Exemplo n.º 4
0
  @Test
  public void testSingleCommandArgs1() throws IOException {
    // @formatter:off
    SingleCommand<Args1> command = singleCommand(Args1.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new CliCommandUsageGenerator()
        .usage(null, null, "test", command.getCommandMetadata(), null, out);
    assertEquals(
        new String(out.toByteArray(), utf8),
        "NAME\n"
            + "        test - args1 description\n"
            + "\n"
            + "SYNOPSIS\n"
            + "        test [ -bigdecimal <bigd> ] [ -date <date> ] [ -debug ]\n"
            + "                [ -double <doub> ] [ -float <floa> ] [ -groups <groups> ]\n"
            + "                [ {-log | -verbose} <verbose> ] [ -long <l> ] [--] [ <parameters>... ]\n"
            + "\n"
            + "OPTIONS\n"
            + "        -bigdecimal <bigd>\n"
            + "            A BigDecimal number\n"
            + "\n"
            + "        -date <date>\n"
            + "            An ISO 8601 formatted date.\n"
            + "\n"
            + "        -debug\n"
            + "            Debug mode\n"
            + "\n"
            + "        -double <doub>\n"
            + "            A double number\n"
            + "\n"
            + "        -float <floa>\n"
            + "            A float number\n"
            + "\n"
            + "        -groups <groups>\n"
            + "            Comma-separated list of group names to be run\n"
            + "\n"
            + "        -log <verbose>, -verbose <verbose>\n"
            + "            Level of verbosity\n"
            + "\n"
            + "        -long <l>\n"
            + "            A long number\n"
            + "\n"
            + "        --\n"
            + "            This option can be used to separate command-line options from the\n"
            + "            list of arguments (useful when arguments might be mistaken for\n"
            + "            command-line options)\n"
            + "\n"
            + "        <parameters>\n"
            + "\n"
            + "\n");
    // @formatter:on
  }
Exemplo n.º 5
0
  public void testHiddenDiscussion() throws IOException {
    SingleCommand<ArgsHiddenDiscussion> cmd = singleCommand(ArgsHiddenDiscussion.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Help.help(cmd.getCommandMetadata(), out);
    // @formatter:off
    testStringAssert(
        new String(out.toByteArray(), utf8),
        "NAME\n"
            + "        ArgsHiddenDiscussion -\n"
            + "\n"
            + "SYNOPSIS\n"
            + "        ArgsHiddenDiscussion\n"
            + "\n");
    // @formatter:on
  }
Exemplo n.º 6
0
  @Test
  public void testPartialRestriction() throws IOException {
    // @formatter:off
    SingleCommand<PartialAnnotated> command = singleCommand(PartialAnnotated.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new CliCommandUsageGenerator()
        .usage(
            "test",
            null,
            command.getCommandMetadata().getName(),
            command.getCommandMetadata(),
            null,
            out);
    assertEquals(
        new String(out.toByteArray()),
        StringUtils.join(
            new String[] {
              "NAME",
              "        test partial -",
              "",
              "SYNOPSIS",
              "        test partial [ --kvp <kvps>... ] [--] [ <args>... ]",
              "",
              "OPTIONS",
              "        --kvp <kvps> <kvps>",
              "",
              "",
              "            The following restriction only applies to the 1st value:",
              "            This options value cannot be blank (empty or all whitespace)",
              "",
              "",
              "        --",
              "            This option can be used to separate command-line options from the",
              "            list of arguments (useful when arguments might be mistaken for",
              "            command-line options)",
              "",
              "        <args>",
              "",
              "",
              ""
            },
            '\n'));
    // @formatter:on
  }
Exemplo n.º 7
0
  @Test
  public void testVersionMissingSupressed() throws IOException {
    // @formatter:off
    SingleCommand<ArgsVersionMissingSuppressed> command =
        singleCommand(ArgsVersionMissingSuppressed.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new CliCommandUsageGenerator()
        .usage(null, null, "test", command.getCommandMetadata(), null, out);
    testStringAssert(
        new String(out.toByteArray(), utf8),
        "NAME\n"
            + "        test - Missing version information\n"
            + "\n"
            + "SYNOPSIS\n"
            + "        test\n"
            + "\n");
    // @formatter:on
  }
Exemplo n.º 8
0
  @Test
  public void testVersion() throws IOException {
    // @formatter:off
    SingleCommand<ArgsVersion> command = singleCommand(ArgsVersion.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new CliCommandUsageGenerator()
        .usage(null, null, "test", command.getCommandMetadata(), null, out);
    testStringAssert(
        new String(out.toByteArray(), utf8),
        "NAME\n"
            + "        test - ArgsVersion description\n"
            + "\n"
            + "SYNOPSIS\n"
            + "        test\n"
            + "\n"
            + "VERSION\n"
            + "            Component: Airline Test\n"
            + "            Version: 1.2.3\n"
            + "            Build: 12345abcde\n");
    // @formatter:on
  }
Exemplo n.º 9
0
  public void testInheritedDiscussion() throws IOException {
    SingleCommand<ArgsInheritedDiscussion> cmd = singleCommand(ArgsInheritedDiscussion.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Help.help(cmd.getCommandMetadata(), out);
    // @formatter:off
    testStringAssert(
        new String(out.toByteArray(), utf8),
        "NAME\n"
            + "        ArgsInheritedDiscussion -\n"
            + "\n"
            + "SYNOPSIS\n"
            + "        ArgsInheritedDiscussion\n"
            + "\n"
            + "DISCUSSION\n"
            + "        First paragraph\n"
            + "\n"
            + "        Middle paragraph\n"
            + "\n"
            + "        Final paragraph\n"
            + "\n");
    // @formatter:on
  }
Exemplo n.º 10
0
  public void testMultiLineDescriptions() throws IOException {
    SingleCommand<ArgsMultiLineDescription> cmd = singleCommand(ArgsMultiLineDescription.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Help.help(cmd.getCommandMetadata(), out);
    // @formatter:off
    assertEquals(
        new String(out.toByteArray(), utf8),
        "NAME\n"
            + "        ArgsMultiLineDescription - Has\n"
            + "        some\n"
            + "        new lines\n"
            + "\n"
            + "SYNOPSIS\n"
            + "        ArgsMultiLineDescription [ -v ]\n"
            + "\n"
            + "OPTIONS\n"
            + "        -v\n"
            + "            Verbose descriptions\n"
            + "            have new lines\n"
            + "\n");
    // @formatter:on
  }
Exemplo n.º 11
0
  public void testCopyrightLicense() throws IOException {
    SingleCommand<ArgsCopyrightAndLicense> cmd = singleCommand(ArgsCopyrightAndLicense.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Help.help(cmd.getCommandMetadata(), out);
    // @formatter:off
    testStringAssert(
        new String(out.toByteArray(), utf8),
        "NAME\n"
            + "        ArgsCopyrightAndLicense -\n"
            + "\n"
            + "SYNOPSIS\n"
            + "        ArgsCopyrightAndLicense\n"
            + "\n"
            + "COPYRIGHT\n"
            + "        Copyright (c) Acme Inc 2015-2016\n"
            + "\n"
            + "LICENSE\n"
            + "        This software is open source under the Apache License 2.0\n"
            + "\n"
            + "        Please see http://apache.org/licenses/LICENSE-2.0 for more information\n"
            + "\n");
    // @formatter:on
  }
Exemplo n.º 12
0
  @Test
  public void testExitCodes() throws IOException {
    // @formatter:off
    SingleCommand<ArgsExitCodes> command = singleCommand(ArgsExitCodes.class);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new CliCommandUsageGenerator()
        .usage(null, null, "test", command.getCommandMetadata(), null, out);
    testStringAssert(
        new String(out.toByteArray(), utf8),
        "NAME\n"
            + "        test - ArgsExitCodes description\n"
            + "\n"
            + "SYNOPSIS\n"
            + "        test\n"
            + "\n"
            + "EXIT CODES\n"
            + "        This command returns one of the following exit codes:\n"
            + "\n"
            + "            0   Success\n"
            + "            1\n"
            + "            2   Error 2\n\n");
    // @formatter:on
  }