Skip to content

update in oss to make enterprise cli interactive#1612

Merged
nikhilsinhaparseable merged 2 commits intoparseablehq:mainfrom
nikhilsinhaparseable:cli-interactive-change
Apr 4, 2026
Merged

update in oss to make enterprise cli interactive#1612
nikhilsinhaparseable merged 2 commits intoparseablehq:mainfrom
nikhilsinhaparseable:cli-interactive-change

Conversation

@nikhilsinhaparseable
Copy link
Copy Markdown
Contributor

@nikhilsinhaparseable nikhilsinhaparseable commented Apr 4, 2026

Summary by CodeRabbit

  • New Features

    • Interactive two-phase collection of enterprise environment settings, including license paths, cluster secret, and mode-specific prompts.
    • Server mode auto-detection from environment/arguments to tailor prompts.
  • Refactor

    • Simplified interactive prompt flow to remove duplicated logic and added helpers for prompt collection.
    • Ensured environment file is parsed at most once per process to avoid redundant loading.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 4, 2026

Walkthrough

Added enterprise environment-variable prompting with mode detection, a process-wide guard to parse .parseable.env only once, refactored interactive prompting into helpers, exposed interactive publicly, and added a public entry point prompt_enterprise_envs.

Changes

Cohort / File(s) Summary
Interactive Module Refactor & Enterprise Prompting
src/interactive.rs
Made load_env_file public and added ENV_FILE_LOADED: AtomicBool guard; refactored prompt_missing_envs into collect_prompts; added detect_mode, get_enterprise_base_prompts, get_enterprise_mode_prompts; introduced public prompt_enterprise_envs() returning collected (env,var) pairs (base then mode-specific).
Module Visibility
src/lib.rs
Changed module declaration from mod interactive; to pub mod interactive; to expose the interactive API publicly.

Sequence Diagram

sequenceDiagram
    actor User
    participant EnvFile as .parseable.env
    participant CLI as CLI Args
    participant Detect as Mode Detection
    participant Base as Base Prompts
    participant Mode as Mode-Specific Prompts
    participant Collector as collect_prompts

    User->>EnvFile: load_env_file()
    EnvFile-->>User: parsed envs (only once via ENV_FILE_LOADED)

    CLI->>Detect: read --mode / args
    EnvFile->>Detect: read P_MODE
    Detect-->>User: resolved mode (or unset)

    User->>Base: prompt_enterprise_envs()
    Base->>Collector: collect base prompts (license, P_CLUSTER_SECRET, maybe P_MODE)
    Collector-->>User: prompt questions
    User-->>Collector: responses
    Collector-->>Base: base env pairs

    Base->>Mode: get_enterprise_mode_prompts(resolved mode)
    Mode->>Collector: collect mode-specific prompts
    Collector-->>User: mode-specific questions
    User-->>Collector: responses
    Collector-->>Mode: mode-specific env pairs

    Mode-->>User: combined enterprise env pairs
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • parmesant
  • nitisht

Poem

🐇 I hopped through files and found the mode,

one parse, two phases, inputs in code.
Base then specific, prompts neatly spun,
secrets and paths gathered—task done! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, missing all required template sections including objective, description of changes, and testing/documentation checkboxes. Add a comprehensive description following the template: explain the goal, describe the changes made (env file parsing, prompt refactoring, enterprise env vars), and verify the testing and documentation checkboxes.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding interactive functionality to enterprise CLI in the OSS version.
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.

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: 2

