Skip to content

Commit

Permalink
crc-embedder: Use cobra.ExactArgs
Browse files Browse the repository at this point in the history
Checks for the number of arguments was done manually (`len(args)`)
while cobra provides a helper for this.
This also adds a missing check in `crc-embedder download`
  • Loading branch information
cfergeau authored and guillaumerose committed Aug 19, 2021
1 parent 7759fb6 commit 9c730a6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/crc-embedder/cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func init() {
}

var downloadCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Use: "download",
Short: "Download data files embedded in the crc executable",
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
4 changes: 1 addition & 3 deletions cmd/crc-embedder/cmd/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func init() {
}

var embedCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Use: "embed",
Short: "Embed data files in crc executable",
Long: `Embed the OpenShift bundle and the binaries needed at runtime in the crc executable`,
Expand All @@ -39,9 +40,6 @@ var embedCmd = &cobra.Command{
}

func runEmbed(args []string) {
if len(args) != 1 {
logging.Fatal("embed takes exactly one argument")
}
executablePath := args[0]
destDir, err := ioutil.TempDir("", "crc-embedder")
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions cmd/crc-embedder/cmd/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func init() {
}

var extractCmd = &cobra.Command{
Args: cobra.ExactArgs(3),
Use: "extract",
Short: "Extract data file embedded in the crc executable",
Long: `Extract a data file which is embedded in the crc executable`,
Expand All @@ -22,9 +23,6 @@ var extractCmd = &cobra.Command{
}

func runExtract(args []string) {
if len(args) != 3 {
logging.Fatalf("extract takes exactly three arguments")
}
executablePath := args[0]
embedName := args[1]
destFile := args[2]
Expand Down
4 changes: 1 addition & 3 deletions cmd/crc-embedder/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func init() {
}

var listCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Use: "list",
Short: "List data files embedded in the crc executable",
Long: `List all the data files which were embedded in the crc executable`,
Expand All @@ -22,9 +23,6 @@ var listCmd = &cobra.Command{
}

func runList(args []string) {
if len(args) != 1 {
logging.Fatalf("list takes exactly one argument")
}
executablePath := args[0]
extractor, err := binappend.MakeExtractor(executablePath)
if err != nil {
Expand Down

0 comments on commit 9c730a6

Please sign in to comment.