Skip to content

Commit

Permalink
[#587] Fix unoriented output messages (#593)
Browse files Browse the repository at this point in the history
Some of the messages used in RepoSense are structurally unoriented.

This include the missing transition message where --config flag is
unused, using default path for analysis and the double printing of
the help message, and the confusing arrangement of usage parameters as
shown in #587.

Let's fix these scenarios to improve the quality of our output messages.
  • Loading branch information
eugenepeh authored Mar 8, 2019
1 parent c1134fc commit 7c06d69
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 69 deletions.
3 changes: 3 additions & 0 deletions src/main/java/reposense/RepoSense.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import net.sourceforge.argparse4j.helper.HelpScreenException;
import reposense.model.AuthorConfiguration;
import reposense.model.CliArguments;
import reposense.model.ConfigCliArguments;
Expand Down Expand Up @@ -62,6 +63,8 @@ public static void main(String[] args) {
logger.log(Level.WARNING, ioe.getMessage(), ioe);
} catch (ParseException pe) {
logger.log(Level.WARNING, pe.getMessage(), pe);
} catch (HelpScreenException e) {
// help message was printed by the ArgumentParser; it is safe to exit.
}
}

Expand Down
54 changes: 33 additions & 21 deletions src/main/java/reposense/parser/ArgsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.logging.Logger;

