Skip to content

Commit

Permalink
feat: silence usage on errors
Browse files Browse the repository at this point in the history
Signed-off-by: Kasper J. Hermansen <contact@kjuulh.io>
  • Loading branch information
kjuulh committed Apr 12, 2024
1 parent 8a28519 commit ea78391
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 51 deletions.
3 changes: 1 addition & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/spf13/cobra"

"github.com/lunarway/shuttle/pkg/config"
"github.com/lunarway/shuttle/pkg/errors"
"github.com/lunarway/shuttle/pkg/executors"
"github.com/lunarway/shuttle/pkg/ui"
)
Expand Down Expand Up @@ -206,7 +205,7 @@ func newRunSubCommand(
err := executorRegistry.Execute(ctx, context, script, actualArgs, *validateArgs)
if err != nil {
traceError(err)
return errors.NewExitCode(1, "cmd failed: %s", err.Error())
return err
}

return nil
Expand Down
54 changes: 5 additions & 49 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,6 @@ import (
)

func TestRun(t *testing.T) {

usage := `Usage:
shuttle run required_arg [flags]
Flags:
--foo string
-h, --help help for required_arg
Global Flags:
-c, --clean Start from clean setup
--interactive sets whether to enable ui for getting missing values via. prompt instead of failing immediadly, default is set by [SHUTTLE_INTERACTIVE=true/false]
--plan string Overload the plan used.
Specifying a local path with either an absolute path (/some/plan) or a relative path (../some/plan) to another location
for the selected plan.
Select a version of a git plan by using #branch, #sha or #tag
If none of above is used, then the argument will expect a full plan spec.
-p, --project string Project path (default ".")
--skip-pull Skip git plan pulling step
--template string Template string to use. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
--validate Validate arguments against script definition in plan and exit with 1 on unknown or missing arguments (default true)
-v, --verbose Print verbose output
`

pwd, err := os.Getwd()
if err != nil {
t.Fatalf("Failed to get working directory: %v", err)
Expand Down Expand Up @@ -60,29 +36,9 @@ Global Flags:
err: nil,
},
{
name: "exit 1",
input: args("-p", "testdata/project", "run", "exit_1"),
stdoutput: `Usage:
shuttle run exit_1 [flags]
Flags:
-h, --help help for exit_1
Global Flags:
-c, --clean Start from clean setup
--interactive sets whether to enable ui for getting missing values via. prompt instead of failing immediadly, default is set by [SHUTTLE_INTERACTIVE=true/false]
--plan string Overload the plan used.
Specifying a local path with either an absolute path (/some/plan) or a relative path (../some/plan) to another location
for the selected plan.
Select a version of a git plan by using #branch, #sha or #tag
If none of above is used, then the argument will expect a full plan spec.
-p, --project string Project path (default ".")
--skip-pull Skip git plan pulling step
--template string Template string to use. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
--validate Validate arguments against script definition in plan and exit with 1 on unknown or missing arguments (default true)
-v, --verbose Print verbose output
`,
name: "exit 1",
input: args("-p", "testdata/project", "run", "exit_1"),
stdoutput: ``,
erroutput: "Error: exit code 4 - Failed executing script `exit_1`: shell script `exit 1`\nExit code: 1\n",
err: errors.New(
"exit code 4 - Failed executing script `exit_1`: shell script `exit 1`\nExit code: 1",
Expand All @@ -107,7 +63,7 @@ Global Flags:
{
name: "script fails when required argument is missing",
input: args("-p", "testdata/project", "run", "required_arg"),
stdoutput: usage,
stdoutput: "",
erroutput: `Error: Error: required flag(s) "foo" not set
`,
err: errors.New(`Error: required flag(s) "foo" not set`),
Expand Down Expand Up @@ -150,7 +106,7 @@ Global Flags:
{
name: "script fails on unkown argument",
input: args("-p", "testdata/project", "run", "required_arg", "foo=bar", "--a b"),
stdoutput: usage,
stdoutput: "",
erroutput: `Error: unknown flag: --a b
`,
err: errors.New(`unknown flag: --a b`),
Expand Down

0 comments on commit ea78391

Please sign in to comment.