-
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.
#44: Commands for package management
- Loading branch information
1 parent
60f7dd0
commit 76c0d34
Showing
9 changed files
with
761 additions
and
30 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
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 compose | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// EnumValue struct to hold enumeration. | ||
type EnumValue struct { | ||
Enum []string | ||
defaultValue string | ||
value *string | ||
} | ||
|
||
// Set sets EnumValue. | ||
func (e *EnumValue) Set(value string) error { | ||
for _, allowed := range e.Enum { | ||
if value == allowed { | ||
*e.value = value | ||
return nil | ||
} | ||
} | ||
return fmt.Errorf("expected one of %v, got '%s'", e.Enum, value) | ||
} | ||
|
||
// Type returns a string name for this EnumValue type | ||
func (e *EnumValue) Type() string { | ||
return "string" | ||
} | ||
|
||
func (e *EnumValue) String() string { | ||
return *e.value | ||
} | ||
|
||
// EnumVarP adds custom enum flag to cobra command. | ||
func EnumVarP(cmd *cobra.Command, value *string, name, shorthand string, defaultValue string, enumValues []string, usage string) { | ||
ev := &EnumValue{ | ||
Enum: enumValues, | ||
defaultValue: defaultValue, | ||
value: value, | ||
} | ||
|
||
*ev.value = ev.defaultValue | ||
cmd.Flags().VarP(ev, name, shorthand, usage) | ||
} |
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
Oops, something went wrong.