Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide Usage when PreRun fails #752

Merged
merged 1 commit into from
Apr 24, 2023
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
1 change: 1 addition & 0 deletions cmd/saucectl/saucectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func main() {
Use: cmdUse,
Short: cmdShort,
Long: cmdLong,
SilenceUsage: true,
TraverseChildren: true,
Version: fmt.Sprintf("%s\n(build %s)", version.Version, version.GitCommit),
}
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/artifacts/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Command(preRun func(cmd *cobra.Command, args []string)) *cobra.Command {
cmd := &cobra.Command{
Use: "artifacts",
Short: "Interact with job artifacts",
SilenceUsage: true,
TraverseChildren: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if preRun != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/artifacts/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ func DownloadCommand() *cobra.Command {
var out string

cmd := &cobra.Command{
Use: "download <jobID> <file-pattern>",
Short: "Downloads the specified artifacts from the given job. Supports glob pattern.",
Use: "download <jobID> <file-pattern>",
Short: "Downloads the specified artifacts from the given job. Supports glob pattern.",
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 || args[0] == "" {
return errors.New("no job ID specified")
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/artifacts/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func ListCommand() *cobra.Command {
Aliases: []string{
"ls",
},
Short: "Returns the list of artifacts for the specified job.",
Short: "Returns the list of artifacts for the specified job.",
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 || args[0] == "" {
return errors.New("no job ID specified")
Expand Down
7 changes: 4 additions & 3 deletions internal/cmd/artifacts/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ func UploadCommand() *cobra.Command {
var out string

cmd := &cobra.Command{
Use: "upload <jobID> <filename>",
Short: "Uploads an artifact for the job.",
Long: "Uploads an artifact for the job. Real Device job is not supported.",
Use: "upload <jobID> <filename>",
Short: "Uploads an artifact for the job.",
Long: "Uploads an artifact for the job. Real Device job is not supported.",
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 || args[0] == "" {
return errors.New("no job ID specified")
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/completion/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ PowerShell:
PS> saucectl completion powershell > saucectl.ps1
`,
DisableFlagsInUseLine: true,
SilenceUsage: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/configure/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ var (
// Command creates the `configure` command
func Command() *cobra.Command {
cmd := &cobra.Command{
Use: configureUse,
Short: configureShort,
Long: configureLong,
Example: configureExample,
Use: configureUse,
Short: configureShort,
Long: configureLong,
Example: configureExample,
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
tracker := segment.DefaultTracker

Expand Down
10 changes: 6 additions & 4 deletions internal/cmd/imagerunner/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ var defaultTableStyle = table.Style{

func ArtifactsCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "artifacts",
Short: "Commands for interacting with artifacts produced by the imagerunner.",
Use: "artifacts",
Short: "Commands for interacting with artifacts produced by the imagerunner.",
SilenceUsage: true,
}

cmd.AddCommand(
Expand All @@ -80,8 +81,9 @@ func downloadCommand() *cobra.Command {
var out string

cmd := &cobra.Command{
Use: "download <runID> <file-pattern>",
Short: "Downloads the specified artifacts from the given run. Supports glob pattern.",
Use: "download <runID> <file-pattern>",
Short: "Downloads the specified artifacts from the given run. Supports glob pattern.",
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 || args[0] == "" {
return errors.New("no run ID specified")
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/imagerunner/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ func Command(preRun func(cmd *cobra.Command, args []string)) *cobra.Command {
var regio string

cmd := &cobra.Command{
Use: "imagerunner",
Short: "Commands for interacting with imagerunner runs",
Use: "imagerunner",
Short: "Commands for interacting with imagerunner runs",
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if preRun != nil {
preRun(cmd, args)
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/imagerunner/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (

func LogsCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "logs <runID>",
Short: "Fetch the logs for an imagerunner run",
Use: "logs <runID>",
Short: "Fetch the logs for an imagerunner run",
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 || args[0] == "" {
return errors.New("no run ID specified")
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/ini/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ func Command() *cobra.Command {
initCfg := &initConfig{}

cmd := &cobra.Command{
Use: initUse,
Short: initShort,
Long: initLong,
Example: initExample,
Use: initUse,
Short: initShort,
Long: initLong,
Example: initExample,
SilenceUsage: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
return preRun()
},
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/jobs/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func Command(preRun func(cmd *cobra.Command, args []string)) *cobra.Command {
cmd := &cobra.Command{
Use: "jobs",
Short: "Interact with jobs",
SilenceUsage: true,
TraverseChildren: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if preRun != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/jobs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func GetCommand() *cobra.Command {
var out string

cmd := &cobra.Command{
Use: "get",
Short: "Get job by id",
Use: "get",
Short: "Get job by id",
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 || args[0] == "" {
return errors.New("no job ID specified")
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/jobs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ func ListCommand() *cobra.Command {
Aliases: []string{
"ls",
},
Short: "Returns the list of jobs",
Short: "Returns the list of jobs",
SilenceUsage: true,
PreRun: func(cmd *cobra.Command, args []string) {
tracker := segment.DefaultTracker

Expand Down
11 changes: 6 additions & 5 deletions internal/cmd/new/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ var (
// Command creates the `new` command
func Command() *cobra.Command {
cmd := &cobra.Command{
Deprecated: deprecationMsg,
Use: newUse,
Short: newShort,
Long: newLong,
Example: newExample,
Deprecated: deprecationMsg,
Use: newUse,
Short: newShort,
Long: newLong,
Example: newExample,
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
},
}
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/run/cucumber.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func NewCucumberCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "cucumberjs",
Short: "Run Cucumber test",
SilenceUsage: true,
Hidden: true,
TraverseChildren: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/run/cypress.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewCypressCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "cypress",
Short: "Run cypress tests",
SilenceUsage: true,
Hidden: true, // TODO reveal command once ready
TraverseChildren: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/run/espresso.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewEspressoCmd() *cobra.Command {
Short: "Run espresso tests",
Long: "Unlike 'saucectl run', this command allows you to bypass the config file partially or entirely by configuring an adhoc suite (--name) via flags.",
Example: `saucectl run espresso -c "" --name "My Suite" --app app.apk --testApp testApp.apk --otherApps=a.apk,b.apk --device name="Google Pixel.*",platformVersion=14.0,carrierConnectivity=false,deviceType=PHONE,private=false --emulator name="Android Emulator",platformVersion=8.0`,
SilenceUsage: true,
Hidden: true, // TODO reveal command once ready
TraverseChildren: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/run/playwright.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewPlaywrightCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "playwright",
Short: "Run playwright tests",
SilenceUsage: true,
Hidden: true, // TODO reveal command once ready
TraverseChildren: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/run/puppeteer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func NewPuppeteerCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "puppeteer",
Short: "Run puppeteer tests",
SilenceUsage: true,
Hidden: true, // TODO reveal command once ready
TraverseChildren: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/run/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewReplayCmd() *cobra.Command {
Short: "Replay chrome devtools recordings",
Long: "Unlike 'saucectl run', this command allows you to bypass the config file partially or entirely by configuring an adhoc suite (--name) via flags.",
Example: `saucectl run replay recording.json -c "" --name "My Suite"`,
SilenceUsage: true,
TraverseChildren: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
sc.BindAll()
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func Command() *cobra.Command {
cmd := &cobra.Command{
Use: runUse,
Short: runShort,
SilenceUsage: true,
TraverseChildren: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
return preRun()
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/run/testcafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func NewTestcafeCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "testcafe",
Short: "Run testcafe tests",
SilenceUsage: true,
Hidden: true, // TODO reveal command once ready
TraverseChildren: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/run/xcuitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func NewXCUITestCmd() *cobra.Command {
Short: "Run xcuitest tests.",
Long: "Unlike 'saucectl run', this command allows you to bypass the config file partially or entirely by configuring an adhoc suite (--name) via flags.",
Example: `saucectl run xcuitest -c "" --name "My Suite" --app app.ipa --testApp testApp.ipa --otherApps=a.ipa,b.ipa --device name="iPhone.*",platformVersion=14.0,carrierConnectivity=false,deviceType=PHONE,private=false`,
SilenceUsage: true,
Hidden: true, // TODO reveal command once ready
TraverseChildren: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down
9 changes: 5 additions & 4 deletions internal/cmd/signup/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ var (
// Command creates the `run` command
func Command() *cobra.Command {
cmd := &cobra.Command{
Use: runUse,
Short: runShort,
Long: runLong,
Example: runExample,
Use: runUse,
Short: runShort,
Long: runLong,
Example: runExample,
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
log.Info().Msg("Start Signup Command")
err := Run()
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/storage/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Command(preRun func(cmd *cobra.Command, args []string)) *cobra.Command {
cmd := &cobra.Command{
Use: "storage",
Short: "Interact with Sauce Storage",
SilenceUsage: true,
TraverseChildren: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if preRun != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/cmd/storage/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ func DownloadCommand() *cobra.Command {
var filename string

cmd := &cobra.Command{
Use: "download fileID",
Short: "Downloads an app file from Sauce Storage.",
Use: "download fileID",
Short: "Downloads an app file from Sauce Storage.",
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 || args[0] == "" {
return errors.New("no ID specified")
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/storage/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func ListCommand() *cobra.Command {
Aliases: []string{
"ls",
},
Short: "Returns the list of files that have been uploaded to Sauce Storage.",
Short: "Returns the list of files that have been uploaded to Sauce Storage.",
SilenceUsage: true,
PreRun: func(cmd *cobra.Command, args []string) {
tracker := segment.DefaultTracker

Expand Down
1 change: 1 addition & 0 deletions internal/cmd/storage/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func UploadCommand() *cobra.Command {
Use: "upload filename",
Short: "Uploads an app file to Sauce Storage and returns a unique file ID assigned to the app. " +
"Sauce Storage supports app files in *.apk, *.aab, *.ipa, or *.zip format.",
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 || args[0] == "" {
return errors.New("no filename specified")
Expand Down