-
-
Notifications
You must be signed in to change notification settings - Fork 49
feat(spec): allow a mount at the top level #806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
7e04c4c
d67252d
9eb998b
1e79a08
29e81b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -351,7 +351,12 @@ impl<'a> Parser<'a> { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Returns the parsed arguments and flags, with defaults and env vars applied. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn parse(self, input: &[String]) -> Result<ParseOutput, miette::Error> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let custom_env = self.env.as_ref(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let (mut out, overridden_flags) = parse_partial_with_env(self.spec, input, custom_env)?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let (mut out, overridden_flags) = parse_partial_with_env( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.spec, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| custom_env, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MountTiming::WhenAWordIsUnknown, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trace!("{out:?}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let get_env = |key: &str| -> Option<String> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -539,14 +544,28 @@ pub fn parse(spec: &Spec, input: &[String]) -> Result<ParseOutput, miette::Error | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Use this for help text generation or when you need the raw parsed values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[must_use = "parsing result should be used"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn parse_partial(spec: &Spec, input: &[String]) -> Result<ParseOutput, miette::Error> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parse_partial_with_env(spec, input, None).map(|(out, _)| out) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parse_partial_with_env(spec, input, None, MountTiming::Eager).map(|(out, _)| out) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Internal version of parse_partial that accepts an optional custom env map. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// When a command's own `mount` runs, for the root — which nothing descends into. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// A completion has to know every command before it can offer one, even with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// nothing typed yet, so it resolves up front. An execution knows the word it was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// given, so it only pays for discovery when that word matches nothing declared — | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// and a CLI that declares its commands and mounts a few more does not spawn a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// process on every invocation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[derive(Clone, Copy, PartialEq, Eq)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enum MountTiming { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Eager, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WhenAWordIsUnknown, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn parse_partial_with_env( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| spec: &Spec, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input: &[String], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| custom_env: Option<&HashMap<String, String>>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mount_timing: MountTiming, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> Result<(ParseOutput, HashSet<String>), miette::Error> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trace!("parse_partial: {input:?}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut input = input.iter().cloned().collect::<VecDeque<_>>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -592,8 +611,44 @@ fn parse_partial_with_env( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Track whether we've already applied the default_subcommand to prevent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // multiple switches (e.g., if default is "run" and there's a task named "run") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut used_default_subcommand = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Whether the command in scope has had its own mounts run. A mount on the root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // is the case that needs this: a subcommand's mounts are run when the parser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // descends into it, but nothing descends into the root. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut mounts_resolved = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // A completion needs the whole command list before it can offer anything, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // `mycli <tab>` has no word to trigger discovery with — so waiting for one would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // mean a root mount never contributed to the very thing it exists for. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if mount_timing == MountTiming::Eager && !out.cmd.mounts.is_empty() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mounts_resolved = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut mounted = out.cmd.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mounted.mount(&[])?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| merge_subcommand_flags(&mut out.available_flags, gather_flags(&mounted), false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if let Some(last) = out.cmds.last_mut() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *last = mounted.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.cmd = mounted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eager mount before flag scanMedium Severity Root mounts now resolve at the start of every Additional Locations (1)Reviewed by Cursor Bugbot for commit 9eb998b. Configure here. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while idx < input.len() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Only for a word that could name a command, and only when it matches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // nothing already declared. A CLI that declares its commands and mounts more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // does not spawn a process for every invocation, and a flag — `--help`, or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // anything unrecognized — never triggers discovery at all, which it would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // otherwise do simply by not being a subcommand. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if !mounts_resolved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && !out.cmd.mounts.is_empty() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && !input[idx].starts_with('-') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && out.cmd.find_subcommand(&input[idx]).is_none() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
cursor[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mounts_resolved = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut mounted = out.cmd.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mounted.mount(&mount_prefix_words(&prefix_flags))?; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
greptile-apps[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| merge_subcommand_flags(&mut out.available_flags, gather_flags(&mounted), false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+651
to
+662
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Run only overriding mounts before default fallback.
When a default exists, execute only mounts with Proposed fix let mut mounted = out.cmd.clone();
+if spec.default_subcommand.is_some() {
+ mounted.mounts.retain(|mount| mount.overrides_default);
+}
mounted.mount(&mount_prefix_words(&prefix_flags))?;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if let Some(last) = out.cmds.last_mut() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *last = mounted.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.cmd = mounted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
cursor[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if let Some(subcommand) = out.cmd.find_subcommand(&input[idx]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut subcommand = subcommand.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Pass prefix words (global flags before this subcommand) to mount | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -610,6 +665,8 @@ fn parse_partial_with_env( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input.remove(idx); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.cmds.push(subcommand.clone()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.cmd = subcommand.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // A descent already ran the new command's mounts, above. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mounts_resolved = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
cursor[bot] marked this conversation as resolved.
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prefix_flags.clear(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Continue from current position (don't reset to 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // After remove(), idx now points to the next element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -670,6 +727,9 @@ fn parse_partial_with_env( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.cmds.push(subcommand.clone()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.cmd = subcommand.clone(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prefix_flags.clear(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This descent ran the new command's mounts, so lazy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // discovery must not run them a second time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mounts_resolved = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| used_default_subcommand = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Continue the loop to check if this word is a subcommand of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // default subcommand (e.g., a task name added via mount). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1524,6 +1584,99 @@ arg "[input]" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(first_string_value(&parsed), "input.txt"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[cfg(unix)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn a_mount_on_the_root_discovers_subcommands() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The root is a command like any other, so it can find its own subcommands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // by running something. Uses `echo` rather than a fixture because resolving | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // a mount is what is being tested. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let spec: Spec = r#" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name "ex" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bin "ex" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cmd "declared" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mount run="echo 'cmd \"discovered\"'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .parse() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let out = parse(&spec, &["ex".to_string(), "discovered".to_string()]).unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(out.cmd.name, "discovered"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[cfg(unix)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn completion_sees_root_mounted_commands_with_nothing_typed() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The case a root mount exists for. `mycli <tab>` has no word to trigger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // discovery with, so a completion has to resolve up front or the mounted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // commands are never offered. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let spec: Spec = r#" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name "ex" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bin "ex" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cmd "declared" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mount run="echo 'cmd \"discovered\"'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .parse() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let out = parse_partial(&spec, &["ex".to_string()]).unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert!( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.cmd.subcommands.contains_key("discovered"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "a completion should see mounted commands; got {:?}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| out.cmd.subcommands.keys().collect::<Vec<_>>() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[cfg(unix)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn a_flag_does_not_run_the_mount() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // A flag matches no subcommand, which would have been enough to trigger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // discovery — so `ex --help` spawned a process. The mount fails if it runs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // so parsing at all is the proof that it did not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let spec: Spec = r#" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name "ex" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bin "ex" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| flag "--verbose" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cmd "declared" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mount run="exit 1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .parse() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let out = parse(&spec, &["ex".to_string(), "--verbose".to_string()]).unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(out.cmd.name, "ex"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[cfg(unix)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn a_declared_subcommand_does_not_run_the_mount() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The mount would fail if it ran, so this parsing at all is the proof that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // discovery is skipped when the word is already known. Worth pinning: a root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // mount that resolved eagerly would spawn a process on every invocation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let spec: Spec = r#" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name "ex" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bin "ex" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cmd "declared" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mount run="exit 1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .parse() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let out = parse(&spec, &["ex".to_string(), "declared".to_string()]).unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(out.cmd.name, "declared"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn a_root_mount_survives_being_written_out() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let spec: Spec = "name \"ex\"\nbin \"ex\"\nmount run=\"ex plugins --usage\"\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .parse() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(spec.cmd.mounts.len(), 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let reparsed: Spec = spec.to_string().parse().unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(reparsed.cmd.mounts.len(), 1, "written:\n{spec}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(reparsed.cmd.mounts[0].run, "ex plugins --usage"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn test_mount_prefix_applies_flag_overrides() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let stdin = Arc::new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Forward root global flags during eager discovery.
parse_partialruns the root mount with&[]before Phase 1 collectsprefix_flags. Normal lazy discovery forwardsmount_prefix_words(&prefix_flags)at Line 652.If a root mount uses a declared global flag to select its emitted commands, completion returns commands for the default context instead of the selected context. Collect and forward declared root global flags before eager mounting. Add a completion regression test.
🤖 Prompt for AI Agents