Coffeescript Cakefile - cmdline options array

Is it possible to pass multiple cmdline arguments to Cakefile and capture these values ​​in an array? For example, something like this:

option '', '--compilation-level [LEVEL]', 'Description...' task "build", "compile js", (options)-> compilationLevels = options['compilation-level'] || ['DEFAULT'] if compilationLevels.length >= 2 console.log 'multiple compiles' else console.log 'just one compile' 

Then run w / cake --compilation-level ADVANCED_OPTIMIZATIONS --compilation-level SIMPLE_OPTIMIZATIONS build

If this is not possible, suggestions on the most optimal way to achieve this goal will be very useful :)

+4
source share
1 answer

Yep: Cake is powered by CoffeeScript OptionParser , which is ported from the Ruby utility of the same name. If you are looking for a source for isList , you will see that the parameter can be used several times to create an array if (and only if) a regular expression

 OPTIONAL = /\[(\w+(\*?))\]/ 

matches the name of the long flag. In short: you just need to add one character to your code.

 option '', '--compilation-level [LEVEL*]', 'Description...' 

What * matters! :)

+2
source

Source: https://habr.com/ru/post/1384737/


All Articles