Skip to content

feat: interactive CLI prompts for missing environment variables#1610

Open
nikhilsinhaparseable wants to merge 2 commits intoparseablehq:mainfrom
nikhilsinhaparseable:cli-interactive
Open

feat: interactive CLI prompts for missing environment variables#1610
nikhilsinhaparseable wants to merge 2 commits intoparseablehq:mainfrom
nikhilsinhaparseable:cli-interactive

Conversation

@nikhilsinhaparseable
Copy link
Copy Markdown
Contributor

@nikhilsinhaparseable nikhilsinhaparseable commented Apr 2, 2026

Instead of failing with a cryptic clap error when required env vars are
missing, the server now detects the storage subcommand and interactively
prompts the user for each missing value. This covers:

  • Storage-specific envs (S3, Azure Blob, GCS)
  • TLS cert/key pair (detects partial config that would silently fall back to HTTP)
  • OIDC group (detects partial config where setting one var activates the whole group)
  • Kafka bootstrap servers, topics, and security credentials (feature-gated)

Collected values are persisted to .parseable.env only after clap
validation succeeds, so invalid entries are never saved. On subsequent
startups, the file is auto-loaded (explicit env vars take precedence).
The file is also source-able for shell-wide use.

Interactive mode only activates when stdin is a terminal — non-interactive
environments (Docker, CI) get the standard clap error as before. Secret
fields (S3 secret key, SASL password, etc.) use hidden input via crossterm
raw mode.

Summary by CodeRabbit

  • New Features
    • Interactive environment-variable setup that auto-detects the chosen storage backend (S3, Blob, GCS, Local) and prompts for missing values, including conditional groups for TLS, OIDC, and Kafka.
    • Secret inputs are entered masked in terminal; prompts require non-empty input for required vars and allow skipping optional ones.
    • Collected values are persisted to a dotfile with a printed "source" hint and a best-effort to restrict file permissions; persistence only occurs after successful CLI validation.

 Instead of failing with a cryptic clap error when required env vars are
  missing, the server now detects the storage subcommand and interactively
  prompts the user for each missing value. This covers:

  - Storage-specific envs (S3, Azure Blob, GCS)
  - TLS cert/key pair (detects partial config that would silently fall back to HTTP)
  - OIDC group (detects partial config where setting one var activates the whole group)
  - Kafka bootstrap servers, topics, and security credentials (feature-gated)

  Collected values are persisted to `.parseable.env` only after clap
  validation succeeds, so invalid entries are never saved. On subsequent
  startups, the file is auto-loaded (explicit env vars take precedence).
  The file is also `source`-able for shell-wide use.

  Interactive mode only activates when stdin is a terminal — non-interactive
  environments (Docker, CI) get the standard clap error as before. Secret
  fields (S3 secret key, SASL password, etc.) use hidden input via crossterm
  raw mode.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b5449996-e0a7-4f34-b5b0-b68f64b16da0

📥 Commits

Reviewing files that changed from the base of the PR and between 99a430b and fcc06e8.

📒 Files selected for processing (1)
  • src/interactive.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/interactive.rs

Walkthrough

Adds an interactive env-var collection module invoked before CLI parsing that detects the storage subcommand, loads persisted values from .parseable.env, interactively prompts for missing required/optional variables (with hidden input for secrets), and can persist newly collected values back to .parseable.env.

Changes

Cohort / File(s) Summary
Interactive Module
src/interactive.rs
New module providing prompt_missing_envs() to detect storage subcommand, load/parse .parseable.env, build conditional prompt sets (storage, TLS, OIDC, optional Kafka feature), interactively collect missing vars (hidden input for secrets, Ctrl+C/exit handling), and save_collected_envs() to append safe export KEY='VALUE' lines and attempt 0600 perms.
Module Registration
src/lib.rs
Adds mod interactive; to include the new module in the crate.
CLI Init & PARSEABLE
src/parseable/mod.rs
Modifies PARSEABLE initializer to call prompt_missing_envs() before argument parsing, switches from Cli::parse() to Cli::try_parse() with explicit Ok/Err handling, and calls save_collected_envs() only after successful parse; then matches on cli.storage to construct Parseable as before.

