Skip to content

feat(secret flag) add reusable secret flag implementation, update guide#1366

Merged
cgoetz-inovex merged 11 commits intomainfrom
feat/STACKITCLI-318_secret-flags-2
Apr 21, 2026
Merged

feat(secret flag) add reusable secret flag implementation, update guide#1366
cgoetz-inovex merged 11 commits intomainfrom
feat/STACKITCLI-318_secret-flags-2

Conversation

@cgoetz-inovex
Copy link
Copy Markdown
Contributor

Had to split implementation into two parts: Set() and SecretFlagToSP. Set is only called when an argument is specified on the command line. So moving the PromptForPassword logic into Set does not work.

I'm not sure if the current solution with a specialized *ToStringPointer func is the way to go. So I've only refactored obs-credentials add as an example.

Description

relates to #1234

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see e.g. here)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

…n tests

`print.Printer` had a reference to a `cobra.Command` for using its IO
streams. Each Command also used a Printer, resulting in an awkward
circular dependency.
Refactored Printer to use IO streams directly. When using the application
these are set in `main`, when used in tests these can be set to
`bytes.Buffer`s.
Also replaced usages of `os.Args` with just a string slice. Also set
in `main`.
`cobra.Command`s `Args` and IO-streams are set in `NewRootCmd` with
`traverseCommands`.
`CmdParams` also has an `fs.FS`, currently unused but will allow using
the real FS during regular use and an in-memory-FS during tests.

This change prepares the application for integrative testing while keeping
good isolation. Generally speaking the goal is to move all things with
side effects into main (compare with https://grafana.com/blog/how-i-write-http-services-in-go-after-13-years/#func-main-only-calls-run)
Had to split implementation into two parts: `Set()` and `SecretFlagToSP`.
Set is only called when an argument is specified on the command line.
So moving the `PromptForPassword` logic into `Set` does not work.

I'm not sure if the current solution with a specialized `*ToStringPointer`
func is the way to go. So I've only refactored `obs-credentials add`
as an example.
@cgoetz-inovex cgoetz-inovex requested a review from a team as a code owner April 14, 2026 13:39
Base automatically changed from feat/STACKITCLI-318_secret-flags to main April 15, 2026 10:54
Comment thread internal/pkg/flags/secret.go Outdated
marceljk
marceljk previously approved these changes Apr 21, 2026
Comment thread internal/pkg/flags/secret_test.go
@github-actions
Copy link
Copy Markdown

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/stackit-cli/.github/docs/contribution-guide 0.00% (ø)
github.com/stackitcloud/stackit-cli/internal/cmd/beta/alb/observability-credentials/add 54.05% (+1.28%) 👍
github.com/stackitcloud/stackit-cli/internal/pkg/flags 61.04% (+3.77%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/stackitcloud/stackit-cli/.github/docs/contribution-guide/cmd.go 0.00% (ø) 0 0 0
github.com/stackitcloud/stackit-cli/internal/cmd/beta/alb/observability-credentials/add/add.go 54.05% (+1.28%) 37 (+1) 20 (+1) 17 👍
github.com/stackitcloud/stackit-cli/internal/pkg/flags/secret.go 89.66% (+89.66%) 29 (+29) 26 (+26) 3 (+3) 🌟

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/stackitcloud/stackit-cli/internal/pkg/flags/secret_test.go

@cgoetz-inovex cgoetz-inovex merged commit f52c9ac into main Apr 21, 2026
3 checks passed
@cgoetz-inovex cgoetz-inovex deleted the feat/STACKITCLI-318_secret-flags-2 branch April 21, 2026 14:54
j1n-o9r pushed a commit to j1n-o9r/stackit-cli that referenced this pull request Apr 22, 2026
…de (stackitcloud#1366)

* refac(io) set IO once in main to allow overriding with in memory io in tests

`print.Printer` had a reference to a `cobra.Command` for using its IO
streams. Each Command also used a Printer, resulting in an awkward
circular dependency.
Refactored Printer to use IO streams directly. When using the application
these are set in `main`, when used in tests these can be set to
`bytes.Buffer`s.
Also replaced usages of `os.Args` with just a string slice. Also set
in `main`.
`cobra.Command`s `Args` and IO-streams are set in `NewRootCmd` with
`traverseCommands`.
`CmdParams` also has an `fs.FS`, currently unused but will allow using
the real FS during regular use and an in-memory-FS during tests.

This change prepares the application for integrative testing while keeping
good isolation. Generally speaking the goal is to move all things with
side effects into main (compare with https://grafana.com/blog/how-i-write-http-services-in-go-after-13-years/#func-main-only-calls-run)

* fix(fmt) run formatter

* fix(test) adapt cli args after changing arg slicing

* feat(secret flag) add reusable secret flag implementation, update guide

Had to split implementation into two parts: `Set()` and `SecretFlagToSP`.
Set is only called when an argument is specified on the command line.
So moving the `PromptForPassword` logic into `Set` does not work.

I'm not sure if the current solution with a specialized `*ToStringPointer`
func is the way to go. So I've only refactored `obs-credentials add`
as an example.

* fix(docs) generate docs

* fix(lint) fix linting errors

* fix(secretflag) use title case when printing flag usage

* fix(fmt) run formatter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants