Skip to content

CLI: Add --version to CLI option #7549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion app/test/processing/app/CommandLineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.File;

import org.apache.commons.compress.utils.IOUtils;
import org.fest.assertions.Assertions;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -126,5 +127,24 @@ public void testCommandLinePreferencesSave() throws Exception {

prefs = new PreferencesMap(prefFile);
assertEquals("preference should be saved", "xxx", prefs.get("test_pref"));
}
}

@Test
public void testCommandLineVersion() throws Exception {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(new String[]{
arduinoPath.getAbsolutePath(),
"--version",
});
pr.waitFor();

Assertions.assertThat(pr.exitValue())
.as("Process will finish with exit code 0 in --version")
.isEqualTo(0);
Assertions.assertThat(new String(IOUtils.toByteArray(pr.getInputStream())))
.matches("Arduino: \\d+\\.\\d+\\.\\d+.*\n");
Assertions.assertThat(new String(IOUtils.toByteArray(pr.getInputStream())))
.as("Currently, STDERR is not used in --version.")
.isEqualTo("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class CommandlineParser {

private enum ACTION {
GUI, NOOP, VERIFY("--verify"), UPLOAD("--upload"), GET_PREF("--get-pref"), INSTALL_BOARD("--install-boards"), INSTALL_LIBRARY("--install-library");
GUI, NOOP, VERIFY("--verify"), UPLOAD("--upload"), GET_PREF("--get-pref"), INSTALL_BOARD("--install-boards"), INSTALL_LIBRARY("--install-library"), VERSION("--version");

final String value;

Expand Down Expand Up @@ -52,6 +52,7 @@ public CommandlineParser(String[] args) {
actions.put("--get-pref", ACTION.GET_PREF);
actions.put("--install-boards", ACTION.INSTALL_BOARD);
actions.put("--install-library", ACTION.INSTALL_LIBRARY);
actions.put("--version", ACTION.VERSION);
}

public void parseArgumentsPhase1() {
Expand Down Expand Up @@ -84,6 +85,10 @@ public void parseArgumentsPhase1() {
}
libraryToInstall = args[i];
}
if (a == ACTION.VERSION) {
BaseNoGui.showMessage("Arduino", BaseNoGui.VERSION_NAME_LONG);
System.exit(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like this exit here, this bypasses any cleanup that would normally (perhaps) run after this function returns. Also, this function is expected to parse arguments only, not act on them. Also, passing --version --verify now just acts on --version, instead of showing an error that only one of them can be passed.

Better would seem to set action here, and act on it elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right!
Thank you for your comment.

}
action = a;
continue;
}
Expand Down
5 changes: 5 additions & 0 deletions build/shared/manpage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ SYNOPSIS

*arduino* [*--install-library* __library name__[:__version__][,__library name__[:__version__],__library name__[:__version__]]

*arduino* [*--version*]

DESCRIPTION
-----------
The 'arduino' integrated development environment allows editing,
Expand Down Expand Up @@ -83,6 +85,9 @@ ACTIONS
Fetches available libraries list and install the specified one. If __version__ is omitted, the latest is installed. If a library with the same version is already installed, nothing is installed and program exits with exit code 1. If a library with a different version is already installed, it's replaced.
Multiple libraries can be specified, separated by a comma.

*--version*::
Print the version information and exit.

OPTIONS
-------
*--board* __package__:__arch__:__board__[:__parameters__]::
Expand Down