opts guard and removing severity

This commit is contained in:
zach rice committed 2019-11-12 15:18:13 -05:00
1 parent e446ba0738
commit 315ee56024
17 files changed
+99 -121

No files matched your search

+27 -4
View File
@@ -63,8 +63,10 @@ func ParseOptions() (Options, error) {
_, err := parser.Parse()
if err != nil {
parser.WriteHelp(os.Stdout)
os.Exit(Success)
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type != flags.ErrHelp {
parser.WriteHelp(os.Stdout)
}
os.Exit(0)
}
if opts.Version {
@@ -83,11 +85,32 @@ func ParseOptions() (Options, error) {
// If invalid sets of options are present, a descriptive error will return
// else nil is returned
func (opts Options) Guard() error {
// 1. only one target option set at a time:
// repo, owner-path, repo-path
if !oneOrNoneSet(opts.Repo, opts.OwnerPath, opts.RepoPath, opts.Host) {
return fmt.Errorf("only one target option must can be set. target options: repo, owner-path, repo-path, host")
}
if !oneOrNoneSet(opts.Organization, opts.User, opts.PullRequest) {
return fmt.Errorf("only one target option must can be set. target options: repo, owner-path, repo-path, host")
}
if !oneOrNoneSet(opts.AccessToken, opts.Password) {
log.Warn("both access-token and password are set. Only password will be attempted")
}
return nil
}
func oneOrNoneSet(optStr ...string) bool {
c := 0
for _, s := range optStr {
if s != "" {
c++
}
}
if c <= 1 {
return true
}
return false
}
// CloneOptions returns a git.cloneOptions pointer. The authentication method
// is determined by what is passed in via command-Line options. If No
// Username/PW or AccessToken is available and the repo target is not using the