-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afccbbb
commit 7f66daf
Showing
20 changed files
with
1,914 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin/* | ||
*.code-workspace |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type tChoice struct { | ||
Allowed []string // Slice of allowed values | ||
Value string // Defaulted value | ||
} | ||
|
||
/* | ||
newChoice give a list of allowed flag parameters, where the second argument is the default | ||
'allowed' slice of allowed strings | ||
'defaulted' default string | ||
*/ | ||
func newChoice(allowed []string, defaulted string) *tChoice { | ||
return &tChoice{ | ||
Allowed: allowed, | ||
Value: defaulted, | ||
} | ||
} | ||
|
||
/* | ||
Set is called upon flag provisioning, validates its value | ||
'p' string to be put into the flag | ||
*/ | ||
func (a *tChoice) Set(p string) error { | ||
|
||
isIncluded := func(opts []string, val string) bool { | ||
for _, opt := range opts { | ||
if val == opt { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
if !isIncluded(a.Allowed, p) { | ||
return fmt.Errorf("%s is not included in {%s}", p, strings.Join(a.Allowed, "|")) | ||
} | ||
|
||
/* Set the value */ | ||
|
||
a.Value = p | ||
|
||
return nil | ||
} | ||
|
||
/* | ||
String returns flag value | ||
*/ | ||
func (a tChoice) String() string { | ||
return a.Value | ||
} | ||
|
||
/* | ||
Type returns text for help purposes | ||
*/ | ||
func (a *tChoice) Type() string { | ||
return fmt.Sprintf("{%s}", strings.Join(a.Allowed, "|")) | ||
} |
Oops, something went wrong.