Skip to content

Commit e494f39

Browse files
matthijskooijmancmaglie
authored andcommitted
Add --get-pref option
This allows reading specific preferences from the commandline.
1 parent f745fff commit e494f39

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

app/src/processing/app/Base.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ static protected void initRequirements() {
268268
}
269269

270270

271-
protected static enum ACTION { GUI, VERIFY, UPLOAD, NOOP };
271+
protected static enum ACTION { GUI, VERIFY, UPLOAD, NOOP, GET_PREF };
272272
public Base(String[] args) throws Exception {
273273
platform.init(this);
274274

@@ -322,6 +322,7 @@ public Base(String[] args) throws Exception {
322322
ACTION action = ACTION.GUI;
323323
boolean doVerboseBuild = false;
324324
boolean doVerboseUpload = false;;
325+
String getPref = null;
325326
String selectBoard = null;
326327
String selectPort = null;
327328
String currentDirectory = System.getProperty("user.dir");
@@ -332,6 +333,7 @@ public Base(String[] args) throws Exception {
332333
actions.put("--verify", ACTION.VERIFY);
333334
actions.put("--upload", ACTION.UPLOAD);
334335
actions.put("--noop", ACTION.NOOP);
336+
actions.put("--get-pref", ACTION.GET_PREF);
335337

336338
// Check if any files were passed in on the command line
337339
for (int i = 0; i < args.length; i++) {
@@ -342,6 +344,12 @@ public Base(String[] args) throws Exception {
342344
String mess = I18n.format(_("Can only pass one of: {0}"), PApplet.join(valid, ", "));
343345
showError(null, mess, 3);
344346
}
347+
if (a == ACTION.GET_PREF) {
348+
i++;
349+
if (i >= args.length)
350+
showError(null, _("Argument required for --get-pref"), 3);
351+
getPref = args[i];
352+
}
345353
action = a;
346354
continue;
347355
}
@@ -406,7 +414,7 @@ public Base(String[] args) throws Exception {
406414
if ((action == ACTION.UPLOAD || action == ACTION.VERIFY) && filenames.size() != 1)
407415
showError(null, _("Must specify exactly one sketch file"), 3);
408416

409-
if (action == ACTION.NOOP && filenames.size() != 0)
417+
if ((action == ACTION.NOOP || action == ACTION.GET_PREF) && filenames.size() != 0)
410418
showError(null, _("Cannot specify any sketch files"), 3);
411419

412420
if ((action != ACTION.UPLOAD && action != ACTION.VERIFY) && (doVerboseBuild || doVerboseUpload))
@@ -493,6 +501,15 @@ public Base(String[] args) throws Exception {
493501
// Do nothing (intended for only changing preferences)
494502
System.exit(0);
495503
break;
504+
case GET_PREF:
505+
String value = Preferences.get(getPref, null);
506+
if (value != null) {
507+
System.out.println(value);
508+
System.exit(0);
509+
} else {
510+
System.exit(4);
511+
}
512+
break;
496513
}
497514
}
498515

build/shared/manpage.adoc

+6
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ OPTIONS
149149
Immediately quit after processing the commandline. This can be
150150
used to just set preferences with *--pref*.
151151

152+
*--get-pref __preference__*::
153+
Prints the value of the given preference to the standard output
154+
stream. When the value does not exist, nothing is printed and
155+
the exit status is set (see EXIT STATUS below).
156+
152157
PREFERENCES
153158
-----------
154159
Arduino keeps a list of preferences, as simple name and value pairs.
@@ -185,6 +190,7 @@ EXIT STATUS
185190
*1*:: Build failed or upload failed
186191
*2*:: Sketch not found
187192
*3*:: Invalid (argument for) commandline option
193+
*4*:: Preference passed to *--get-pref* does not exist
188194

189195
FILES
190196
-----

0 commit comments

Comments
 (0)