# README
Functions which extend the capabilities of the flag
package.
This package includes:
-
flagx.ArgsFromEnv
allows flags to be passed from the command-line or as an environment variable. -
flagx.FileBytes
is a new flag type. It automatically reads the content of the given file as a[]byte
, handling any error during flag parsing and simplifying application logic. -
flagx.StringArray
is a new flag type that handles appending to[]string
Usage of any of the above is like:
package main
import (
"flag"
"fmt"
"github.com/m-lab/go/flagx"
)
var (
flagArray flagx.StringArray
)
func main() {
flag.Var(&flagArray, "array", "append to string array")
flag.Parse()
fmt.Printf("%+v\n", flagArray)
// your code here
}
# Functions
ArgsFromEnv will expand command-line argument parsing to include setting the values of flags from their corresponding environment variables.
ArgsFromEnvWithLog operates as ArgsFromEnv with an additional option to disable logging of all flag values.
AssignedFlags returns a map[string]struct{} where every key in the map is the name of a flag in the passed-in FlagSet that was explicitly set on the command-line.
EnableAdvancedFlags adds all flags registered with the Advanced flag set to the default flag.CommandLine flag set.
MakeShellVariableName makes every passed-in string match the regexp [A-Z_][A-Z0-9_]* Characters in shell variable names should be part of the portable character set (defined to be [A-Z0-9_] in https://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html) and may not begin with a digit.
MustNewURL creates a new flagx.URL initialized with the given value.
# Variables
Advanced is a *flag.FlagSet for advanced flags.
ErrBadTimeFormat is returned when failing to parse a Time value.
# Structs
DateTime is a flag type for accepting date parameters.
Enum is a new flag type.
File is a new flag type.
FileBytesArray is a new flag type that combines the semantics of StringArray for multiple filenames and FileBytes for reading the content of each file.
KeyValue is a way of setting the elements of a map[string]string individually as key-value pairs on the command-line.
Time is a flag type for accepting time parameters formatted as HH:MM:SS.
URL is a flag type for parsing URL strings and handling errors during flag parsing.
# Type aliases
DurationArray collects time.Durations so a duration flag can be specified multiple times or using "," separated items.
FileBytes is a new flag type.
StringArray is a new flag type.