Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions go/cmd/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var (
valueStyle = cli.ValueStyle
)

func registerCICommands(c *core.Core) {
_ = c.Command("ci", core.Command{
func registerCICommands(c *core.Core) core.Result {
if r := c.Command("ci", core.Command{
Description: "cmd.ci.long",
Action: func(opts core.Options) core.Result {
dryRun := !cmdutil.OptionBool(opts, "we-are-go-for-launch")
Expand All @@ -32,16 +32,20 @@ func registerCICommands(c *core.Core) {
cmdutil.OptionBool(opts, "prerelease"),
)
},
})
}); !r.OK {
return r
}

_ = c.Command("ci/init", core.Command{
if r := c.Command("ci/init", core.Command{
Description: "cmd.ci.init.long",
Action: func(opts core.Options) core.Result {
return runCIReleaseInit()
},
})
}); !r.OK {
return r
}

_ = c.Command("ci/changelog", core.Command{
if r := c.Command("ci/changelog", core.Command{
Description: "cmd.ci.changelog.long",
Action: func(opts core.Options) core.Result {
return runChangelog(
Expand All @@ -50,14 +54,19 @@ func registerCICommands(c *core.Core) {
cmdutil.OptionString(opts, "to"),
)
},
})
}); !r.OK {
return r
}

_ = c.Command("ci/version", core.Command{
if r := c.Command("ci/version", core.Command{
Description: "cmd.ci.version.long",
Action: func(opts core.Options) core.Result {
return runCIReleaseVersion(cmdutil.ContextOrBackground())
},
})
}); !r.OK {
return r
}
return core.Ok(nil)
}

// runCIPublish publishes pre-built artifacts from dist/.
Expand Down
4 changes: 2 additions & 2 deletions go/cmd/ci/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import (
// AddCICommands registers the 'ci' command and all subcommands.
//
// ci.AddCICommands(root)
func AddCICommands(c *core.Core) {
registerCICommands(c)
func AddCICommands(c *core.Core) core.Result {
return registerCICommands(c)
}
27 changes: 18 additions & 9 deletions go/cmd/sdk/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ var (
// AddSDKCommands registers the 'sdk' command and all subcommands.
//
// sdkcmd.AddSDKCommands(root)
func AddSDKCommands(c *core.Core) {
registerSDKGenerateCommand(c, "sdk")
registerSDKGenerateCommand(c, "sdk/generate")
func AddSDKCommands(c *core.Core) core.Result {
if r := registerSDKGenerateCommand(c, "sdk"); !r.OK {
return r
}
if r := registerSDKGenerateCommand(c, "sdk/generate"); !r.OK {
return r
}

_ = c.Command("sdk/diff", core.Command{
if r := c.Command("sdk/diff", core.Command{
Description: "cmd.sdk.diff.long",
Action: func(opts core.Options) core.Result {
return runSDKDiff(
Expand All @@ -46,20 +50,25 @@ func AddSDKCommands(c *core.Core) {
cmdutil.OptionBool(opts, "fail-on-warn", "fail_on_warn"),
)
},
})
}); !r.OK {
return r
}

_ = c.Command("sdk/validate", core.Command{
if r := c.Command("sdk/validate", core.Command{
Description: "cmd.sdk.validate.long",
Action: func(opts core.Options) core.Result {
return runSDKValidate(
cmdutil.OptionString(opts, "spec"),
)
},
})
}); !r.OK {
return r
}
return core.Ok(nil)
}

func registerSDKGenerateCommand(c *core.Core, path string) {
_ = c.Command(path, core.Command{
func registerSDKGenerateCommand(c *core.Core, path string) core.Result {
return c.Command(path, core.Command{
Description: "cmd.sdk.long",
Action: func(opts core.Options) core.Result {
return runSDKGenerate(
Expand Down
45 changes: 30 additions & 15 deletions go/cmd/service/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,56 +28,71 @@ var (
type serviceRequest = servicecommon.Request

// AddServiceCommands registers `core service` commands.
func AddServiceCommands(c *core.Core) {
_ = c.Command("service", core.Command{
func AddServiceCommands(c *core.Core) core.Result {
if r := c.Command("service", core.Command{
Description: "cmd.service.long",
Action: func(opts core.Options) core.Result {
return core.Fail(core.E("service", "use a subcommand: install, start, stop, uninstall, export", nil))
},
})
}); !r.OK {
return r
}

_ = c.Command("service/install", core.Command{
if r := c.Command("service/install", core.Command{
Description: "cmd.service.install.long",
Action: func(opts core.Options) core.Result {
return runServiceInstall(requestFromOptions(opts))
},
})
}); !r.OK {
return r
}

_ = c.Command("service/start", core.Command{
if r := c.Command("service/start", core.Command{
Description: "cmd.service.start.long",
Action: func(opts core.Options) core.Result {
return runServiceStart(requestFromOptions(opts))
},
})
}); !r.OK {
return r
}

_ = c.Command("service/stop", core.Command{
if r := c.Command("service/stop", core.Command{
Description: "cmd.service.stop.long",
Action: func(opts core.Options) core.Result {
return runServiceStop(requestFromOptions(opts))
},
})
}); !r.OK {
return r
}

_ = c.Command("service/uninstall", core.Command{
if r := c.Command("service/uninstall", core.Command{
Description: "cmd.service.uninstall.long",
Action: func(opts core.Options) core.Result {
return runServiceUninstall(requestFromOptions(opts))
},
})
}); !r.OK {
return r
}

_ = c.Command("service/export", core.Command{
if r := c.Command("service/export", core.Command{
Description: "cmd.service.export.long",
Action: func(opts core.Options) core.Result {
return runServiceExport(requestFromOptions(opts))
},
})
}); !r.OK {
return r
}

_ = c.Command("service/run", core.Command{
if r := c.Command("service/run", core.Command{
Description: "cmd.service.run.long",
Hidden: true,
Action: func(opts core.Options) core.Result {
return runServiceRun(cmdutil.ContextOrBackground(), requestFromOptions(opts))
},
})
}); !r.OK {
return r
}
return core.Ok(nil)
}

func requestFromOptions(opts core.Options) serviceRequest {
Expand Down
6 changes: 3 additions & 3 deletions go/internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Blank() {
}

func Err(format string, args ...any) core.Result {
return core.Fail(core.Errorf(format, args...))
return core.Fail(core.E("cli.Err", core.Sprintf(format, args...), nil))
}

func Wrap(cause any, message string) core.Result {
Expand All @@ -71,7 +71,7 @@ func Wrap(cause any, message string) core.Result {
if message == "" {
return core.Fail(err)
}
return core.Fail(core.Errorf("%s: %w", message, err))
return core.Fail(core.E("cli.Wrap", message, err))
}

func WrapVerb(cause any, verb, subject string) core.Result {
Expand All @@ -82,7 +82,7 @@ func WrapVerb(cause any, verb, subject string) core.Result {
if !ok {
err = core.NewError(core.Sprintf("%v", cause))
}
return core.Fail(core.Errorf("failed to %s %s: %w", verb, subject, err))
return core.Fail(core.E("cli.WrapVerb", core.Sprintf("failed to %s %s", verb, subject), err))
}

type ExitError struct {
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/service/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Export(cfg Config, format string) core.Result {
Content: renderWindows(cfg),
})
default:
return core.Fail(core.Errorf("unsupported native service format: %s", nativeFormat))
return core.Fail(core.E("service.Export", "unsupported native service format: "+string(nativeFormat), nil))
}
}

Expand Down
Loading