cmdline

package
v1.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: GPL-3.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Example (NewEntriesProvider_1)
// defines params line command. os.Arg[1:] is commonly used.
params := []string{"some-thing"}

_, err := NewEntriesProvider(params)

fmt.Println("when processing invalid params got error:")
fmt.Println(err)
Output:
when processing invalid params got error:
cmdline issue at position #1: arg "some-thing": invalid format
Example (NewEntriesProvider_2)
// defines params line command. os.Arg[1:] is commonly used.
params := []string{"--arg1=1", "--arg2=1", "--arg1=asdasd"}

_, err := NewEntriesProvider(params)

fmt.Println("when processing duplicated params got error:")
fmt.Println(err)
Output:
when processing duplicated params got error:
cmdline issue at position #3: --arg1 previous found at position #1: duplicate param
Example (NewEntriesProvider_3)
// defines params line command. os.Arg[1:] is commonly used.
params := []string{"--arg3=1", "--arg1=10", "--arg2=asdasd"}

provider, _ := NewEntriesProvider(params)

fmt.Println("when processing params got those entries:")

stringValues := provider.GetStringValues()

var keys []string

for key := range provider.GetStringValues() {
	keys = append(keys, key)
}

sort.Strings(keys)

for i, key := range keys {
	entry := stringValues[key]
	fmt.Printf(
		"%2d - location=%q key=%q value=%q\n",
		i,
		entry.Location,
		key,
		entry.Value,
	)
}
Output:
when processing params got those entries:
 0 - location="cmdline[--arg1]" key="arg1" value="10"
 1 - location="cmdline[--arg2]" key="arg2" value="asdasd"
 2 - location="cmdline[--arg3]" key="arg3" value="1"

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrDuplicateParam = errors.New("duplicate param")

ErrDuplicateParam represents an error when creating the provider with duplicated options in the command line.

View Source
var ErrInvalidFormat = errors.New("invalid format")

ErrInvalidFormat represents an error when creating the provider with an invalid command line option.

Functions

This section is empty.

Types

type EntriesProvider

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

EntriesProvider is an entries' provider that extract entries from command line.

func NewEntriesProvider

func NewEntriesProvider(commandLine []string) (*EntriesProvider, error)

NewEntriesProvider creates an entries' provider that parses and extract parameters from command line.

Each command line parameter MUST match regexp '^--([a-z\d_-]+)=(.+)$'. ErrInvalidFormat is returned in such a case.

func (*EntriesProvider) GetStringValues

func (ep *EntriesProvider) GetStringValues() svalue.Values

GetStringValues implements svalue.Provider interface.

type ParamError

type ParamError struct {
	Positions []int
	Errs      []error
}

ParamError represents an error when creating the provider with invalid parameters.

func (*ParamError) Error

func (e *ParamError) Error() string

Jump to

Keyboard shortcuts

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