Easier way to map boolean settings to strings

I just released my first Nova extension. It is a task extension that runs a command line tool in a script.

The extension has a number of configuration checkboxes that toggle various options on and off in the command line tool.

In order to transform the various checkboxes into the presence or absence of flags used in the shell script, I needed to:

  • Pass each boolean value as an environment value
  • Use shell script conditionals for each boolean to populate a shell variable if true

This works but makes for a very verbose and error-prone script.

It would be very useful if there was an easier way for a checkbox boolean to be transformed into a string to be used as a flag / argument.

One possibility might be to allow a checkbox to specify a two-member enum instead of a boolean as its value. In this case, this would allow a checkbox to control a choice between the strings “-verbose” and “”.

Another more flexible possibility might to add a way to specify conditional logic as part of the specification. Possibly an extension to the JSON syntax similar to:

{ 
  if: $(Config.php.verbose),
  then: "--verbose",
  else: ""
}

Each value could be interpolated. It could also be that if the else entry is omitted, the default would be the empty string.

It’s also quite possible there is already a way to do something like this which I did not discover. Thanks.

This is an excellent idea. I’ll file this as a feature request.

1 Like