-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add storage delete command (#831)
- Loading branch information
1 parent
2db4c2b
commit c0ed293
Showing
6 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package storage | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
cmds "github.com/saucelabs/saucectl/internal/cmd" | ||
"github.com/saucelabs/saucectl/internal/segment" | ||
"github.com/saucelabs/saucectl/internal/usage" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/text/cases" | ||
"golang.org/x/text/language" | ||
) | ||
|
||
func DeleteCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "delete <fileID>", | ||
Short: "Delete a 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") | ||
} | ||
|
||
return nil | ||
}, | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
tracker := segment.DefaultTracker | ||
|
||
go func() { | ||
tracker.Collect( | ||
cases.Title(language.English).String(cmds.FullName(cmd)), | ||
usage.Properties{}.SetFlags(cmd.Flags()), | ||
) | ||
_ = tracker.Close() | ||
}() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if err := appsClient.Delete(args[0]); err != nil { | ||
return fmt.Errorf("failed to delete file: %v", err) | ||
} | ||
|
||
println("File deleted successfully!") | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters