opt

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: BSD-3-Clause Imports: 2 Imported by: 10

README

opt

Package opt implements command-line flag parsing.

Installation
$ go get [-u] modernc.org/opt
Documentation

godoc.org/modernc.org/opt

Documentation

Overview

Package opt implements command-line flag parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

A Set represents a set of defined options.

func NewSet

func NewSet() *Set

NewSet returns a new, empty option set.

func (*Set) Arg

func (p *Set) Arg(name string, imm bool, handler func(opt, arg string) error)

Arg defines a simple option with an argument, e.g. `-I foo` or `-I=foo`. Setting imm argument enables additionally `-Ifoo`. When the option is found during Parse, the handler is called with the values of the option and the argument, e.g. "-I" and "foo" for all of the variants.

func (*Set) Opt

func (p *Set) Opt(name string, handler func(opt string) error)

Opt defines a simple option, e.g. `-f`. When the option is found during Parse, the handler is called with the value of the option, e.g. "-f".

func (*Set) Parse

func (p *Set) Parse(opts []string, handler func(string) error) (err error)

Parse parses opts. Must be called after all options are defined. The handler is called for all items in opts that were not defined before using Opt or Arg.

If any handler returns a non-nil error, Parse will stop. If the error is of type Skip, the error returned by Parse will contain all the unprocessed items of opts.

The opts slice must not be modified by any handler while Parser is executing.

type Skip

type Skip []string

Skip is an error that contains all unprocessed items passed to Parse.

func (Skip) Error

func (s Skip) Error() string

Jump to

Keyboard shortcuts

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