Skip to content

Commit 935bece

Browse files
author
Federico Fissore
committed
Command line --get-pref may be used without name of the target pref.
If pref name is missing, all prefs are printed on stdout. Should fix/mitigate #2982
1 parent a48906e commit 935bece

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

Diff for: app/src/cc/arduino/view/SplashScreenHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void close() {
9090
}
9191

9292
private void printText(String str) {
93-
System.out.println(str);
93+
System.err.println(str);
9494
}
9595

9696
}

Diff for: app/src/processing/app/Base.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,7 @@ protected void onProgress(Progress progress) {
477477
// Do nothing (intended for only changing preferences)
478478
System.exit(0);
479479
} else if (parser.isGetPrefMode()) {
480-
String value = PreferencesData.get(parser.getGetPref(), null);
481-
if (value != null) {
482-
System.out.println(value);
483-
System.exit(0);
484-
} else {
485-
System.exit(4);
486-
}
480+
BaseNoGui.dumpPrefs(parser);
487481
}
488482
}
489483

Diff for: arduino-core/src/processing/app/BaseNoGui.java

+13
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,26 @@ static public void init(String[] args) throws Exception {
570570
System.exit(0);
571571
}
572572
else if (parser.isGetPrefMode()) {
573+
dumpPrefs(parser);
574+
}
575+
}
576+
577+
protected static void dumpPrefs(CommandlineParser parser) {
578+
if (parser.getGetPref() != null) {
573579
String value = PreferencesData.get(parser.getGetPref(), null);
574580
if (value != null) {
575581
System.out.println(value);
576582
System.exit(0);
577583
} else {
578584
System.exit(4);
579585
}
586+
} else {
587+
System.out.println("#PREFDUMP#");
588+
PreferencesMap prefs = PreferencesData.getMap();
589+
for (Map.Entry<String, String> entry : prefs.entrySet()) {
590+
System.out.println(entry.getKey() + "=" + entry.getValue());
591+
}
592+
System.exit(0);
580593
}
581594
}
582595

Diff for: arduino-core/src/processing/app/debug/LegacyTargetBoard.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public LegacyTargetBoard(String _id, PreferencesMap _prefs,
5858
String board = containerPlatform.getId() + "_" + id;
5959
board = board.toUpperCase();
6060
prefs.put("build.board", board);
61-
System.out
61+
System.err
6262
.println(format(_("Board {0}:{1}:{2} doesn''t define a ''build.board'' preference. Auto-set to: {3}"),
6363
containerPlatform.getContainerPackage().getId(),
6464
containerPlatform.getId(), id, board));

Diff for: arduino-core/src/processing/app/debug/LegacyTargetPackage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public LegacyTargetPackage(String _id, File _folder) throws TargetPlatformExcept
5151
TargetPlatform platform = new LegacyTargetPlatform(arch, subFolder, this);
5252
platforms.put(arch, platform);
5353
} catch (TargetPlatformException e) {
54-
System.out.println(e.getMessage());
54+
System.err.println(e.getMessage());
5555
}
5656
}
5757

Diff for: arduino-core/src/processing/app/helpers/CommandlineParser.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ private void parseArguments(String[] args) {
7373
}
7474
if (a == ACTION.GET_PREF) {
7575
i++;
76-
if (i >= args.length) {
77-
BaseNoGui.showError(null, I18n.format(_("Argument required for {0}"), a.value), 3);
76+
if (i < args.length) {
77+
getPref = args[i];
7878
}
79-
getPref = args[i];
8079
}
8180
if (a == ACTION.INSTALL_BOARD) {
8281
i++;

Diff for: build/shared/manpage.adoc

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ SYNOPSIS
2727

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

30-
*arduino* [*--get-pref* __preference__]
30+
*arduino* [*--get-pref* [__preference__]]
3131

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

@@ -63,10 +63,11 @@ ACTIONS
6363
*--upload*::
6464
Build and upload the sketch.
6565

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

7172
*--install-boards* __package name__:__platform architecture__[:__version__]::
7273
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.

0 commit comments

Comments
 (0)