-
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.
feat: add the possibility to trigger environment partial actions
Signed-off-by: Aris Buzachis <[email protected]>
- Loading branch information
1 parent
8c1b0e0
commit 08d5a59
Showing
8 changed files
with
113 additions
and
14 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
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,52 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/pflag" | ||
) | ||
|
||
const componentVarName = "component" | ||
|
||
type PartialActionOptions struct { | ||
ActionOptions | ||
|
||
components []string | ||
|
||
flags *pflag.FlagSet | ||
} | ||
|
||
func NewPartialActionOptions(id string) *PartialActionOptions { | ||
return &PartialActionOptions{ | ||
ActionOptions: *NewActionOptions(id), | ||
|
||
components: []string{}, | ||
} | ||
} | ||
|
||
func (pao *PartialActionOptions) UpdateFlagSet(flags *pflag.FlagSet) { | ||
pao.ActionOptions.UpdateFlagSet(flags) | ||
|
||
// We'll need this later to check if the flag was provided at all - in order to determine if it was a partial action or not. | ||
pao.flags = flags | ||
|
||
usage := fmt.Sprintf("Execute a partial action with the set components. Provide \"--%s ''\" for a no-components operation.", componentVarName) | ||
flags.StringArrayVar(&pao.components, componentVarName, pao.components, usage) | ||
} | ||
|
||
// Handle the "--component ”" case. | ||
func (pao *PartialActionOptions) GetActionComponents() []string { | ||
if len(pao.components) == 1 && pao.components[0] == "" { | ||
return []string{} | ||
} | ||
|
||
return pao.components | ||
} | ||
|
||
func (pao *PartialActionOptions) IsPartial() bool { | ||
if pao.flags == nil { | ||
return false | ||
} | ||
|
||
return pao.flags.Lookup(componentVarName).Changed | ||
} |
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