Skip to content

Commit

Permalink
refactor: main into dockerMain
Browse files Browse the repository at this point in the history
Signed-off-by: Alano Terblanche <[email protected]>
  • Loading branch information
Benehiko committed Jun 7, 2024
1 parent 222683f commit a9b8be1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions cmd/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ import (
)

func main() {
statusCode := dockerMain()
if statusCode != 0 {
os.Exit(statusCode)
}
}

func dockerMain() int {
ctx, cancelNotify := signal.NotifyContext(context.Background(), platformsignals.TerminationSignals...)
defer cancelNotify()

dockerCli, err := command.NewDockerCli(command.WithBaseContext(ctx))
if err != nil {
fmt.Fprintln(os.Stderr, err)
defer os.Exit(1)
return
return 1
}
logrus.SetOutput(dockerCli.Err())
otel.SetErrorHandler(debug.OTELErrorHandler)
Expand All @@ -48,20 +54,17 @@ func main() {
// StatusError should only be used for errors, and all errors should
// have a non-zero exit status, so never exit with 0
if sterr.StatusCode == 0 {
defer os.Exit(1)
return
return 1
}
defer os.Exit(sterr.StatusCode)
return
return sterr.StatusCode
}
if errdefs.IsCancelled(err) {
defer os.Exit(0)
return
return 0
}
fmt.Fprintln(dockerCli.Err(), err)
defer os.Exit(1)
return
return 1
}
return 0
}

func newDockerCommand(dockerCli *command.DockerCli) *cli.TopLevelCommand {
Expand Down

0 comments on commit a9b8be1

Please sign in to comment.