mygithub.libinneed.workers.dev/stackitcloud/stackit-cli
Advanced tools
| # Autocompletion | ||
| This guide describes how you can enable command autocompletion for the STACKIT CLI by leveraging the functionality provided the [Cobra](https://github.com/spf13/cobra) framework. | ||
| The process may vary depending on the type of shell you are using and your operating system (OS). | ||
| You will need to start a new shell for the setup to take effect. | ||
| ## bash | ||
| This process depends on the `bash-completion` package. If you don't have it installed already, you can install it via your OS's package manager. | ||
| #### Linux | ||
| ```shell | ||
| stackit completion bash > ~/.bash_completion | ||
| ``` | ||
| #### macOS | ||
| ```shell | ||
| stackit completion bash > $(brew --prefix)/etc/bash_completion.d/stackit | ||
| ``` | ||
| ## zsh | ||
| If shell completion is not already enabled in your environment you will need to enable it by executing the following once: | ||
| ```shell | ||
| echo "autoload -U compinit; compinit" >> ~/.zshrc | ||
| ``` | ||
| #### Linux | ||
| ```shell | ||
| stackit completion zsh > "${fpath[1]}/_stackit" | ||
| ``` | ||
| #### macOS | ||
| ```shell | ||
| stackit completion zsh > $(brew --prefix)/share/zsh/site-functions/_stackit | ||
| ``` | ||
| Additionaly, you might also need to run: | ||
| ```shell | ||
| source $(brew --prefix)/share/zsh/site-functions/_stackit >> ~/.zshrc | ||
| ``` | ||
| ## PowerShell | ||
| You can load completions for your current shell session by running: | ||
| ```shell | ||
| stackit completion powershell | Out-String | Invoke-Expression | ||
| ``` | ||
| To load completions for every new session, add the output of the above command to your PowerShell profile. | ||
| ## fish | ||
| ```shell | ||
| stackit completion fish > ~/.config/fish/completions/stackit.fish | ||
| ``` |
@@ -20,2 +20,4 @@ # STACKIT CLI release workflow. | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_TOKEN }} | ||
| steps: | ||
@@ -36,2 +38,4 @@ - uses: actions/checkout@v4 | ||
| passphrase: ${{ secrets.GPG_PASSPHRASE }} | ||
| - name: Install Snapcraft | ||
| uses: samuelmeuli/action-snapcraft@v2 | ||
| - name: Run GoReleaser | ||
@@ -43,2 +47,2 @@ uses: goreleaser/goreleaser-action@v5 | ||
| GITHUB_TOKEN: ${{ secrets.CLI_RELEASE }} | ||
| GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} | ||
| GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} |
+15
-1
@@ -81,2 +81,16 @@ before: | ||
| # Not setting it for now so we can publish prerelease tags | ||
| # skip_upload: auto | ||
| # skip_upload: auto | ||
| snapcrafts: | ||
| # IDs of the builds for which to create packages for | ||
| - builds: | ||
| - linux-builds | ||
| # The name of the snap | ||
| name: stackit-cli | ||
| # The canonical title of the application, displayed in the software | ||
| # centre graphical frontends | ||
| title: STACKIT CLI | ||
| publish: true | ||
| summary: A command-line interface to manage STACKIT resources. | ||
| description: "A command-line interface to manage STACKIT resources.\nThis CLI is in a BETA state. More services and functionality will be supported soon." | ||
| license: Apache-2.0 |
@@ -241,11 +241,4 @@ package create | ||
| // The number of replicas is enforced by the API according to the instance type | ||
| var replicas int64 | ||
| if *model.Type == "Single" { | ||
| replicas = 1 | ||
| } else if *model.Type == "Replica" { | ||
| replicas = 3 | ||
| } else if *model.Type == "Sharded" { | ||
| replicas = 9 | ||
| } else { | ||
| replicas, err := mongodbflexUtils.GetInstanceReplicas(*model.Type) | ||
| if err != nil { | ||
| return req, fmt.Errorf("invalid MongoDB Flex intance type: %w", err) | ||
@@ -252,0 +245,0 @@ } |
@@ -14,2 +14,3 @@ package describe | ||
| "stackit/internal/pkg/services/mongodbflex/client" | ||
| mongodbflexUtils "stackit/internal/pkg/services/mongodbflex/utils" | ||
| "stackit/internal/pkg/tables" | ||
@@ -95,2 +96,8 @@ "stackit/internal/pkg/utils" | ||
| instanceType, err := mongodbflexUtils.GetInstanceType(*instance.Replicas) | ||
| if err != nil { | ||
| // Should never happen | ||
| instanceType = "" | ||
| } | ||
| table := tables.NewTable() | ||
@@ -111,2 +118,6 @@ table.AddRow("ID", *instance.Id) | ||
| table.AddSeparator() | ||
| table.AddRow("TYPE", instanceType) | ||
| table.AddSeparator() | ||
| table.AddRow("REPLICAS", *instance.Replicas) | ||
| table.AddSeparator() | ||
| table.AddRow("CPU", *instance.Flavor.Cpu) | ||
@@ -116,3 +127,3 @@ table.AddSeparator() | ||
| table.AddSeparator() | ||
| err := table.Display(cmd) | ||
| err = table.Display(cmd) | ||
| if err != nil { | ||
@@ -119,0 +130,0 @@ return fmt.Errorf("render table: %w", err) |
@@ -12,2 +12,9 @@ package utils | ||
| // The number of replicas is enforced by the API according to the instance type | ||
| var instanceTypeToReplicas = map[string]int64{ | ||
| "Single": 1, | ||
| "Replica": 3, | ||
| "Sharded": 9, | ||
| } | ||
| func ValidateFlavorId(service, flavorId string, flavors *[]mongodbflex.HandlersInfraFlavor) error { | ||
@@ -86,1 +93,18 @@ for _, f := range *flavors { | ||
| } | ||
| func GetInstanceReplicas(instanceType string) (int64, error) { | ||
| numReplicas, ok := instanceTypeToReplicas[instanceType] | ||
| if !ok { | ||
| return 0, fmt.Errorf("invalid instance type: %v", instanceType) | ||
| } | ||
| return numReplicas, nil | ||
| } | ||
| func GetInstanceType(numReplicas int64) (string, error) { | ||
| for k, v := range instanceTypeToReplicas { | ||
| if v == numReplicas { | ||
| return k, nil | ||
| } | ||
| } | ||
| return "", fmt.Errorf("invalid number of replicas: %v", numReplicas) | ||
| } |
+7
-3
@@ -10,3 +10,3 @@ # STACKIT CLI (BETA) | ||
| Please refer to our [installation](./INSTALLATION.md) guide for instructions on how to install and get started using the STACKIT CLI. | ||
| Please refer to our [installation guide](./INSTALLATION.md) for instructions on how to install and get started using the STACKIT CLI. | ||
@@ -69,3 +69,3 @@ ## Usage | ||
| For more details on how to setup authentication using a service account, check our [Authentication guide](./AUTHENTICATION.md) | ||
| For more details on how to setup authentication using a service account, check our [authentication guide](./AUTHENTICATION.md). | ||
@@ -102,2 +102,6 @@ ## Configuration | ||
| ## Autocompletion | ||
| If you wish to setup command autocompletion in your shell for the STACKIT CLI, please refer to our [autocompletion guide](./AUTOCOMPLETION.md). | ||
| ## Reporting issues | ||
@@ -109,3 +113,3 @@ | ||
| Your contribution is welcome! For more details on how to contribute, refer to our [Contribution Guide](./CONTRIBUTION.md). | ||
| Your contribution is welcome! For more details on how to contribute, refer to our [contribution guide](./CONTRIBUTION.md). | ||
@@ -112,0 +116,0 @@ ## License |