diff options
-rw-r--r-- | commands/env.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/commands/env.go b/commands/env.go index c2128780..9be20c14 100644 --- a/commands/env.go +++ b/commands/env.go @@ -48,7 +48,13 @@ func (o out) Println(a ...interface{}) { _, _ = fmt.Fprintln(o, a...) } -func getCWD(cmd *cobra.Command, args []string) (string, error) { +// getCWD returns the current working directory. Normal operation simply +// returns the working directory reported by the OS (as an OS-compatible +// filepath.) During tests, temporary repositories are created outside +// the test execution's CWD. In this case, it's possible to provide an +// alternate CWD filepath by adding a value to the command's context +// with the key "cwd". +func getCWD(cmd *cobra.Command) (string, error) { cwd, ok := cmd.Context().Value("cwd").(string) if cwd != "" && ok { return cwd, nil @@ -65,7 +71,7 @@ func getCWD(cmd *cobra.Command, args []string) (string, error) { // loadRepo is a pre-run function that load the repository for use in a command func loadRepo(env *Env) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { - cwd, err := getCWD(cmd, args) + cwd, err := getCWD(cmd) if err != nil { return err } |