| 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 |
|
| 35 |
1.1 |
|
| 36 |
1.1 |
|
| 38 |
1.1 |
|
| 46 |
1.1 |
|
| 52 |
1.1 |
|
| 56 |
1.1 2.2 |
|
| 57 |
1.1 |
|
| 61 |
1.1 |
|
| 67 |
1.1 |