How do you get spaces in flag values when using directives?
Context
The flag
package receives and/or handles flags with spaces differently depending on how Go is called. Quoting the flag value works from the command-line but not with a directive, such as go generate
, for example.
In other words, called from the command line, Flag1
will receive the correct value (i.e., 4 words, 3 spaces).
Works
% go run -tags generate main.go -Flag1="flag value with spaces"
Doesn't Work
However, calling the exact same command in a directive file, e.g., with go generate ./...
, Flag1
will not receive the correct value. Take a directive file (e.g., generate.go
) with this line in it:
//go:generate go run -tags generate main.go -Flag1="flag value with spaces" -Flag2=next
Flag1
is not set correctly and Flag2
is not set at all.