diff options
author | Steve Moyer <smoyer1@selesy.com> | 2022-06-15 09:07:00 -0400 |
---|---|---|
committer | Steve Moyer <smoyer1@selesy.com> | 2022-06-15 09:07:00 -0400 |
commit | 0a9aaa94429172d14297f709ec2137cd3749cfea (patch) | |
tree | 8a5ed7f8168d3aadfb1b80a86f2d4bbe97bf2742 /commands/env.go | |
parent | 941f5b3fc362be388dd3bd979799dd296daec243 (diff) | |
download | git-bug-0a9aaa94429172d14297f709ec2137cd3749cfea.tar.gz |
refactor(778): test only command implementations
Diffstat (limited to 'commands/env.go')
-rw-r--r-- | commands/env.go | 31 |
1 files changed, 4 insertions, 27 deletions
diff --git a/commands/env.go b/commands/env.go index 9be20c14..a6bca7e4 100644 --- a/commands/env.go +++ b/commands/env.go @@ -14,7 +14,7 @@ import ( "github.com/MichaelMure/git-bug/util/interrupt" ) -const GitBugNamespace = "git-bug" +const gitBugNamespace = "git-bug" // Env is the environment of a command type Env struct { @@ -48,35 +48,15 @@ func (o out) Println(a ...interface{}) { _, _ = fmt.Fprintln(o, a...) } -// 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 - } - - cwd, err := os.Getwd() - if err != nil { - return "", fmt.Errorf("unable to get the current working directory: %q", err) - } - - return cwd, nil -} - // 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) + cwd, err := os.Getwd() if err != nil { - return err + return fmt.Errorf("unable to get the current working directory: %q", err) } - env.repo, err = repository.OpenGoGitRepo(cwd, GitBugNamespace, []repository.ClockLoader{bug.ClockLoader}) + env.repo, err = repository.OpenGoGitRepo(cwd, gitBugNamespace, []repository.ClockLoader{bug.ClockLoader}) if err == repository.ErrNotARepo { return fmt.Errorf("%s must be run from within a git repo", rootCommandName) } @@ -163,9 +143,6 @@ func loadBackendEnsureUser(env *Env) func(*cobra.Command, []string) error { // This wrapper style is necessary because a Cobra PostE function does not run if RunE return an error. func closeBackend(env *Env, runE func(cmd *cobra.Command, args []string) error) func(*cobra.Command, []string) error { return func(cmd *cobra.Command, args []string) error { - env.err = out{Writer: cmd.ErrOrStderr()} - env.out = out{Writer: cmd.OutOrStdout()} - errRun := runE(cmd, args) if env.backend == nil { |