From 6ec7d67ea14d236c65b3d93bb4c4501432696659 Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Tue, 7 Jun 2022 07:45:30 -0400 Subject: test(808): document getCWD() and clean-up arguments --- commands/env.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'commands/env.go') 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 } -- cgit