MCPcopy
hub / github.com/puma/puma-dev / StubCommandLineArgs

Function StubCommandLineArgs

dev/devtest/testutils.go:49–69  ·  view source on GitHub ↗

* StubCommandLineArgs overrides command arguments to allow flag-based branches to execute. It does not modify os.Args[0] so it can be used for subprocess tests. It also resets all defined flags to their default values, as `flag.Parse()` will not reset non-existent boolean flags if they have been

(args ...string)

Source from the content-addressed store, hash-verified

47 stubbed in other tests.
48*/
49func StubCommandLineArgs(args ...string) {
50 for _, arg := range args {
51 StubbedArgs[arg] += 1
52 }
53
54 for arg := range StubbedArgs {
55 stubbedFlagName := strings.Replace(arg, "-", "", -1)
56
57 if fl := flag.Lookup(stubbedFlagName); fl != nil {
58
59 oldValue := fl.Value.String()
60
61 if err := flag.Set(fl.Name, fl.DefValue); err == nil {
62 LogDebugf("reset flag %s to %s (was %s)", fl.Name, fl.Value.String(), oldValue)
63 }
64 }
65 }
66
67 os.Args = append([]string{os.Args[0]}, args...)
68 flag.Parse()
69}
70
71// EnsurePumaDevDirectory creates ~/.puma-dev if it does not already exist.
72func EnsurePumaDevDirectory() {

Calls 1

LogDebugfFunction · 0.85