Illustrates the handling of Values.
// examples/values.go
package main
import (
libclimate "github.com/synesissoftware/libCLImate.Go"
"fmt"
"os"
)
func main() {
// Specify specifications, parse, and checking standard flags
climate, _ := libclimate.Init(func(cl *libclimate.Climate) (err error) {
cl.Version = []int{0, 0, 1}
cl.InfoLines = []string{
"libCLImate.Go Examples",
"",
":version:",
"",
}
cl.ValueNames = []string{"country name", "state id", "city name", "district id"}
cl.ValuesConstraint = []int{2, 4}
cl.ValuesString = "<country-name> <state-id> [ <city-name> [ <district-id> ]]"
return nil
}, libclimate.InitFlag_PanicOnFailure)
r, _ := climate.ParseAndVerify(os.Args, libclimate.ParseFlag_PanicOnFailure)
// Program logic
fmt.Printf("%v value(s):\n", len(r.Values))
for ix, value := range r.Values {
fmt.Printf("\t[%d]\t'%s'\n", ix, value.Value)
}
}If executed with no arguments
go run examples/values.goit gives the output:
values: country name not specified
If executed with the arguments
go run examples/values.go --helpit gives the output:
libCLImate.Go Examples
values 0.0.1
USAGE: values [ ... flags and options ... ] <country-name> <state-name> [ <city-name> [ <district-id> ]]
flags/options:
--help
Shows this help and exits
--version
Shows version information and exits
If executed with the arguments
go run examples/values.go Englandit gives the output:
values: state id not specified
If executed with the arguments
go run examples/values.go England Worcestershireit gives the output:
2 value(s):
[0] 'England'
[1] 'Worcestershire'
If executed with the arguments
go run examples/values.go England Worcestershire Eveshamit gives the output:
3 value(s):
[0] 'England'
[1] 'Worcestershire'
[2] 'Evesham'
If executed with the arguments
go run examples/values.go England Worcestershire Evesham Bengeworthit gives the output:
4 value(s):
[0] 'England'
[1] 'Worcestershire'
[2] 'Evesham'
[3] 'Bengeworth'
If executed with the arguments
go run examples/values.go England Worcestershire Evesham Bengeworth Badsleyit gives the output:
values: too many values