-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move individual cli main.go's into commands subfolder * add fundamental cobra code * adapt main functions into cobra commands * update dependencies, readme and goreleaser * rewrite tests for cobra * set goreleaser to prerelease mode if the version in the tag is non-final * add version exception to argument count checking
- Loading branch information
1 parent
75a3760
commit 60e2957
Showing
36 changed files
with
2,208 additions
and
2,583 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
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,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func exactArgsWithVersionException(n int) cobra.PositionalArgs { | ||
return func(cmd *cobra.Command, args []string) error { | ||
version, _ := cmd.Flags().GetBool("version") | ||
if version { | ||
return nil | ||
} | ||
if len(args) != n { | ||
return fmt.Errorf("accepts %d arg(s), received %d", n, len(args)) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func minArgsWithVersionException(n int) cobra.PositionalArgs { | ||
return func(cmd *cobra.Command, args []string) error { | ||
version, _ := cmd.Flags().GetBool("version") | ||
if version { | ||
return nil | ||
} | ||
if len(args) < n { | ||
return fmt.Errorf("requires at least %d arg(s), only received %d", n, len(args)) | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func rangeArgsWithVersionException(min int, max int) cobra.PositionalArgs { | ||
return func(cmd *cobra.Command, args []string) error { | ||
version, _ := cmd.Flags().GetBool("version") | ||
if version { | ||
return nil | ||
} | ||
if len(args) < min || len(args) > max { | ||
return fmt.Errorf("accepts between %d and %d arg(s), received %d", min, max, len(args)) | ||
} | ||
return nil | ||
} | ||
} |
Oops, something went wrong.