-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathparseopt.go
More file actions
53 lines (45 loc) · 1.38 KB
/
parseopt.go
File metadata and controls
53 lines (45 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package warg
import (
"os"
"go.bbkane.com/warg/metadata"
)
// ParseWithMetadata attaches custom metadata to the parse context,
// accessible later via [CmdContext].ParseMetadata. Useful for injecting test mocks.
func ParseWithMetadata(md metadata.Metadata) ParseOpt {
return func(poh *ParseOpts) {
poh.ParseMetadata = md
}
}
// func ParseWithArgs(args []string) ParseOpt {
// return func(poh *ParseOpts) {
// poh.Args = args
// }
// }
// ParseWithLookupEnv overrides the environment variable lookup function used during parsing.
// Defaults to [os.LookupEnv]. Use [LookupMap] to supply a static map for tests.
func ParseWithLookupEnv(lookup LookupEnv) ParseOpt {
return func(poh *ParseOpts) {
poh.LookupEnv = lookup
}
}
// ParseWithStderr overrides the stderr file passed to [CmdContext].
// The caller is responsible for closing the file.
func ParseWithStderr(stderr *os.File) ParseOpt {
return func(poh *ParseOpts) {
poh.Stderr = stderr
}
}
// ParseWithStdin overrides the stdin file passed to [CmdContext].
// The caller is responsible for closing the file.
func ParseWithStdin(stdin *os.File) ParseOpt {
return func(poh *ParseOpts) {
poh.Stdin = stdin
}
}
// ParseWithStdout overrides the stdout file passed to [CmdContext].
// The caller is responsible for closing the file.
func ParseWithStdout(stdout *os.File) ParseOpt {
return func(poh *ParseOpts) {
poh.Stdout = stdout
}
}