Skip to content

Commit

Permalink
Change --version and -version options to output EpubCheck version (PR #…
Browse files Browse the repository at this point in the history
…841 resolves #743)

* Change --version and -version options to output EpubCheck version

* Add command line unit tests for help and version; correct a message to mention option -v instead of -version
  • Loading branch information
kamorrissey authored and tofi86 committed May 2, 2018
1 parent d66ec72 commit e498c61
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/main/java/com/adobe/epubcheck/tool/EpubChecker.java
Expand Up @@ -591,7 +591,7 @@ private boolean processArguments(String[] args)
setCustomMessageFileFromEnvironment();
for (int i = 0; i < args.length; i++)
{
if (args[i].equals("--version") || args[i].equals("-version") || args[i].equals("-v"))
if (args[i].equals("-v"))
{
if (i + 1 < args.length)
{
Expand Down Expand Up @@ -813,6 +813,10 @@ else if (args[i].equals("--help") || args[i].equals("-help") || args[i].equals("
{
displayHelp(); // display help message
}
else if (args[i].equals("--version") || args[i].equals("-version"))
{
displayVersion();
}
else
{
if (path == null)
Expand Down Expand Up @@ -902,4 +906,12 @@ private static void displayHelp()
{
outWriter.println(String.format(Messages.get("help_text"), EpubCheck.version()));
}

/**
* This method displays the EpubCheck version.
*/
private static void displayVersion()
{
outWriter.println(String.format(Messages.get("epubcheck_version_text"), EpubCheck.version()));
}
}
Expand Up @@ -17,7 +17,7 @@ error_processing_unexpanded_epub=\nThis check cannot process expanded epubs\n
deleting_archive=\nEpub creation cancelled due to detected errors.\n
display_help=-help displays help
argument_needed=At least one argument expected
version_argument_expected=Version number omitted from the -version argument.
version_argument_expected=Version number omitted from the -v argument.
mode_argument_expected=Type omitted from the -mode argument.
profile_argument_expected=Profile name omitted after the -profile argument.
profile_unknown=Unknown profile '%1$s', using default validation profile.
Expand All @@ -33,6 +33,7 @@ epubcheck_completed=epubcheck completed
error_creating_config_file=Error creating config file '%1$s'.
expected_message_filename=Expected the Custom message file name, but found '%1$s'
unrecognized_argument=Unrecognized argument: '%1$s'
epubcheck_version_text=EpubCheck v%1$s
help_text = \
EpubCheck v%1$s\n\n\
Expand Down Expand Up @@ -89,5 +90,7 @@ help_text = \
\ or the console\n\
-c, --customMessages [<file>] = override message severity levels as defined in the custom message file named <file>\n\
\n\
--version = displays the EpubCheck version\n\
\n\
-h, -? or --help = displays this help message\n
37 changes: 37 additions & 0 deletions src/test/java/com/adobe/epubcheck/cli/CLITest.java
Expand Up @@ -173,6 +173,43 @@ public void testQuietRunWithOutput()
xmlOut.delete();
}
}

@Test
public void testHelpRun1()
{
assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "--help"}));
}

@Test
public void testHelpRun2()
{
assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "-h"}));
}

@Test
public void testHelpRun3()
{
assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "-?"}));
}

@Test
public void testVersionRun1()
{
assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "--version"}));
}

@Test
public void testVersionRun2()
{
assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "-version"}));
}

@Test
public void testInvalidOption()
{
/* Make sure an unrecognized option generates an error. */
assertEquals(1, run(new String[]{epubPath + "valid/lorem.epub", "--invalidoption"}));
}

private int run(String[] args, boolean verbose)
{
Expand Down

0 comments on commit e498c61

Please sign in to comment.