-
Notifications
You must be signed in to change notification settings - Fork 29
Add stackit git commands: list, describe, create and delete. #725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
67d5569
Add stackit git commands: list, describe, create and delete.
peremanent 61b9c73
Stop using new variables for the globalflags.ProjectIdFlag and Docs g…
peremanent d368ead
Merge branch 'stackitcloud:main' into main
peremanent 9399e8b
Stackit git: add vertical table on describe and limit list command
peremanent c10e7bd
Merge with upstream and modify stackit git commands to use new params…
peremanent ab6005e
Merge with upstream and modify stackit git commands to use new params…
peremanent 9ad9ef4
Delete toolchain opetion from go.mod file
peremanent fb1c1a6
Get go.mod and go.sum from main
peremanent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,37 @@ | ||
| ## stackit git | ||
|
|
||
| Provides functionality for STACKIT Git | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Provides functionality for STACKIT Git. | ||
|
|
||
| ``` | ||
| stackit git [flags] | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Help for "stackit git" | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| -y, --assume-yes If set, skips all confirmation prompts | ||
| --async If set, runs the command asynchronously | ||
| -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] | ||
| -p, --project-id string Project ID | ||
| --region string Target region for region-specific requests | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit](./stackit.md) - Manage STACKIT resources using the command line | ||
| * [stackit git create](./stackit_git_create.md) - Creates STACKIT Git instance | ||
| * [stackit git delete](./stackit_git_delete.md) - Deletes STACKIT Git instance | ||
| * [stackit git describe](./stackit_git_describe.md) - Describes STACKIT Git instance | ||
| * [stackit git list](./stackit_git_list.md) - Lists all instances of STACKIT Git. | ||
|
|
This file contains hidden or 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,41 @@ | ||
| ## stackit git create | ||
|
|
||
| Creates STACKIT Git instance | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Create an STACKIT Git instance by name. | ||
|
|
||
| ``` | ||
| stackit git create [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| Create an instance with name 'my-new-instance' | ||
| $ stackit git create --name my-new-instance | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Help for "stackit git create" | ||
| --name string The name of the instance. | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| -y, --assume-yes If set, skips all confirmation prompts | ||
| --async If set, runs the command asynchronously | ||
| -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] | ||
| -p, --project-id string Project ID | ||
| --region string Target region for region-specific requests | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit git](./stackit_git.md) - Provides functionality for STACKIT Git | ||
|
|
This file contains hidden or 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,40 @@ | ||
| ## stackit git delete | ||
|
|
||
| Deletes STACKIT Git instance | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Deletes an STACKIT Git instance by its internal ID. | ||
|
|
||
| ``` | ||
| stackit git delete INSTANCE_ID [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| Delete an instance with ID "xxx" | ||
| $ stackit git delete xxx | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Help for "stackit git delete" | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| -y, --assume-yes If set, skips all confirmation prompts | ||
| --async If set, runs the command asynchronously | ||
| -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] | ||
| -p, --project-id string Project ID | ||
| --region string Target region for region-specific requests | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit git](./stackit_git.md) - Provides functionality for STACKIT Git | ||
|
|
This file contains hidden or 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,40 @@ | ||
| ## stackit git describe | ||
|
|
||
| Describes STACKIT Git instance | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Describes an STACKIT Git instance by its internal ID. | ||
|
|
||
| ``` | ||
| stackit git describe INSTANCE_ID [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| Describe instance "xxx" | ||
| $ stackit git describe xxx | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Help for "stackit git describe" | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| -y, --assume-yes If set, skips all confirmation prompts | ||
| --async If set, runs the command asynchronously | ||
| -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] | ||
| -p, --project-id string Project ID | ||
| --region string Target region for region-specific requests | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit git](./stackit_git.md) - Provides functionality for STACKIT Git | ||
|
|
This file contains hidden or 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,40 @@ | ||
| ## stackit git list | ||
|
|
||
| Lists all instances of STACKIT Git. | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Lists all instances of STACKIT Git for the current project. | ||
|
|
||
| ``` | ||
| stackit git list [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| List all STACKIT Git instances | ||
| $ stackit git instance list | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Help for "stackit git list" | ||
| ``` | ||
|
|
||
| ### Options inherited from parent commands | ||
|
|
||
| ``` | ||
| -y, --assume-yes If set, skips all confirmation prompts | ||
| --async If set, runs the command asynchronously | ||
| -o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"] | ||
| -p, --project-id string Project ID | ||
| --region string Target region for region-specific requests | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit git](./stackit_git.md) - Provides functionality for STACKIT Git | ||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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,165 @@ | ||
| package create | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "github.com/goccy/go-yaml" | ||
| "github.com/spf13/cobra" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/args" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/errors" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/examples" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/flags" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/print" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/services/git/client" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/utils" | ||
| "github.com/stackitcloud/stackit-sdk-go/services/git" | ||
| "github.com/stackitcloud/stackit-sdk-go/services/git/wait" | ||
| ) | ||
|
|
||
| const ( | ||
| nameFlag = "name" | ||
| ) | ||
|
|
||
| type inputModel struct { | ||
| *globalflags.GlobalFlagModel | ||
| Id *string | ||
| Name string | ||
| } | ||
|
|
||
| func NewCmd(p *print.Printer) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "create", | ||
| Short: "Creates STACKIT Git instance", | ||
| Long: "Create an STACKIT Git instance by name.", | ||
| Args: args.NoArgs, | ||
| Example: examples.Build( | ||
| examples.NewExample( | ||
| `Create an instance with name 'my-new-instance'`, | ||
| `$ stackit git create --name my-new-instance`, | ||
| ), | ||
| ), | ||
| RunE: func(cmd *cobra.Command, _ []string) (err error) { | ||
| ctx := context.Background() | ||
| model, err := parseInput(p, cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Configure API client | ||
| apiClient, err := client.ConfigureClient(p) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if !model.AssumeYes { | ||
| prompt := fmt.Sprintf("Are you sure you want to create the instance %q?", model.Name) | ||
| err = p.PromptForConfirmation(prompt) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| // Call API | ||
| request := buildRequest(ctx, model, apiClient) | ||
|
|
||
| result, err := request.Execute() | ||
| if err != nil { | ||
| return fmt.Errorf("create stackit git instance: %w", err) | ||
| } | ||
| model.Id = result.Id | ||
|
|
||
| // Wait for async operation, if async mode not enabled | ||
| if !model.Async { | ||
| s := spinner.New(p) | ||
| s.Start("Creating stackit git instance") | ||
| _, err = wait.CreateGitInstanceWaitHandler(ctx, apiClient, model.ProjectId, *model.Id).WaitWithContext(ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("wait for stackit git Instance creation: %w", err) | ||
| } | ||
| s.Stop() | ||
| } | ||
|
|
||
| return outputResult(p, model, result) | ||
| }, | ||
| } | ||
|
|
||
| configureFlags(cmd) | ||
| return cmd | ||
| } | ||
|
|
||
| func configureFlags(cmd *cobra.Command) { | ||
| cmd.Flags().String(nameFlag, "", "The name of the instance.") | ||
| if err := flags.MarkFlagsRequired(cmd, nameFlag); err != nil { | ||
| cobra.CheckErr(err) | ||
| } | ||
| } | ||
|
|
||
| func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) { | ||
| globalFlags := globalflags.Parse(p, cmd) | ||
|
|
||
| if globalFlags.ProjectId == "" { | ||
| return nil, &errors.ProjectIdError{} | ||
| } | ||
| name := flags.FlagToStringValue(p, cmd, nameFlag) | ||
|
|
||
| model := inputModel{ | ||
| GlobalFlagModel: globalFlags, | ||
| Name: name, | ||
| } | ||
|
|
||
| if p.IsVerbosityDebug() { | ||
| modelStr, err := print.BuildDebugStrFromInputModel(model) | ||
| if err != nil { | ||
| p.Debug(print.ErrorLevel, "convert model to string for debugging: %v", err) | ||
| } else { | ||
| p.Debug(print.DebugLevel, "parsed input values: %s", modelStr) | ||
| } | ||
| } | ||
|
|
||
| return &model, nil | ||
| } | ||
|
|
||
| func buildRequest(ctx context.Context, model *inputModel, apiClient *git.APIClient) git.ApiCreateInstanceRequest { | ||
| return apiClient.CreateInstance(ctx, model.ProjectId).CreateInstancePayload(createPayload(model)) | ||
| } | ||
|
|
||
| func createPayload(model *inputModel) git.CreateInstancePayload { | ||
| return git.CreateInstancePayload{ | ||
| Name: &model.Name, | ||
| } | ||
| } | ||
|
|
||
| func outputResult(p *print.Printer, model *inputModel, resp *git.Instance) error { | ||
| if model == nil { | ||
| return fmt.Errorf("input model is nil") | ||
| } | ||
| var outputFormat string | ||
| if model.GlobalFlagModel != nil { | ||
| outputFormat = model.OutputFormat | ||
| } | ||
| switch outputFormat { | ||
| case print.JSONOutputFormat: | ||
| details, err := json.MarshalIndent(resp, "", " ") | ||
| if err != nil { | ||
| return fmt.Errorf("marshal instance: %w", err) | ||
| } | ||
| p.Outputln(string(details)) | ||
|
|
||
| return nil | ||
| case print.YAMLOutputFormat: | ||
| details, err := yaml.MarshalWithOptions(resp, yaml.IndentSequence(true), yaml.UseJSONMarshaler()) | ||
| if err != nil { | ||
| return fmt.Errorf("marshal iminstanceage: %w", err) | ||
| } | ||
| p.Outputln(string(details)) | ||
|
|
||
| return nil | ||
| default: | ||
| p.Outputf("Created instance %q with id %s\n", model.Name, utils.PtrString(model.Id)) | ||
| return nil | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.