stdflag

package
v0.0.0-...-1dd1f65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package stdflag contains standard command-line flag code for c4t binaries.

Index

Examples

Constants

View Source
const (

	// FlagCompiler is a standard flag for compiler selection arguments.
	FlagCompiler = "c"
	// FlagOutDir is a short flag for specifying an output directory.
	FlagOutDir = "d"
	// FlagWorkerCount is a standard flag for arguments that set a worker count.
	FlagWorkerCount = "j"

	// FlagMachine is a standard flag for machine selection arguments.
	FlagMachine = "m"
	// FlagNum is a standard flag for 'number of' arguments.
	FlagNum = "n"
	// FlagCompilerTimeout is a short flag for compiler timeout.
	FlagCompilerTimeout = "t"

	// FlagConfigFile is a standard flag for overriding the config file.
	FlagConfigFile = "C"
	// FlagAltWorkerCount is a flag for arguments that set a secondary worker count.
	FlagAltWorkerCount = "J"
	// FlagRunTimeout is a short flag for run timeout.
	FlagRunTimeout = "T"

	// FlagCPUProfile is a standard flag for specifying a CPU profile output.
	FlagCPUProfile = "cpuprofile"
)
View Source
const (
	// FlagCompilerTimeoutLong is a long flag for compiler timeout.
	FlagCompilerTimeoutLong = "compiler-timeout"
	// FlagRunTimeoutLong is a long flag for run timeout.
	FlagRunTimeoutLong = "run-timeout"
	// FlagWorkerCountLong is a long flag for arguments that set a worker count.
	FlagWorkerCountLong = "num-workers"
	// FlagCompilerWorkerCountLong is a long flag for arguments that set a compiler worker count.
	FlagCompilerWorkerCountLong = "num-compiler-workers"
	// FlagRunWorkerCountLong is a long flag for arguments that set a runner worker count.
	FlagRunWorkerCountLong = "num-run-workers"
)
View Source
const (
	// FlagOutputCsv is a flag for selecting the CSV tabulator.
	FlagOutputCsv = "output-csv"
	// UsageOutputCsv is the usage for the output-CSV flag.
	UsageOutputCsv = "output tables as CSV"
)
View Source
const MachBinName = "c4t-mach"

MachBinName is the name of the machine node binary.

Variables

View Source
var ErrBadPlanArguments = errors.New("expected plan file argument")

ErrBadPlanArguments occurs when we expect a plan file argument, but get something else.

Functions

func C4fRunnerCliFlags

func C4fRunnerCliFlags() []c.Flag

C4fRunnerCliFlags gets the 'cli' flags needed to set up a c4f runner.

func C4fRunnerFromCli

func C4fRunnerFromCli(ctx *c.Context, errw io.Writer) *c4f.Runner

C4fRunnerFromCli makes a c4f runner using the flags previously set up by C4fRunnerCliFlags.

func CPUProfileCliFlag

func CPUProfileCliFlag() c.Flag

CPUProfileCliFlag sets up a 'cpu profile dumper' flag.

func CPUProfileFromCli

func CPUProfileFromCli(ctx *c.Context) string

CPUProfileFromCli retrieves the 'cpu profile dumper' set up by CPUProfileCliFlag.

func ConfFileCliFlag

func ConfFileCliFlag() c.Flag

ConfFileCliFlag creates a cli flag for the config file.

func ConfigFromCli

func ConfigFromCli(ctx *c.Context) (*config.Config, error)

ConfigFromCli sets up a Config using the file flag set up by ConfFileCliFlag.

func CorpusSizeCliFlag

func CorpusSizeCliFlag() c.Flag

CorpusSizeCliFlag sets up a 'target corpus size' flag.

func CorpusSizeFromCli

func CorpusSizeFromCli(ctx *c.Context) int

CorpusSizeFromCli retrieves a plan file using the file flag set up by CorpusSizeCliFlag.

func GlobalTimeoutCliFlag

func GlobalTimeoutCliFlag() c.Flag

GlobalTimeoutCliFlag sets up a CLI flag for global timeouts.

func GlobalTimeoutFromCli

func GlobalTimeoutFromCli(ctx *c.Context) quantity.Timeout

GlobalTimeoutFromCli retrieves any global timeout specified on the command line in ctx.

func MachArgs

func MachArgs(dir string, qs quantity.MachNodeSet) []string

MachArgs is the arguments for an invocation of c4t-mach, given directory dir and the config uc.

