diff --git a/src/gh_cmd.rs b/src/gh_cmd.rs index 08aa9837..dc8b5890 100644 --- a/src/gh_cmd.rs +++ b/src/gh_cmd.rs @@ -128,7 +128,9 @@ fn extract_identifier_and_extra_args(args: &[String]) -> Option<(String, Vec bool { } fn view_run(args: &[String], _verbose: u8) -> Result<()> { + // Pass through before extracting a positional run ID so flag-only forms like + // `gh run view --log-failed --job ` keep their original argument order. + if should_passthrough_run_view(args) { + return run_passthrough_with_extra("gh", &["run", "view"], args); + } + let (run_id, extra_args) = match extract_identifier_and_extra_args(args) { Some(result) => result, None => return Err(anyhow::anyhow!("Run ID required")), }; - // Pass through when user requests logs or JSON — the filter would strip them - if should_passthrough_run_view(&extra_args) { - return run_passthrough_with_extra("gh", &["run", "view", &run_id], &extra_args); - } - let timer = tracking::TimedExecution::start(); let mut cmd = Command::new("gh"); @@ -1399,6 +1402,20 @@ mod tests { assert_eq!(extra, vec!["--web"]); } + #[test] + fn test_extract_identifier_skips_short_job_flag_value() { + let args: Vec = vec!["-j".into(), "123456789".into(), "--log-failed".into()]; + assert!(extract_identifier_and_extra_args(&args).is_none()); + } + + #[test] + fn test_extract_identifier_short_attempt_flag_before_identifier() { + let args: Vec = vec!["-a".into(), "2".into(), "123456789".into()]; + let (id, extra) = extract_identifier_and_extra_args(&args).unwrap(); + assert_eq!(id, "123456789"); + assert_eq!(extra, vec!["-a", "2"]); + } + #[test] fn test_run_view_passthrough_log_failed() { assert!(should_passthrough_run_view(&["--log-failed".into()])); @@ -1468,6 +1485,14 @@ mod tests { assert_eq!(extra, vec!["--attempt", "3"]); } + #[test] + fn test_extract_identifier_with_short_job_flag_before() { + let args: Vec = vec!["-j".into(), "67890".into(), "12345".into()]; + let (id, extra) = extract_identifier_and_extra_args(&args).unwrap(); + assert_eq!(id, "12345"); + assert_eq!(extra, vec!["-j", "67890"]); + } + // --- should_passthrough_pr_view tests --- #[test]