Documentation ¶
Overview ¶
cli package is a goschtalt decoder package for processing the command line interface.
See the example for how to use this extension package.
Example ¶
package main import ( "fmt" "strings" "github.com/schmidtw/goschtalt" "github.com/schmidtw/goschtalt/extensions/decoders/cli" ) func main() { args := []string{ "--kvp", "example.version", "1", "--kvp", "example.colors.0", "red", "--kvp", "example.colors.1", "green", "--kvp", "example.colors.2", "blue", } g, err := goschtalt.New(cli.Options("cli", ".", args)...) if err != nil { panic(err) } err = g.Compile() if err != nil { panic(err) } var cfg struct { Example struct { Version int Colors []string } } err = g.Unmarshal("", &cfg) if err != nil { panic(err) } fmt.Println("example") fmt.Printf(" version = %d\n", cfg.Example.Version) fmt.Printf(" colors = [ %s ]\n", strings.Join(cfg.Example.Colors, ", ")) }
Output: example version = 1 colors = [ red, green, blue ]
Index ¶
Examples ¶
Constants ¶
View Source
const Extension = `cli`
The extension this decoder uses since the decode itself isn't public.
Variables ¶
View Source
var ErrInput = errors.New("invalid input")
Functions ¶
func Options ¶
func Options(filename, delimiter string, args []string, dirFS ...func(string) fs.FS) []goschtalt.Option
CLIConfig is a lightweight and opinionated command line processor that configures goschtalt.Config based on command line options referencing the local filesystem(s) based on relative or absolut paths. Additionally, key/value pairs can be provided as well.
The list of command options: (each may be repeated any number of times) [-f filename] / [--file filename] provides an exact file to evaluate [-d dir] / [--dir dir] provides a directory to examine for files [-r dir] / [--recurse dir] provides a directory tree to examine for files recursively [--kvp key value] provides a specific key and value pair that should be set
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.