1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-20 14:54:31 +01:00

CLI: Add --version to CLI option (#7549)

* 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.

* Split "parse" and "action".
Move print action to probably suitable place.

This commit will fix the behavior of multiple actions about --version.

* add testcase
This commit is contained in:
Yohsuke FURUTA 2018-05-23 00:46:11 +09:00 committed by Cristian Maglie
parent 60021c1e63
commit 24029c5ace
4 changed files with 47 additions and 2 deletions

View File

@ -487,6 +487,9 @@ public class Base {
System.exit(0);
} else if (parser.isGetPrefMode()) {
BaseNoGui.dumpPrefs(parser);
} else if (parser.isVersionMode()) {
System.out.print("Arduino: " + BaseNoGui.VERSION_NAME_LONG);
System.exit(0);
}
}

View File

@ -34,6 +34,7 @@ import static org.junit.Assert.*;
import java.io.File;
import org.apache.commons.compress.utils.IOUtils;
import org.fest.assertions.Assertions;
import org.junit.Before;
import org.junit.Test;
@ -126,5 +127,36 @@ public class CommandLineTest {
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+.*");
}
@Test
public void testCommandLineMultipleAction() throws Exception {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(new String[]{
arduinoPath.getAbsolutePath(),
"--version",
"--verify",
});
pr.waitFor();
Assertions.assertThat(pr.exitValue())
.as("Multiple Action will be rejected")
.isEqualTo(3);
}
}

View File

@ -16,7 +16,7 @@ import static processing.app.I18n.tr;
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;
@ -52,6 +52,7 @@ public class CommandlineParser {
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() {
@ -340,6 +341,10 @@ public class CommandlineParser {
return action == ACTION.INSTALL_LIBRARY;
}
public boolean isVersionMode() {
return action == ACTION.VERSION;
}
public String getBoardToInstall() {
return this.boardToInstall;
}

View File

@ -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,
@ -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__]::