From aa380da6a61f9b29ee263d95d17a2953a0528b28 Mon Sep 17 00:00:00 2001 From: Ethel Morgan Date: Wed, 24 Jun 2020 12:10:57 +0100 Subject: import package flag from helix --- doc.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 doc.go (limited to 'doc.go') diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..fa9c9fd --- /dev/null +++ b/doc.go @@ -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 -- cgit v1.2.3