From 935becec6446eabc3cde0ef1aeb6481567dc982e Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Fri, 29 May 2015 15:15:08 +0200 Subject: [PATCH] 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 --- app/src/cc/arduino/view/SplashScreenHelper.java | 2 +- app/src/processing/app/Base.java | 8 +------- arduino-core/src/processing/app/BaseNoGui.java | 13 +++++++++++++ .../src/processing/app/debug/LegacyTargetBoard.java | 2 +- .../processing/app/debug/LegacyTargetPackage.java | 2 +- .../processing/app/helpers/CommandlineParser.java | 5 ++--- build/shared/manpage.adoc | 5 +++-- 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/src/cc/arduino/view/SplashScreenHelper.java b/app/src/cc/arduino/view/SplashScreenHelper.java index 7d5948fec..a9b9b9665 100644 --- a/app/src/cc/arduino/view/SplashScreenHelper.java +++ b/app/src/cc/arduino/view/SplashScreenHelper.java @@ -90,7 +90,7 @@ public class SplashScreenHelper { } private void printText(String str) { - System.out.println(str); + System.err.println(str); } } diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index c20f70301..f3011f23b 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -477,13 +477,7 @@ public class Base { // 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); } } diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index 4035fbbc9..c939a0ffc 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -570,6 +570,12 @@ public class BaseNoGui { 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); @@ -577,6 +583,13 @@ public class BaseNoGui { } else { System.exit(4); } + } else { + System.out.println("#PREFDUMP#"); + PreferencesMap prefs = PreferencesData.getMap(); + for (Map.Entry entry : prefs.entrySet()) { + System.out.println(entry.getKey() + "=" + entry.getValue()); + } + System.exit(0); } } diff --git a/arduino-core/src/processing/app/debug/LegacyTargetBoard.java b/arduino-core/src/processing/app/debug/LegacyTargetBoard.java index ff06ab29d..5684d8640 100644 --- a/arduino-core/src/processing/app/debug/LegacyTargetBoard.java +++ b/arduino-core/src/processing/app/debug/LegacyTargetBoard.java @@ -58,7 +58,7 @@ public class LegacyTargetBoard implements TargetBoard { 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)); diff --git a/arduino-core/src/processing/app/debug/LegacyTargetPackage.java b/arduino-core/src/processing/app/debug/LegacyTargetPackage.java index 42d6b0730..c7b315a34 100644 --- a/arduino-core/src/processing/app/debug/LegacyTargetPackage.java +++ b/arduino-core/src/processing/app/debug/LegacyTargetPackage.java @@ -51,7 +51,7 @@ public class LegacyTargetPackage implements TargetPackage { TargetPlatform platform = new LegacyTargetPlatform(arch, subFolder, this); platforms.put(arch, platform); } catch (TargetPlatformException e) { - System.out.println(e.getMessage()); + System.err.println(e.getMessage()); } } diff --git a/arduino-core/src/processing/app/helpers/CommandlineParser.java b/arduino-core/src/processing/app/helpers/CommandlineParser.java index 2e66e6361..01d0d93b5 100644 --- a/arduino-core/src/processing/app/helpers/CommandlineParser.java +++ b/arduino-core/src/processing/app/helpers/CommandlineParser.java @@ -73,10 +73,9 @@ public class CommandlineParser { } 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++; diff --git a/build/shared/manpage.adoc b/build/shared/manpage.adoc index fbd629a76..541a431b6 100644 --- a/build/shared/manpage.adoc +++ b/build/shared/manpage.adoc @@ -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__]] @@ -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.