diff options
author | Julien Dessaux | 2024-05-01 16:23:08 +0200 |
---|---|---|
committer | Julien Dessaux | 2024-05-01 16:23:08 +0200 |
commit | 8b9195e3e3506d576b39a23ca646c260dfacc808 (patch) | |
tree | 1cdbdd2fb368654ef8eab702258eb5d6a90e1447 /cmd | |
parent | chore(gonf): fix go vet and staticcheck errors (diff) | |
download | gonf-8b9195e3e3506d576b39a23ca646c260dfacc808.tar.gz gonf-8b9195e3e3506d576b39a23ca646c260dfacc808.tar.bz2 gonf-8b9195e3e3506d576b39a23ca646c260dfacc808.zip |
chore(gonf): fix errcheck and shadow errors
Diffstat (limited to '')
-rw-r--r-- | cmd/gonf/cmd_build.go | 16 | ||||
-rw-r--r-- | cmd/gonf/main.go | 10 |
2 files changed, 17 insertions, 9 deletions
diff --git a/cmd/gonf/cmd_build.go b/cmd/gonf/cmd_build.go index ebcde29..6a59b4b 100644 --- a/cmd/gonf/cmd_build.go +++ b/cmd/gonf/cmd_build.go @@ -19,7 +19,7 @@ func cmdBuild(ctx context.Context, where FLAG can be one or more of`, flag.ContinueOnError) hostFlag := addHostFlag(f) f.SetOutput(stderr) - f.Parse(args) + _ = f.Parse(args) if helpMode { f.SetOutput(stdout) f.Usage() @@ -32,17 +32,23 @@ where FLAG can be one or more of`, flag.ContinueOnError) return runBuild(ctx, stderr, hostDir) } -func runBuild(ctx context.Context, stderr io.Writer, hostDir string) error { +func runBuild(ctx context.Context, stderr io.Writer, hostDir string) (err error) { wd, err := os.Getwd() if err != nil { return err } - defer os.Chdir(wd) - os.Chdir(hostDir) + defer func() { + if e := os.Chdir(wd); err == nil { + err = e + } + }() + if err = os.Chdir(hostDir); err != nil { + return err + } cmd := exec.CommandContext(ctx, "go", "build", "-ldflags", "-s -w -extldflags \"-static\"", hostDir) cmd.Env = append(cmd.Environ(), "CGO_ENABLED=0") if out, err := cmd.CombinedOutput(); err != nil { - fmt.Fprint(stderr, string(out)) + _, _ = fmt.Fprint(stderr, string(out)) return err } return nil diff --git a/cmd/gonf/main.go b/cmd/gonf/main.go index 8dae51d..fe6f065 100644 --- a/cmd/gonf/main.go +++ b/cmd/gonf/main.go @@ -49,11 +49,13 @@ where FLAG can be one or more of`, flag.ContinueOnError) f.BoolVar(&helpMode, "help", false, "show contextual help") f.StringVar(&configDir, "config", "", "(REQUIRED for most commands) path to a gonf configurations repository (overrides the GONF_CONFIG environment variable)") f.SetOutput(stderr) - f.Parse(args[1:]) + if err := f.Parse(args[1:]); err != nil { + return err + } if f.NArg() < 1 { f.Usage() - return errors.New("No command given") + return errors.New("no command given") } cmd := f.Arg(0) argsTail := f.Args()[1:] @@ -68,7 +70,7 @@ where FLAG can be one or more of`, flag.ContinueOnError) configDir = getenv("GONF_CONFIG") if configDir == "" { f.Usage() - return errors.New("The GONF_CONFIG environment variable is unset and the -config FLAG is missing. Please use one or the other.") + return errors.New("the GONF_CONFIG environment variable is unset and the -config FLAG is missing. Please use one or the other") } } switch cmd { @@ -76,7 +78,7 @@ where FLAG can be one or more of`, flag.ContinueOnError) return cmdBuild(ctx, f, argsTail, getenv, stdout, stderr) default: f.Usage() - return fmt.Errorf("Invalid command: %s", cmd) + return fmt.Errorf("invalid command: %s", cmd) } } return nil |