Skip to content

Interactive configuration prompt for osctrl-cli - #1067

Merged
javuto merged 1 commit into
developfrom
cli-prompt-parameters
Sep 25, 2026
Merged

javuto merged 1 commit into
developfrom
cli-prompt-parameters

Conversation

@javuto

@javuto javuto commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

osctrl-cli: Interactive Configuration Prompt

Problem Statement

Running osctrl-cli without a valid API configuration just failed:

  • Missing/unreadable --api-file (default osctrl-api.json) → hard LoadConfiguration error
  • Empty URL or token → CreateAPI failure

Nothing guided the operator to a working setup.

Changes

New: cmd/cli/api_prompt.go

  • missingAPIConfiguration — reports whether URL or token are still absent
  • promptMissingAPIConfiguration — asks only for what's missing:
    • URL: plain-text prompt, re-asks on empty input
    • Token: hidden input via term.ReadPassword, re-asks on empty
    • Values already resolved (flag, API_URL/API_TOKEN env, config file) are kept and not re-asked
  • Non-interactive stdin (pipes, scripts, CI) never blocks — fails with actionable guidance naming exactly what's missing and all supported sources (--api-file, --api-url/--api-token, env vars, or run interactively)

Wired: cmd/cli/main.go

  • cliWrapper API path — every API-backed command now falls back to the prompt
  • check-api — same fallback
  • Unreadable config file logs the reason in debug and falls through to prompting instead of aborting

Unchanged

  • login's own flow (only needs a URL, then mints its own token)
  • Explicit --db / DB-file paths

Behavior Example

$ osctrl-cli node list
No osctrl API configuration found. Please provide the connection details.
 -> API URL: https://osctrl.example.com
 -> API token: ********
...

Validation

Check Result
go build ./... ✅
go test ./cmd/cli/ ./pkg/apiclient/ ✅
golangci-lint ./cmd/cli/... ✅ 0 issues
gofmt ✅ clean

Tests Added

  • cmd/cli/api_prompt_test.go — completeness detection (URL/token/both/none) and non-interactive fallback errors (partial configs keep their values; error names what's missing)

@javuto javuto added ✨ enhancement New feature or request osctrl-cli osctrl-cli related changes labels Sep 25, 2026
@javuto
javuto merged commit 6740d35 into develop Sep 25, 2026
7 checks passed
@javuto
javuto deleted the cli-prompt-parameters branch September 25, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ enhancement New feature or request osctrl-cli osctrl-cli related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant