Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commitb2fe134

Browse files
committed
Silence cobra error handling and use flog.Fatal
1 parentb7cd44f commitb2fe134

File tree

6 files changed

+9
-16
lines changed

6 files changed

+9
-16
lines changed

‎cmd/coder/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ func main() {
4242
app.Version=fmt.Sprintf("%s %s %s/%s",version,runtime.Version(),runtime.GOOS,runtime.GOARCH)
4343

4444
iferr:=app.ExecuteContext(ctx);err!=nil {
45-
// NOTE: The returned error is already handled and logged by the cmd lib (cobra), so no need to re-handle it here.
46-
// As we are in the main, if there was an error, exit the process with an error code.
47-
os.Exit(1)
45+
flog.Fatal("%v",err)
4846
}
4947
}

‎internal/cmd/ceapi.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import (
55

66
"cdr.dev/coder-cli/coder-sdk"
77
"golang.org/x/xerrors"
8-
9-
"go.coder.com/flog"
108
)
119

1210
// Helpers for working with the Coder Enterprise API.
@@ -73,7 +71,6 @@ func findEnv(ctx context.Context, client *coder.Client, envName, userEmail strin
7371
// Keep track of what we found for the logs.
7472
found=append(found,env.Name)
7573
}
76-
flog.Error("found %q",found)
77-
flog.Error("%q not found",envName)
74+
7875
returnnil,coder.ErrNotFound
7976
}

‎internal/cmd/cmd.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import (
1010
// Make constructs the "coder" root command
1111
funcMake()*cobra.Command {
1212
app:=&cobra.Command{
13-
Use:"coder",
14-
Short:"coder provides a CLI for working with an existing Coder Enterprise installation",
13+
Use:"coder",
14+
Short:"coder provides a CLI for working with an existing Coder Enterprise installation",
15+
SilenceErrors:true,
16+
SilenceUsage:true,
1517
}
1618

1719
app.AddCommand(

‎internal/cmd/login.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net"
77
"net/http"
88
"net/url"
9-
"os"
109
"strings"
1110

1211
"cdr.dev/coder-cli/coder-sdk"
@@ -42,10 +41,8 @@ func makeLoginCmd() *cobra.Command {
4241
// Don't return errors as it would print the usage.
4342

4443
iferr:=login(cmd,u,config.URL,config.Session);err!=nil {
45-
flog.Error("Login error: %s.",err)
46-
os.Exit(1)
44+
returnxerrors.Errorf("Login error",err)
4745
}
48-
4946
returnnil
5047
},
5148
}

‎internal/cmd/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func shell(_ *cobra.Command, cmdArgs []string) error {
7171
ifexitErr,ok:=err.(wsep.ExitError);ok {
7272
os.Exit(exitErr.Code)
7373
}
74-
flog.Fatal("%+v",err)
74+
returnxerrors.Errorf("run command: %w",err)
7575
}
7676
returnnil
7777
}

‎internal/cmd/urls.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ func validatePort(port string) (int, error) {
7575
}
7676
ifp<1 {
7777
// Port 0 means 'any free port', which we don't support.
78-
flog.Error("Port must be > 0")
79-
return0,strconv.ErrRange
78+
return0,xerrors.New("Port must be > 0")
8079
}
8180
returnint(p),nil
8281
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp