I'm trying to extend the Shake command line argument, with two goals in mind:
--foo
.go
does one thing in the root, and another in the foobar
directory.How can I do that?
There are four relevant functions to extend the Shake command line:
shake
is the main entry point to Shake, which takes a ShakeOptions
structure describing all the options. If you want an entirely custom command line interface, use any command-line parser to populate these fields.shakeArgs
runs Shake filling in the ShakeOptions
using the command line arguments, so is useful to get a standard command line with Shake.shakeArgsWith
takes a list of extra options as its second argument, and logic for how to deal with any non-flag arguments as its third. You can inject new flags, and modify how a non-flag like go
gets resolved based on any other information you have to hand, including current directory.shakeOptDescrs
gives data types describing flags corresponding to fields in ShakeOptions
.As to their relationship, shake
is the actual build system. shakeArgsWith
uses the information from shakeOptDescrs
and any custom flags to build and run a command line parser. shakeArgs
calls shakeArgsWith
using no additional flags.
In the specific case of adding a flag or customising the behaviour of a non-flag, shakeArgsWith
is sufficient. If you need more control, you can build your own parser, perhaps incorporating the existing flags found in shakeOptDescrs
or not.