-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modifying runOptions so each option is an element in a list to comply…
… with standard patterns Signed-off-by: Michael Shitrit <[email protected]>
- Loading branch information
Showing
2 changed files
with
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package command | ||
|
||
import corev1 "k8s.io/api/core/v1" | ||
|
||
type optionType int | ||
|
||
const ( | ||
useCustomizedPod optionType = iota | ||
noOutputExpected | ||
) | ||
|
||
type RunOption interface { | ||
getOptionType() optionType | ||
getOptionValue() interface{} | ||
} | ||
|
||
type runOption struct { | ||
optionType | ||
value interface{} | ||
} | ||
|
||
func (ro *runOption) getOptionType() optionType { | ||
return ro.optionType | ||
} | ||
|
||
func (ro *runOption) getOptionValue() interface{} { | ||
return ro.value | ||
} | ||
|
||
func CreateOptionUseCustomizedExecutePod(pod *corev1.Pod) RunOption { | ||
return &runOption{useCustomizedPod, pod} | ||
} | ||
|
||
func CreateOptionNoExpectedOutput() RunOption { | ||
return &runOption{optionType: noOutputExpected} | ||
} | ||
|
||
func convertToMap(opts []RunOption) map[optionType]interface{} { | ||
runOptions := make(map[optionType]interface{}) | ||
for _, option := range opts { | ||
runOptions[option.getOptionType()] = option.getOptionValue() | ||
} | ||
|
||
return runOptions | ||
} |