Skip to content

Commit

Permalink
Command line --get-pref may be used without name of the target pref.
Browse files Browse the repository at this point in the history
If pref name is missing, all prefs are printed on stdout.
Should fix/mitigate #2982
  • Loading branch information
Federico Fissore committed May 29, 2015
1 parent a48906e commit 935bece
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/src/cc/arduino/view/SplashScreenHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void close() {
}

private void printText(String str) {
System.out.println(str);
System.err.println(str);
}

}
8 changes: 1 addition & 7 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,7 @@ protected void onProgress(Progress progress) {
// Do nothing (intended for only changing preferences)
System.exit(0);
} else if (parser.isGetPrefMode()) {
String value = PreferencesData.get(parser.getGetPref(), null);
if (value != null) {
System.out.println(value);
System.exit(0);
} else {
System.exit(4);
}
BaseNoGui.dumpPrefs(parser);
}
}

Expand Down
13 changes: 13 additions & 0 deletions arduino-core/src/processing/app/BaseNoGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,26 @@ static public void init(String[] args) throws Exception {
System.exit(0);
}
else if (parser.isGetPrefMode()) {
dumpPrefs(parser);
}
}

protected static void dumpPrefs(CommandlineParser parser) {
if (parser.getGetPref() != null) {
String value = PreferencesData.get(parser.getGetPref(), null);
if (value != null) {
System.out.println(value);
System.exit(0);
} else {
System.exit(4);
}
} else {
System.out.println("#PREFDUMP#");
PreferencesMap prefs = PreferencesData.getMap();
for (Map.Entry<String, String> entry : prefs.entrySet()) {
System.out.println(entry.getKey() + "=" + entry.getValue());
}
System.exit(0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public LegacyTargetBoard(String _id, PreferencesMap _prefs,
String board = containerPlatform.getId() + "_" + id;
board = board.toUpperCase();
prefs.put("build.board", board);
System.out
System.err
.println(format(_("Board {0}:{1}:{2} doesn''t define a ''build.board'' preference. Auto-set to: {3}"),
containerPlatform.getContainerPackage().getId(),
containerPlatform.getId(), id, board));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public LegacyTargetPackage(String _id, File _folder) throws TargetPlatformExcept
TargetPlatform platform = new LegacyTargetPlatform(arch, subFolder, this);
platforms.put(arch, platform);
} catch (TargetPlatformException e) {
System.out.println(e.getMessage());
System.err.println(e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ private void parseArguments(String[] args) {
}
if (a == ACTION.GET_PREF) {
i++;
if (i >= args.length) {
BaseNoGui.showError(null, I18n.format(_("Argument required for {0}"), a.value), 3);
if (i < args.length) {
getPref = args[i];
}
getPref = args[i];
}
if (a == ACTION.INSTALL_BOARD) {
i++;
Expand Down
5 changes: 3 additions & 2 deletions build/shared/manpage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SYNOPSIS

*arduino* [*--verify*|*--upload*] [*--board* __package__:__arch__:__board__[:__parameters__]] [*--port* __portname__] [*--pref* __name__=__value__] [*-v*|*--verbose*] [--preserve-temp-files] [__FILE.ino__]

*arduino* [*--get-pref* __preference__]
*arduino* [*--get-pref* [__preference__]]

*arduino* [*--install-boards* __package name__:__platform architecture__[:__version__]]

Expand Down Expand Up @@ -63,10 +63,11 @@ ACTIONS
*--upload*::
Build and upload the sketch.

*--get-pref* __preference__::
*--get-pref* [__preference__]::
Prints the value of the given preference to the standard output
stream. When the value does not exist, nothing is printed and
the exit status is set (see EXIT STATUS below).
If no preference is given as parameter, it prints all preferences.

*--install-boards* __package name__:__platform architecture__[:__version__]::
Fetches available board support (platform) list and install the specified one, along with its related tools. If __version__ is omitted, the latest is installed. If a platform with the same version is already installed, nothing is installed and program exits with exit code 1. If a platform with a different version is already installed, it's replaced.
Expand Down

0 comments on commit 935bece

Please sign in to comment.