feat: interactive CLI prompts for missing environment variables#1610
feat: interactive CLI prompts for missing environment variables#1610nikhilsinhaparseable wants to merge 2 commits intoparseablehq:mainfrom
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds an interactive env-var collection module invoked before CLI parsing that detects the storage subcommand, loads persisted values from Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
src/interactive.rssrc/lib.rssrc/parseable/mod.rs
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:
Collected values are persisted to
.parseable.envonly after clapvalidation 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