Sequence Diagram

sequenceDiagram
    actor User
    participant PARSEABLE as PARSEABLE<br/>Initializer
    participant Interactive as Interactive<br/>Module
    participant Parser as CLI Parser<br/>(clap)
    participant FS as File System<br/>(.parseable.env)

    User->>PARSEABLE: start
    PARSEABLE->>Interactive: prompt_missing_envs()
    Interactive->>Interactive: detect storage subcommand
    Interactive->>FS: read .parseable.env
    FS-->>Interactive: returned env vars
    Interactive->>Interactive: build prompt set (storage, TLS, OIDC, Kafka?)
    alt interactive tty and missing required vars
        Interactive->>User: prompt for values (hidden for secrets)
        User-->>Interactive: provided values
    end
    Interactive-->>PARSEABLE: return collected (key,value)*
    PARSEABLE->>Parser: Cli::try_parse()
    alt parse ok
        Parser-->>PARSEABLE: Ok(cli)
        PARSEABLE->>FS: save_collected_envs(collected)
        FS-->>User: print saved path + source instruction
        PARSEABLE->>PARSEABLE: initialize Parseable from cli.storage
    else parse err
        Parser-->>PARSEABLE: Err(error)
        PARSEABLE->>User: exit with clap error
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 sniffing the air
I found the vars that hid away,
I asked them kindly, saved their say,
Secrets tucked with quiet care,
.parseable.env safe and fair,
A rabbit's nudge — now all set to play.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is comprehensive and well-structured, covering the goal, key changes, and rationale. However, it lacks explicit checkboxes for testing, documentation, and code comments as required by the template. Add the template checklist items and confirm testing was done, documentation was added, and code comments explain the intent of complex sections.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding interactive CLI prompts for missing environment variables. It is specific, clear, and reflects the primary feature introduced in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@nitisht nitisht requested a review from parmesant April 2, 2026 07:27
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/interactive.rs`:
- Around line 49-77: Before detecting subcommands, short-circuit interactive
prompting when the user requested help/version: in prompt_missing_envs() (and
the other interactive setup block around the later code mentioned), inspect the
raw command-line arguments (std::env::args()) for help/version flags (e.g.,
"-h", "--help", "--version", "-V") or patterns like a subcommand followed by
"--help" and immediately return an empty Vec so clap can show its help/version
output; implement this check at the very start of prompt_missing_envs() (before
calling detect_storage_subcommand(), load_env_file(), or get_env_prompts()) and
mirror the same early-return logic in the other interactive setup code region
referenced.
- Around line 193-205: The loader (load_env_file) must reverse the shell-escape
that save_env_file emits for single quotes: after stripping outer single or
double quotes in the parsing logic around the block that trims value (and the
similar block at the other occurrence), detect and decode the shell-escaped
apostrophe sequence produced by save_env_file (the '\'' sequence) back into a
single quote character; in practice, after unwrapping surrounding quotes replace
the literal sequence '\'' (backslash-escaped single quote inside single quotes)
with "'" so values like pa'ss round-trip correctly, and apply the same decoding
in both places referenced (the current key/value parsing and the later
occurrence at the other location).
- Around line 141-150: The current save_collected_envs function panics on IO
failures via expect calls, turning a best-effort persistence into a hard startup
failure; change save_collected_envs to return a Result<(), Box<dyn
std::error::Error>> (or Result<(), std::io::Error>) and propagate errors from
save_env_file using the ? operator instead of unwrapping, then update all call
sites (e.g., where collected_envs is passed) to handle the Result by printing a
warning like eprintln!("Warning: could not persist interactive configuration:
{err}") when Err is returned so the process continues; apply the same change
pattern to the other similar persistence code block around the 213–267 region.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0b60667e-d236-4129-891a-58965830168f

📥 Commits

Reviewing files that changed from the base of the PR and between 187a4e6 and 99a430b.

📒 Files selected for processing (3)
  • src/interactive.rs
  • src/lib.rs
  • src/parseable/mod.rs

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.

1 participant