Example

ExampleMachArgs is a testable example for MachArgs.

package main

import (
	"fmt"
	"strings"
	"time"

	"github.com/c4-project/c4t/internal/quantity"

	"github.com/c4-project/c4t/internal/ux/stdflag"
)

func main() {
	qempty := quantity.MachNodeSet{}
	fmt.Println(strings.Join(stdflag.MachArgs("", qempty), ", "))

	qi := quantity.MachNodeSet{
		Compiler: quantity.BatchSet{
			Timeout:  quantity.Timeout(10 * time.Second),
			NWorkers: 10,
		},
		Runner: quantity.BatchSet{
			Timeout:  quantity.Timeout(5 * time.Minute),
			NWorkers: 20,
		},
	}

	fmt.Println(strings.Join(stdflag.MachArgs("foo", qi), ", "))

}
Output:

-d, , -compiler-timeout, 0s, -run-timeout, 0s, -num-compiler-workers, 0, -num-run-workers, 0
-d, foo, -compiler-timeout, 10s, -run-timeout, 5m0s, -num-compiler-workers, 10, -num-run-workers, 20

func MachCliFlags

func MachCliFlags() []c.Flag

MachCliFlags gets the cli flags for setting up the 'user config' part of a mach or invoker invocation.

func MachInvocation

func MachInvocation(dir string, qs quantity.MachNodeSet) []string

MachInvocation gets the invocation for the local-machine binary as a string list.

func MachNodeQuantitySetFromCli

func MachNodeQuantitySetFromCli(ctx *c.Context) quantity.MachNodeSet

MachNodeQuantitySetFromCli gets the machine node quantity set from the flags in ctx.

func OutDirCliFlag

func OutDirCliFlag(defaultdir string) c.Flag

OutDirCliFlag sets up an 'output directory' cli flag.

func OutDirFromCli

func OutDirFromCli(ctx *c.Context) string

OutDirFromCli gets the output directory set up by OutDirCliFlag.

func PlanFileFromCli

func PlanFileFromCli(ctx *c.Context) (string, error)

PlanFileFromCli retrieves a plan file (which may be empty) from the arguments of ctx. Its corresponding setup function is SetupPlanAppSettings; there is no 'plan file' flag.

func RootQuantitiesFromCli

func RootQuantitiesFromCli(ctx *c.Context) quantity.RootSet

RootQuantitiesFromCli gets from ctx the root-level quantity overrides specified by the user.

func RootQuantityCliFlags

func RootQuantityCliFlags() []c.Flag

RootQuantityCliFlags sets up the root quantity override flags read by RootQuantitiesFromCli.

func SetCommonAppSettings

func SetCommonAppSettings(a *c.App, outw, errw io.Writer) *c.App

SetCommonAppSettings sets app settings on a that are common to all c4t endpoints. It passes through the pointer a.

func SetPlanAppSettings

func SetPlanAppSettings(a *c.App, outw, errw io.Writer) *c.App

SetPlanAppSettings sets app settings on a that are common to c4t endpoints handling a plan. It passes through the pointer a.

func SubjectFuzzesCliFlag

func SubjectFuzzesCliFlag() c.Flag

SubjectFuzzesCliFlag sets up a 'number of cycles' flag.

func SubjectFuzzesFromCli

func SubjectFuzzesFromCli(ctx *c.Context) int

SubjectFuzzesFromCli retrieves a plan file using the file flag set up by SubjectFuzzesCliFlag.

func TabulatorCliFlags

func TabulatorCliFlags() []c.Flag

TabulatorCliFlags expands into the flag set for configuring TabulatorFromCli.

func TabulatorFromCli

func TabulatorFromCli(ctx *c.Context, w io.Writer) tabulator.Tabulator

TabulatorFromCli constructs a Tabulator that corresponds to the flags set in ctx.

There is only one format choice at the moment (CSV vs tab), but this may change in future.

func Verbose

func Verbose(ctx *c.Context) bool

Verbose gets the value of the verbosity flag from ctx.

func VerboseFlag

func VerboseFlag() c.Flag

VerboseFlag sets up a verbosity flag.

func WorkerCountCliFlag

func WorkerCountCliFlag() c.Flag

WorkerCountCliFlag sets up a worker count flag.

func WorkerCountFromCli

func WorkerCountFromCli(ctx *c.Context) int

WorkerCountFromCli retrieves a 'worker count' flag set up by WorkerCountCliFlag.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL