Add --get-pref option

This allows reading specific preferences from the commandline.
This commit is contained in:
Matthijs Kooijman 2014-04-07 12:19:22 +02:00 committed by Cristian Maglie
parent f745fff50b
commit e494f39255
2 changed files with 25 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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
-----