diff options
author | Ethel Morgan <eth@ethulhu.co.uk> | 2020-06-24 12:10:57 +0100 |
---|---|---|
committer | Ethel Morgan <eth@ethulhu.co.uk> | 2020-06-24 12:10:57 +0100 |
commit | aa380da6a61f9b29ee263d95d17a2953a0528b28 (patch) | |
tree | c2915f6508ed321eeacb6ca3c7ba8de313c0ce11 /doc.go | |
parent | 02f268cc3ba056be15097a7185a367585dd05275 (diff) |
import package flag from helixv0.0.1
Diffstat (limited to 'doc.go')
-rw-r--r-- | doc.go | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2020 Ethel Morgan +// +// SPDX-License-Identifier: MIT + +/* +Package flag wraps Go's built-in flag package, with the addition of idiomatic custom flags. + +Custom Flags + +Custom flags are wrappers around Go's built-in string flags, with a parser +func. They can be used to parse custom flag types, or to have custom flag +validators, while keeping the parsing & validation with the flag's definition. + + var ( + urlFlag = flag.Custom("url", "", "url to GET", func(raw string) (interface{}, error) { + return url.Parse(raw) + }) + outputFlag = flag.Custom("output", "", "output format", func(raw string) (interface{}, error) { + if !(raw == "table" || raw == "json") { + return nil, fmt.Errorf("must be either json or table, got %v", raw) + } + return raw, nil + }) + ) + + func main() { + flag.Parse() + urlFlag := (*urlFlag).(*url.URL) + outputFlag := (*outputFlag).(string) + } + +*/ +package flag |