CliUtils.java

1
package com.github.dakusui.symfonion.cli;
2
3
import com.github.dakusui.symfonion.exceptions.CliException;
4
import com.github.dakusui.symfonion.song.Keyword;
5
import org.apache.commons.cli.CommandLine;
6
7
import java.io.File;
8
9
import static java.lang.String.format;
10
11
public enum CliUtils {
12
  ;
13
  
14
  /**
15
     * A method to compose an error message for a specified option.
16
     * This is equivalent to call {@code composeErrMsg(msg, optionName, null}.
17
     *
18
     * @param msg        A message for the option.
19
     * @param optionName A short form of the option.
20
     * @return THe composed message.
21
     */
22
    public static String composeErrMsg(String msg, String optionName) {
23 1 1. composeErrMsg : replaced return value with "" for com/github/dakusui/symfonion/cli/CliUtils::composeErrMsg → NO_COVERAGE
      return composeErrMsg(msg, optionName, null);
24
    }
25
  
26
  /**
27
     * A method to compose an error message for a specified option.
28
     *
29
     * @param msg            A message for the option.
30
     * @param optionName     A short form of the option.
31
     * @param longOptionName A long form of the option.
32
     * @return The composed message.
33
     */
34
    public static String composeErrMsg(String msg, String optionName, String longOptionName) {
35 1 1. composeErrMsg : negated conditional → NO_COVERAGE
      if (longOptionName != null) {
36 1 1. composeErrMsg : replaced return value with "" for com/github/dakusui/symfonion/cli/CliUtils::composeErrMsg → NO_COVERAGE
        return format("(-%s/--%s) %s", optionName, longOptionName, msg);
37
      } else {
38 1 1. composeErrMsg : replaced return value with "" for com/github/dakusui/symfonion/cli/CliUtils::composeErrMsg → NO_COVERAGE
        return format("(-%s) %s", optionName, msg);
39
      }
40
    }
41
  
42
  static String getSingleOptionValueFromCommandLine(CommandLine cmd, String optionName)
43
      throws CliException {
44
    String ret = cmd.getOptionValue(optionName);
45
    int sz = cmd.getOptionProperties(optionName).size();
46 1 1. getSingleOptionValueFromCommandLine : negated conditional → KILLED
    if (sz != 1) {
47
      String msg = composeErrMsg(format(
48
              "This option requires one and only one value. (found %d times)", sz),
49
          optionName, null);
50
      throw new CliException(msg);
51
    }
52 1 1. getSingleOptionValueFromCommandLine : replaced return value with "" for com/github/dakusui/symfonion/cli/CliUtils::getSingleOptionValueFromCommandLine → KILLED
    return ret;
53
  }
54
  
55
  public static File composeOutputFile(String outfile, String portName) {
56 2 1. composeOutputFile : negated conditional → SURVIVED
2. composeOutputFile : negated conditional → SURVIVED
    if (portName == null || Keyword.$default.name().equals(portName)) {
57 1 1. composeOutputFile : replaced return value with null for com/github/dakusui/symfonion/cli/CliUtils::composeOutputFile → NO_COVERAGE
      return new File(outfile);
58
    }
59
    File ret;
60
    int lastIndexOfDot = outfile.lastIndexOf('.');
61 1 1. composeOutputFile : negated conditional → SURVIVED
    if (lastIndexOfDot == -1) {
62
      ret = new File(outfile + "." + portName);
63
    } else {
64
      ret = new File(outfile.substring(0, lastIndexOfDot) + "." + portName
65
          + outfile.substring(lastIndexOfDot));
66
    }
67 1 1. composeOutputFile : replaced return value with null for com/github/dakusui/symfonion/cli/CliUtils::composeOutputFile → KILLED
    return ret;
68
  }
69
}

Mutations

23

1.1
Location : composeErrMsg
Killed by : none
replaced return value with "" for com/github/dakusui/symfonion/cli/CliUtils::composeErrMsg → NO_COVERAGE

35

1.1
Location : composeErrMsg
Killed by : none
negated conditional → NO_COVERAGE

36

1.1
Location : composeErrMsg
Killed by : none
replaced return value with "" for com/github/dakusui/symfonion/cli/CliUtils::composeErrMsg → NO_COVERAGE

38

1.1
Location : composeErrMsg
Killed by : none
replaced return value with "" for com/github/dakusui/symfonion/cli/CliUtils::composeErrMsg → NO_COVERAGE

46

1.1
Location : getSingleOptionValueFromCommandLine
Killed by : com.github.dakusui.symfonion.tests.MalformedTest.givenMalformed_brokenObject(com.github.dakusui.symfonion.tests.MalformedTest)
negated conditional → KILLED

52

1.1
Location : getSingleOptionValueFromCommandLine
Killed by : com.github.dakusui.symfonion.tests.MalformedTest.givenMalformed_brokenObject(com.github.dakusui.symfonion.tests.MalformedTest)
replaced return value with "" for com/github/dakusui/symfonion/cli/CliUtils::getSingleOptionValueFromCommandLine → KILLED

56

1.1
Location : composeOutputFile
Killed by : none
negated conditional → SURVIVED

2.2
Location : composeOutputFile
Killed by : none
negated conditional → SURVIVED

57

1.1
Location : composeOutputFile
Killed by : none
replaced return value with null for com/github/dakusui/symfonion/cli/CliUtils::composeOutputFile → NO_COVERAGE

61

1.1
Location : composeOutputFile
Killed by : none
negated conditional → SURVIVED

67

1.1
Location : composeOutputFile
Killed by : com.github.dakusui.symfonion.tests.cli.subcommands.CompileTest.test(com.github.dakusui.symfonion.tests.cli.subcommands.CompileTest)
replaced return value with null for com/github/dakusui/symfonion/cli/CliUtils::composeOutputFile → KILLED

Active mutators

Tests examined


Report generated by PIT 1.15.3