-
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.
Merge pull request #64 from bunnyshell/environ-groups
Environ groups
- Loading branch information
Showing
19 changed files
with
680 additions
and
7 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,81 @@ | ||
package action | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"bunnyshell.com/cli/pkg/api/variable_group" | ||
"bunnyshell.com/cli/pkg/config" | ||
"bunnyshell.com/cli/pkg/lib" | ||
"bunnyshell.com/cli/pkg/util" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
options := config.GetOptions() | ||
settings := config.GetSettings() | ||
|
||
createOptions := variable_group.NewCreateOptions() | ||
|
||
command := &cobra.Command{ | ||
Use: "create", | ||
|
||
ValidArgsFunction: cobra.NoFileCompletions, | ||
|
||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
hasStdin, err := util.IsStdinPresent() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
flags := cmd.Flags() | ||
if !flags.Changed("value") && !hasStdin { | ||
return errMissingValue | ||
} | ||
|
||
if flags.Changed("value") && hasStdin { | ||
return errMultipleValueInputs | ||
} | ||
|
||
return nil | ||
}, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
createOptions.Environment = settings.Profile.Context.Environment | ||
|
||
hasStdin, err := util.IsStdinPresent() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if hasStdin { | ||
buf, err := io.ReadAll(os.Stdin) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
createOptions.Value = string(buf) | ||
} | ||
|
||
model, err := variable_group.Create(createOptions) | ||
if err != nil { | ||
return lib.FormatCommandError(cmd, err) | ||
} | ||
|
||
return lib.FormatCommandData(cmd, model) | ||
}, | ||
} | ||
|
||
flags := command.Flags() | ||
|
||
flags.AddFlag(options.Environment.AddFlagWithExtraHelp( | ||
"environment", | ||
"Environment for the variable", | ||
"Environments contain multiple variables", | ||
util.FlagRequired, | ||
)) | ||
|
||
createOptions.UpdateFlagSet(flags) | ||
|
||
mainCmd.AddCommand(command) | ||
} |
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,34 @@ | ||
package action | ||
|
||
import ( | ||
"bunnyshell.com/cli/pkg/api/variable_group" | ||
"bunnyshell.com/cli/pkg/lib" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
deleteOptions := variable_group.NewDeleteOptions() | ||
|
||
command := &cobra.Command{ | ||
Use: "delete", | ||
|
||
ValidArgsFunction: cobra.NoFileCompletions, | ||
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := variable_group.Delete(deleteOptions) | ||
if err != nil { | ||
return lib.FormatCommandError(cmd, err) | ||
} | ||
|
||
cmd.Printf("\nGrouped environment variable %s successfully deleted\n", deleteOptions.ID) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
flags := command.Flags() | ||
|
||
flags.AddFlag(GetIDOption(&deleteOptions.ID).GetRequiredFlag("id")) | ||
|
||
mainCmd.AddCommand(command) | ||
} |
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,70 @@ | ||
package action | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"bunnyshell.com/cli/pkg/api/variable_group" | ||
"bunnyshell.com/cli/pkg/lib" | ||
"bunnyshell.com/cli/pkg/util" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
editOptions := variable_group.NewEditOptions("") | ||
|
||
command := &cobra.Command{ | ||
Use: "edit", | ||
|
||
ValidArgsFunction: cobra.NoFileCompletions, | ||
|
||
PreRunE: func(cmd *cobra.Command, _ []string) error { | ||
hasStdin, err := util.IsStdinPresent() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
flags := cmd.Flags() | ||
if flags.Changed("value") && hasStdin { | ||
return errMultipleValueInputs | ||
} | ||
|
||
return nil | ||
}, | ||
|
||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
flags := cmd.Flags() | ||
if flags.Changed("value") { | ||
editOptions.EnvironItemEditAction.SetValue(flags.Lookup("value").Value.String()) | ||
} | ||
|
||
hasStdin, err := util.IsStdinPresent() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if hasStdin { | ||
buf, err := io.ReadAll(os.Stdin) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
editOptions.EnvironItemEditAction.SetValue(string(buf)) | ||
} | ||
|
||
model, err := variable_group.Edit(editOptions) | ||
if err != nil { | ||
return lib.FormatCommandError(cmd, err) | ||
} | ||
|
||
return lib.FormatCommandData(cmd, model) | ||
}, | ||
} | ||
|
||
flags := command.Flags() | ||
|
||
flags.AddFlag(GetIDOption(&editOptions.ID).GetRequiredFlag("id")) | ||
editOptions.UpdateFlagSet(flags) | ||
|
||
mainCmd.AddCommand(command) | ||
} |
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,34 @@ | ||
package action | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"bunnyshell.com/cli/pkg/build" | ||
"bunnyshell.com/cli/pkg/config/option" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
errMissingValue = errors.New("the plain value must be provided") | ||
errMultipleValueInputs = errors.New("the value must be provided either by argument or by stdin, not both") | ||
) | ||
|
||
var mainCmd = &cobra.Command{} | ||
|
||
func GetMainCommand() *cobra.Command { | ||
return mainCmd | ||
} | ||
|
||
func GetIDOption(value *string) *option.String { | ||
help := fmt.Sprintf( | ||
`Find available environment variables with "%s variables list"`, | ||
build.Name, | ||
) | ||
|
||
idOption := option.NewStringOption(value) | ||
|
||
idOption.AddFlagWithExtraHelp("id", "Environment Variable Id", help) | ||
|
||
return idOption | ||
} |
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,39 @@ | ||
package variable_group | ||
|
||
import ( | ||
"bunnyshell.com/cli/pkg/api/variable_group" | ||
"bunnyshell.com/cli/pkg/config" | ||
"bunnyshell.com/cli/pkg/lib" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
options := config.GetOptions() | ||
settings := config.GetSettings() | ||
|
||
listOptions := variable_group.NewListOptions() | ||
|
||
command := &cobra.Command{ | ||
Use: "list", | ||
|
||
ValidArgsFunction: cobra.NoFileCompletions, | ||
|
||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
listOptions.Organization = settings.Profile.Context.Organization | ||
listOptions.Environment = settings.Profile.Context.Environment | ||
|
||
return lib.ShowCollection(cmd, listOptions, func() (lib.ModelWithPagination, error) { | ||
return variable_group.List(listOptions) | ||
}) | ||
}, | ||
} | ||
|
||
flags := command.Flags() | ||
|
||
flags.AddFlag(options.Organization.GetFlag("organization")) | ||
flags.AddFlag(options.Environment.GetFlag("environment")) | ||
|
||
listOptions.UpdateFlagSet(flags) | ||
|
||
mainCmd.AddCommand(command) | ||
} |
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,33 @@ | ||
package variable_group | ||
|
||
import ( | ||
"bunnyshell.com/cli/cmd/variable_group/action" | ||
"bunnyshell.com/cli/pkg/config" | ||
"bunnyshell.com/cli/pkg/util" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var mainCmd = &cobra.Command{ | ||
Use: "variables-groups", | ||
Aliases: []string{"variables-group", "var-groups", "var-group", "var-g"}, | ||
|
||
Short: "Grouped Environment Variables", | ||
Long: "Bunnyshell Environment Variables in Groups", | ||
} | ||
|
||
func init() { | ||
config.MainManager.CommandWithAPI(mainCmd) | ||
|
||
util.AddGroupedCommands( | ||
mainCmd, | ||
cobra.Group{ | ||
ID: "actions", | ||
Title: "Commands for Environment Variables:", | ||
}, | ||
action.GetMainCommand().Commands(), | ||
) | ||
} | ||
|
||
func GetMainCommand() *cobra.Command { | ||
return mainCmd | ||
} |
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,33 @@ | ||
package variable_group | ||
|
||
import ( | ||
"bunnyshell.com/cli/cmd/variable/action" | ||
"bunnyshell.com/cli/pkg/api/variable_group" | ||
"bunnyshell.com/cli/pkg/lib" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
itemOptions := variable_group.NewItemOptions("") | ||
|
||
command := &cobra.Command{ | ||
Use: "show", | ||
|
||
ValidArgsFunction: cobra.NoFileCompletions, | ||
|
||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
model, err := variable_group.Get(itemOptions) | ||
if err != nil { | ||
return lib.FormatCommandError(cmd, err) | ||
} | ||
|
||
return lib.FormatCommandData(cmd, model) | ||
}, | ||
} | ||
|
||
flags := command.Flags() | ||
|
||
flags.AddFlag(action.GetIDOption(&itemOptions.ID).GetRequiredFlag("id")) | ||
|
||
mainCmd.AddCommand(command) | ||
} |
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
Oops, something went wrong.