diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index b692b11b8..d33490323 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -268,7 +268,7 @@ public class Base { } - protected static enum ACTION { GUI, VERIFY, UPLOAD, NOOP }; + protected static enum ACTION { GUI, VERIFY, UPLOAD, NOOP, GET_PREF }; public Base(String[] args) throws Exception { platform.init(this); @@ -322,6 +322,7 @@ public class Base { ACTION action = ACTION.GUI; boolean doVerboseBuild = false; boolean doVerboseUpload = false;; + String getPref = null; String selectBoard = null; String selectPort = null; String currentDirectory = System.getProperty("user.dir"); @@ -332,6 +333,7 @@ public class Base { actions.put("--verify", ACTION.VERIFY); actions.put("--upload", ACTION.UPLOAD); actions.put("--noop", ACTION.NOOP); + actions.put("--get-pref", ACTION.GET_PREF); // Check if any files were passed in on the command line for (int i = 0; i < args.length; i++) { @@ -342,6 +344,12 @@ public class Base { String mess = I18n.format(_("Can only pass one of: {0}"), PApplet.join(valid, ", ")); showError(null, mess, 3); } + if (a == ACTION.GET_PREF) { + i++; + if (i >= args.length) + showError(null, _("Argument required for --get-pref"), 3); + getPref = args[i]; + } action = a; continue; } @@ -406,7 +414,7 @@ public class Base { if ((action == ACTION.UPLOAD || action == ACTION.VERIFY) && filenames.size() != 1) showError(null, _("Must specify exactly one sketch file"), 3); - if (action == ACTION.NOOP && filenames.size() != 0) + if ((action == ACTION.NOOP || action == ACTION.GET_PREF) && filenames.size() != 0) showError(null, _("Cannot specify any sketch files"), 3); if ((action != ACTION.UPLOAD && action != ACTION.VERIFY) && (doVerboseBuild || doVerboseUpload)) @@ -493,6 +501,15 @@ public class Base { // Do nothing (intended for only changing preferences) System.exit(0); break; + case GET_PREF: + String value = Preferences.get(getPref, null); + if (value != null) { + System.out.println(value); + System.exit(0); + } else { + System.exit(4); + } + break; } } diff --git a/build/shared/manpage.adoc b/build/shared/manpage.adoc index db52b2f50..46a0b4946 100644 --- a/build/shared/manpage.adoc +++ b/build/shared/manpage.adoc @@ -149,6 +149,11 @@ OPTIONS Immediately quit after processing the commandline. This can be used to just set preferences with *--pref*. +*--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). + PREFERENCES ----------- Arduino keeps a list of preferences, as simple name and value pairs. @@ -185,6 +190,7 @@ EXIT STATUS *1*:: Build failed or upload failed *2*:: Sketch not found *3*:: Invalid (argument for) commandline option +*4*:: Preference passed to *--get-pref* does not exist FILES -----