cliopts

package
v0.36.4 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cliopts declares codescan's option surface once, as flags.

Every command that scans - genspec, genspec-wasi - needs the same thing: a flag.FlagSet carrying one flag per knob on codescan.Options, and a way to copy what was parsed onto the options a scan runs with. Written per command, that mapping is partial in a different way each time, and a knob added to the library reaches whichever command somebody remembered.

So it is written here instead, as tables keyed by the field each entry writes to, with one guard (see the package tests) asserting that no value-typed field of the options is left unreachable. A command registers the whole surface and adds only what is its own - where to write, what format, how loud.

Naming

A flag is the kebab-case of the field it writes, without exception: SkipJSONifyInterfaceMethods is -skip-jsonify-interface-methods. Guessing a shorter spelling is how a caller ends up guessing wrong, and no rule can derive that JSONify is one word where HTTPServer is two - which is also why coverage is decided by writing through a setter and seeing what moved, never by mangling a name.

What is not here

Options that are not values: the packages to scan (positional arguments), a filesystem or export data to read (the command opens a path), a specification to merge into (the command loads it), and the diagnostic and provenance callbacks. Those are the command's business; the tests carry the list, with a reason each.

Index

Constants

View Source
const DefaultPatterns = "./..."

DefaultPatterns is the pattern a command scans when the caller names nothing.

Variables

View Source
var ErrBadFlag = errors.New("bad flag")

ErrBadFlag is a flag whose value is not one of the ones it accepts.

A sentinel rather than a formatted string at each site: a caller - a test, or a command deciding an exit code - can then ask which kind of refusal it met without matching on prose that is free to change.

Functions

func ConfigSchema

func ConfigSchema() cliconf.Schema

ConfigSchema maps each shared option to its address in a configuration file.

func NotConfigurable

func NotConfigurable() map[string]string

NotConfigurable reports the shared options a file may not address, so a command can excuse them in the guard that checks every flag is either addressable or deliberately not.

func Patterns

func Patterns(args []string) []string

Patterns is the packages to scan: what the caller named, or everything under the working directory.

Positional rather than a flag, so that `genspec ./api/...` reads the way every other Go command does - which is also why it cannot be a table entry.

func SplitList

func SplitList(s string) []string

SplitList parses a comma-separated flag into trimmed, non-empty entries.

It returns nil when there is nothing usable - nil being what the scanner reads as "no filter".

func Version

func Version(cmd string) string

Version reports what this build is, as the module system recorded it.

A binary installed with `go install ...@latest` carries its version; one built from a working copy carries the revision instead, and says so rather than claiming a release it is not.

Types

type Options

type Options = scanner.Options

Options is the scan configuration these flags write to.

It is codescan.Options under its internal name - the public type is an alias of this one - so this package depends downward on the scanner rather than back on the root package. A caller holding a *codescan.Options may pass it here unconverted: they are the same type.

type Values

type Values struct {
	// contains filtered or unexported fields
}

Values holds a parsed command line, before Values.Apply copies it onto the options.

Lists are held as the raw string the caller typed: splitting at Apply time keeps the three-way cases able to tell an empty list from an absent one.

func Register

func Register(fs *flag.FlagSet) *Values

Register declares every flag on fs and returns where the parsed values will land.

The whole surface is registered: a command that hides a knob only makes it unreachable, and the caller finds out by meeting "flag provided but not defined" after writing something against a surface that was never there.

func (*Values) Apply

func (v *Values) Apply(opts *Options) error

Apply copies what was parsed onto the options a scan runs with.

It fails only on a flag whose value is not one of a closed set (-loader): everything else was already validated by the flag package when it parsed.

Jump to

Keyboard shortcuts

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