...
1
2
3
4
5 package base
6
7 import (
8 "flag"
9 "fmt"
10
11 "cmd/go/internal/cfg"
12 "cmd/go/internal/fsys"
13 "cmd/internal/quoted"
14 )
15
16
17
18 type StringsFlag []string
19
20 func (v *StringsFlag) Set(s string) error {
21 var err error
22 *v, err = quoted.Split(s)
23 if *v == nil {
24 *v = []string{}
25 }
26 return err
27 }
28
29 func (v *StringsFlag) String() string {
30 return "<StringsFlag>"
31 }
32
33
34
35 type explicitStringFlag struct {
36 value *string
37 explicit *bool
38 }
39
40 func (f explicitStringFlag) String() string {
41 if f.value == nil {
42 return ""
43 }
44 return *f.value
45 }
46
47 func (f explicitStringFlag) Set(v string) error {
48 *f.value = v
49 if v != "" {
50 *f.explicit = true
51 }
52 return nil
53 }
54
55
56 func AddBuildFlagsNX(flags *flag.FlagSet) {
57 flags.BoolVar(&cfg.BuildN, "n", false, "")
58 flags.BoolVar(&cfg.BuildX, "x", false, "")
59 }
60
61
62 func AddChdirFlag(flags *flag.FlagSet) {
63
64
65 flags.Func("C", "AddChdirFlag", ChdirFlag)
66 }
67
68
69 func AddModFlag(flags *flag.FlagSet) {
70 flags.Var(explicitStringFlag{value: &cfg.BuildMod, explicit: &cfg.BuildModExplicit}, "mod", "")
71 }
72
73
74
75 func AddModCommonFlags(flags *flag.FlagSet) {
76 flags.BoolVar(&cfg.ModCacheRW, "modcacherw", false, "")
77 flags.StringVar(&cfg.ModFile, "modfile", "", "")
78 flags.StringVar(&fsys.OverlayFile, "overlay", "", "")
79 }
80
81 func ChdirFlag(s string) error {
82
83
84 return fmt.Errorf("-C flag must be first flag on command line")
85 }
86
View as plain text