import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.helper.HelpScreenException;
import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.impl.action.HelpArgumentAction;
import net.sourceforge.argparse4j.inf.ArgumentParser;
Expand Down Expand Up @@ -42,8 +43,11 @@ public class ArgsParser {
private static final String PROGRAM_USAGE = "java -jar RepoSense.jar";
private static final String PROGRAM_DESCRIPTION =
"RepoSense is a contribution analysis tool for Git repositories.";
private static final String MESSAGE_HEADER_MUTEX = "mutual exclusive arguments";
private static final String MESSAGE_SINCE_DATE_LATER_THAN_UNTIL_DATE =
"\"Since Date\" cannot be later than \"Until Date\"";
private static final String MESSAGE_USING_DEFAULT_CONFIG_PATH =
"Config path not provided, using current working directory as default.";
private static final Path EMPTY_PATH = Paths.get("");

private static ArgumentParser getArgumentParser() {
Expand All @@ -54,27 +58,18 @@ private static ArgumentParser getArgumentParser() {
.description(PROGRAM_DESCRIPTION);

MutuallyExclusiveGroup mutexParser = parser
.addMutuallyExclusiveGroup(PROGRAM_USAGE)
.addMutuallyExclusiveGroup(MESSAGE_HEADER_MUTEX)
.required(false);

// Boolean flags
parser.addArgument(HELP_FLAGS)
.dest(HELP_FLAGS[0])
.help("Show help message.")
.action(new HelpArgumentAction());

mutexParser.addArgument(CONFIG_FLAGS)
.dest(CONFIG_FLAGS[0])
.type(new ConfigFolderArgumentType())
.metavar("PATH")
.setDefault(EMPTY_PATH)
.help("The directory containing the config files."
+ "If not provided, the config files will be obtained from the current working directory.");

mutexParser.addArgument(REPO_FLAGS)
.nargs("+")
.dest(REPO_FLAGS[0])
.metavar("LOCATION")
.help("The GitHub URL or disk locations to clone repository.");
parser.addArgument(IGNORE_FLAGS)
.dest(IGNORE_FLAGS[0])
.action(Arguments.storeTrue())
.help("A flag to ignore the standalone config file in the repo.");

parser.addArgument(VIEW_FLAGS)
.dest(VIEW_FLAGS[0])
Expand Down Expand Up @@ -118,20 +113,31 @@ private static ArgumentParser getArgumentParser() {
+ "If not provided, default file formats will be used.\n"
+ "Please refer to userguide for more information.");

parser.addArgument(IGNORE_FLAGS)
.dest(IGNORE_FLAGS[0])
.action(Arguments.storeTrue())
.help("A flag to ignore the standalone config file in the repo.");
// Mutex flags - these will always be the last parameters in help message.
mutexParser.addArgument(CONFIG_FLAGS)
.dest(CONFIG_FLAGS[0])
.type(new ConfigFolderArgumentType())
.metavar("PATH")
.setDefault(EMPTY_PATH)
.help("The directory containing the config files."
+ "If not provided, the config files will be obtained from the current working directory.");
mutexParser.addArgument(REPO_FLAGS)
.nargs("+")
.dest(REPO_FLAGS[0])
.metavar("LOCATION")
.help("The GitHub URL or disk locations to clone repository.");

return parser;
}

/**
* Parses the given string arguments to a {@code CliArguments} object.
*
* @throws HelpScreenException if given args contain the --help flag. Help message will be printed out
* by the {@code ArgumentParser} hence this is to signal to the caller that the program is safe to exit.
* @throws ParseException if the given string arguments fails to parse to a {@code CliArguments} object.
*/
public static CliArguments parse(String[] args) throws ParseException {
public static CliArguments parse(String[] args) throws HelpScreenException, ParseException {
try {
ArgumentParser parser = getArgumentParser();
Namespace results = parser.parseArgs(args);
Expand Down Expand Up @@ -163,9 +169,15 @@ public static CliArguments parse(String[] args) throws ParseException {
isAutomaticallyLaunching, isStandaloneConfigIgnored);
}

if (configFolderPath.equals(EMPTY_PATH)) {
logger.info(MESSAGE_USING_DEFAULT_CONFIG_PATH);
}
return new ConfigCliArguments(
configFolderPath, outputFolderPath, sinceDate, untilDate, formats, isAutomaticallyLaunching);
} catch (ArgumentParserException ape) {
} catch (HelpScreenException hse) {
throw hse;
}
catch (ArgumentParserException ape) {
throw new ParseException(getArgumentParser().formatUsage() + ape.getMessage() + "\n");
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/systemtest/java/reposense/ConfigSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.junit.Before;
import org.junit.Test;

import net.sourceforge.argparse4j.helper.HelpScreenException;
import reposense.model.AuthorConfiguration;
import reposense.model.CliArguments;
import reposense.model.ConfigCliArguments;
Expand All @@ -41,14 +42,14 @@ public void setUp() throws IOException {
}

@Test
public void testNoDateRange() throws IOException, URISyntaxException, ParseException {
public void testNoDateRange() throws IOException, URISyntaxException, ParseException, HelpScreenException {
generateReport();
Path actualFiles = Paths.get(getClass().getClassLoader().getResource("noDateRange/expected").toURI());
verifyAllJson(actualFiles, FT_TEMP_DIR);
}

@Test
public void testDateRange() throws IOException, URISyntaxException, ParseException {
public void testDateRange() throws IOException, URISyntaxException, ParseException, HelpScreenException {
generateReport(getInputWithDates("1/9/2017", "30/10/2017"));
Path actualFiles = Paths.get(getClass().getClassLoader().getResource("dateRange/expected").toURI());
verifyAllJson(actualFiles, FT_TEMP_DIR);
Expand All @@ -58,11 +59,12 @@ private String getInputWithDates(String sinceDate, String untilDate) {
return String.format("--since %s --until %s", sinceDate, untilDate);
}

private void generateReport() throws IOException, URISyntaxException, ParseException {
private void generateReport() throws IOException, URISyntaxException, ParseException, HelpScreenException {
generateReport("");
}

private void generateReport(String inputDates) throws IOException, URISyntaxException, ParseException {
private void generateReport(String inputDates)
throws IOException, URISyntaxException, ParseException, HelpScreenException {
Path configFolder = Paths.get(getClass().getClassLoader().getResource("repo-config.csv").toURI()).getParent();

String formats = String.join(" ", TESTING_FILE_FORMATS);
Expand Down
Loading

0 comments on commit 7c06d69

Please sign in to comment.