Documentation
¶
Overview ¶
Package flags holds the command line options every phpscript subcommand accepts, and the work they imply.
The set exists because the same idea used to be spelled once per command: --include in test and in lint with two help texts and two implementations and not in server at all, --cpuprofile only in test, -v defined twice, -f hand-parsed out of argv and printed by no help output. One Options is bound onto every command, and a command reads what it uses.
-f and -w are read before the command is constructed, because the configuration file and the working directory decide what the command is handed. Pre takes them off the argument list; Bind declares them anyway, so they appear in help beside the rest.
Index ¶
- Constants
- func Hoist(args []string, isCommand func(string) bool) []string
- type Options
- func (o *Options) Bind(fs *cli.FlagSet)
- func (o *Options) BindWith(bind func(*cli.FlagSet)) func(*cli.FlagSet)
- func (o *Options) Chdir() error
- func (o *Options) Covering() bool
- func (o *Options) FromConfig(appConfig config.Config)
- func (o *Options) Report() bool
- func (o *Options) ResolveCoverFile(now time.Time) (string, error)
- func (o *Options) RunWith(run func(context.Context, []string) error) func(context.Context, []string) error
- func (o *Options) Validate() error
- func (o *Options) WriteCoverProfile(blocks []coverage.ProfileBlock) (string, error)
Constants ¶
const TimeLayout = "20060102-150405"
TimeLayout is what TimePlaceholder expands to: UTC, sortable, and free of the characters a shell or a path would have an opinion about.
const TimePlaceholder = "{time}"
TimePlaceholder is the token --coverfile expands to a timestamp. A server writing one profile per run names them apart without the operator having to compose a filename per start.
Variables ¶
This section is empty.
Functions ¶
func Hoist ¶
Hoist moves the command name to the front of the argument list, so a global flag may precede it.
Only the flags this package declares are walked over: a command's own flags belong after its name. A bare --cover does not consume the word after it, which is what its NoOptDefVal makes legal.
Types ¶
type Options ¶
type Options struct {
// ConfigFile is -f: the configuration read over the embedded defaults.
ConfigFile string
// WorkDir is -w: the directory the process changes to before it does
// anything else, so every relative path in the configuration, the
// arguments and the scripts means the same thing.
WorkDir string
// Include is --include: a file included ahead of every entrypoint, carried
// to the runtime as runner.Options.Include and to the linter as its name
// registry seed.
Include string
// Verbose is -v.
Verbose bool
// CPUProfile and MemProfile name pprof files written around the command.
CPUProfile string
MemProfile string
// Cover is --cover: "", or one of the coverage modes. CoverFile is where
// the profile is written, TimePlaceholder expanded.
Cover string
CoverFile string
}
Options are the flags every subcommand accepts.
func Pre ¶
Pre reads -f and -w off the argument list and returns what is left.
Both are read before the command is constructed: -f decides the configuration a command is handed, and -w decides what every relative path after it means, the configuration file included. pflag runs later and never sees them, which is why Bind's defaults are the values found here.
func (*Options) BindWith ¶
BindWith returns a Bind that declares the shared flags before the command's own, so every command carries the set whether or not it defines flags.
func (*Options) Chdir ¶
Chdir applies -w. It runs before the configuration is read, so a tree is served by naming it once rather than by repeating it in every path the configuration holds.
func (*Options) FromConfig ¶
FromConfig fills the options a configuration file may also carry, where the command line did not name one. The flag wins: a configuration describes a tree, and a flag is what an operator typed about this run of it.
func (*Options) Report ¶
Report reports whether the coverage mode prints a per-symbol report on top of writing the profile.
func (*Options) ResolveCoverFile ¶
ResolveCoverFile expands TimePlaceholder and creates the directory the profile is written into, so --coverfile=cover/phpscript.{time}.cov works against a tree that has no cover directory yet.
func (*Options) RunWith ¶
func (o *Options) RunWith(run func(context.Context, []string) error) func(context.Context, []string) error
RunWith wraps a command's Run with the shared work: the flags are validated, the CPU profile runs for the length of the command, and the heap profile is written after it. A failure to start profiling is the command's failure; the operator asked for a measurement and did not get one.
func (*Options) Validate ¶
Validate normalizes the coverage flags and rejects a mode that is not one.
func (*Options) WriteCoverProfile ¶
func (o *Options) WriteCoverProfile(blocks []coverage.ProfileBlock) (string, error)
WriteCoverProfile writes blocks to the resolved --coverfile.