🤖 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 530-537: detect_mode() can return None causing unwrap_or_default()
to produce an empty string and the header to read "  mode"; change the fallback
to a descriptive string (e.g., "default" or "unknown") so the call becomes
detect_mode().unwrap_or("default".to_string()) (or equivalent) and then pass
that into collect_prompts(&mode_prompts, is_interactive, &format!("{mode}
mode"), &mut collected) so the printed header is meaningful when no mode is
detected.
- Around line 253-264: The CLI parsing in detect_mode() returns Some("all") for
"--mode all" whereas the env var branch normalizes "all" to None; update the CLI
arg handling in detect_mode() (the loop over std::env::args()) to mirror the env
var logic by mapping any value that equals "all" (case-insensitive) to None
instead of Some("all") so detect_mode() returns None for both env and CLI "all"
inputs, ensuring get_enterprise_base_prompts() sees is_none() consistently.
🪄 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: 8b877fc3-5336-4759-a255-4cb424a988b4

📥 Commits

Reviewing files that changed from the base of the PR and between 8ab9f6b and 10f5046.

📒 Files selected for processing (2)
  • src/interactive.rs
  • src/lib.rs

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.

♻️ Duplicate comments (1)
src/interactive.rs (1)

246-264: ⚠️ Potential issue | 🟠 Major

CLI --mode is ignored when P_MODE is set.

At Line 247, detect_mode() returns from P_MODE before evaluating CLI args (Lines 255-264). An explicit CLI mode can’t override env-derived mode, which can drive the wrong enterprise prompt set.

🐛 Proposed fix
 fn detect_mode() -> Option<String> {
-    if let Ok(mode) = std::env::var(MODE_ENV) {
-        let mode = mode.to_lowercase();
-        if mode != "all" {
-            return Some(mode);
-        }
-        return None;
-    }
-
     let args: Vec<String> = std::env::args().collect();
     for (i, arg) in args.iter().enumerate() {
         let value = if arg == "--mode" {
             args.get(i + 1).map(|v| v.to_lowercase())
         } else {
             arg.strip_prefix("--mode=").map(|v| v.to_lowercase())
         };
         if let Some(mode) = value {
             return (mode != "all").then_some(mode);
         }
     }
 
-    None
+    if let Ok(mode) = std::env::var(MODE_ENV) {
+        let mode = mode.to_lowercase();
+        return (mode != "all").then_some(mode);
+    }
+
+    None
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/interactive.rs` around lines 246 - 264, detect_mode currently returns
immediately when MODE_ENV is set, preventing CLI "--mode" from overriding it;
change the logic in detect_mode so it parses CLI args first (inspect
std::env::args for "--mode" and "--mode=...") and if a mode is found return that
(return (mode != "all").then_some(mode)), otherwise fall back to reading
std::env::var(MODE_ENV) and return that (again treating "all" as None). Refer to
the detect_mode function, the MODE_ENV check using std::env::var, and the CLI
parsing branch that looks for "--mode" / "--mode=" to implement the
reorder/fallback behavior.
🧹 Nitpick comments (1)
src/interactive.rs (1)

120-123: Use std::sync::Once instead of AtomicBool::swap(true, Relaxed) for one-time env file loading.

The current implementation calls swap(true) before file parsing completes (line 121 before lines 124+), creating a race condition: concurrent callers could return early before env vars are populated. Once provides the correct "initialize exactly once and wait until done" semantics. While load_env_file() is currently only called during single-threaded startup, using Once would make the code robust against future concurrent usage.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/interactive.rs` around lines 120 - 123, Replace the current atomic-flag
pattern in load_env_file (which uses ENV_FILE_LOADED.swap(true,
Ordering::Relaxed)) with a std::sync::Once to guarantee waiting until
initialization completes; specifically, introduce a Once (e.g., static
ENV_FILE_ONCE: Once = Once::new()) and call ENV_FILE_ONCE.call_once(|| { /*
existing env-file parsing and setting logic moved here */ }), removing the swap
and early return so concurrent callers block until the call_once closure
finishes, preserving the existing parsing behavior but with correct one-time
initialization semantics.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/interactive.rs`:
- Around line 246-264: detect_mode currently returns immediately when MODE_ENV
is set, preventing CLI "--mode" from overriding it; change the logic in
detect_mode so it parses CLI args first (inspect std::env::args for "--mode" and
"--mode=...") and if a mode is found return that (return (mode !=
"all").then_some(mode)), otherwise fall back to reading std::env::var(MODE_ENV)
and return that (again treating "all" as None). Refer to the detect_mode
function, the MODE_ENV check using std::env::var, and the CLI parsing branch
that looks for "--mode" / "--mode=" to implement the reorder/fallback behavior.

---

Nitpick comments:
In `@src/interactive.rs`:
- Around line 120-123: Replace the current atomic-flag pattern in load_env_file
(which uses ENV_FILE_LOADED.swap(true, Ordering::Relaxed)) with a
std::sync::Once to guarantee waiting until initialization completes;
specifically, introduce a Once (e.g., static ENV_FILE_ONCE: Once = Once::new())
and call ENV_FILE_ONCE.call_once(|| { /* existing env-file parsing and setting
logic moved here */ }), removing the swap and early return so concurrent callers
block until the call_once closure finishes, preserving the existing parsing
behavior but with correct one-time initialization semantics.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fa497294-c6f0-42e6-98b4-4aae30e26f1a

📥 Commits

Reviewing files that changed from the base of the PR and between 10f5046 and 655cae2.

📒 Files selected for processing (1)
  • src/interactive.rs

@nikhilsinhaparseable nikhilsinhaparseable merged commit 79656f6 into parseablehq:main Apr 4, 2026
12 checks passed
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