Skip to content

Commit af9e1f9

Browse files
committed
CLI: Add --version to CLI option
I added to get the Arduino IDE version from the command line It will allow to check easily if the new Arduino is already installed. This feature makes it easier to build external systems linked to specific versions of Arduino. 1. I added `--version` action, which shows version name and exit 1. Currently, VERSION_NAME_LONG (like `1.8.5`, `1.9.0-beta`, `1.8.6 Hourly Build XXX`, etc...) is used. Because I want to know its version number and stable/beta/hourly. 2. Finish with `0`. Because it is `SUCCESSFLLY FINISHED`. 2. Updated man page.
1 parent c792565 commit af9e1f9

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

app/test/processing/app/CommandLineTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.io.File;
3535

3636
import org.apache.commons.compress.utils.IOUtils;
37+
import org.fest.assertions.Assertions;
3738
import org.junit.Before;
3839
import org.junit.Test;
3940

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

127128
prefs = new PreferencesMap(prefFile);
128129
assertEquals("preference should be saved", "xxx", prefs.get("test_pref"));
129-
}
130+
}
131+
132+
@Test
133+
public void testCommandLineVersion() throws Exception {
134+
Runtime rt = Runtime.getRuntime();
135+
Process pr = rt.exec(new String[]{
136+
arduinoPath.getAbsolutePath(),
137+
"--version",
138+
});
139+
pr.waitFor();
140+
141+
Assertions.assertThat(pr.exitValue())
142+
.as("Process will finish with exit code 0 in --version")
143+
.isEqualTo(0);
144+
Assertions.assertThat(new String(IOUtils.toByteArray(pr.getInputStream())))
145+
.matches("Arduino: \\d+\\.\\d+\\.\\d+.*\n");
146+
Assertions.assertThat(new String(IOUtils.toByteArray(pr.getInputStream())))
147+
.as("Currently, STDERR is not used in --version.")
148+
.isEqualTo("");
149+
}
130150
}

arduino-core/src/processing/app/helpers/CommandlineParser.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public class CommandlineParser {
1717

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

2121
final String value;
2222

@@ -52,6 +52,7 @@ public CommandlineParser(String[] args) {
5252
actions.put("--get-pref", ACTION.GET_PREF);
5353
actions.put("--install-boards", ACTION.INSTALL_BOARD);
5454
actions.put("--install-library", ACTION.INSTALL_LIBRARY);
55+
actions.put("--version", ACTION.VERSION);
5556
}
5657

5758
public void parseArgumentsPhase1() {
@@ -84,6 +85,10 @@ public void parseArgumentsPhase1() {
8485
}
8586
libraryToInstall = args[i];
8687
}
88+
if (a == ACTION.VERSION) {
89+
BaseNoGui.showMessage("Arduino", BaseNoGui.VERSION_NAME_LONG);
90+
System.exit(0);
91+
}
8792
action = a;
8893
continue;
8994
}

build/shared/manpage.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ SYNOPSIS
3333

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

36+
*arduino* [*--version*]
37+
3638
DESCRIPTION
3739
-----------
3840
The 'arduino' integrated development environment allows editing,
@@ -83,6 +85,9 @@ ACTIONS
8385
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.
8486
Multiple libraries can be specified, separated by a comma.
8587

88+
*--version*::
89+
Print the version information and exit.
90+
8691
OPTIONS
8792
-------
8893
*--board* __package__:__arch__:__board__[:__parameters__]::

0 commit comments

Comments
 (0)