@@ -445,7 +445,24 @@ fn bearer_token(config: &Config) -> Result<SecretValue> { |
445 | 445 | // Verbs |
446 | 446 | // --------------------------------------------------------------------------- |
447 | 447 |
|
448 | | -fn verb_status(config: &Config) -> Result<Value> { |
| 448 | +const STATUS_USAGE: &str = "\ |
| 449 | +Usage: fleet dispatch status |
| 450 | +
|
| 451 | +GET /health on pm-dispatch: is the service up, and which build. |
| 452 | +Prints the service's health body plus the transport it arrived by. |
| 453 | +
|
| 454 | +Takes no arguments."; |
| 455 | + |
| 456 | +fn verb_status(config: &Config, args: &[String]) -> Result<Value> { |
| 457 | + if args.iter().any(|a| a == "--help" || a == "-h") { |
| 458 | + println!("{STATUS_USAGE}"); |
| 459 | + return Ok(Value::Null); |
| 460 | + } |
| 461 | + if let Some(arg) = args.first() { |
| 462 | + return Err(usage(format!( |
| 463 | + "status takes no arguments, got {arg:?}\n\n{STATUS_USAGE}" |
| 464 | + ))); |
| 465 | + } |
449 | 466 | let transport_sel = pick_transport(config)?; |
450 | 467 | let described = transport_sel.describe(); |
451 | 468 | let body = finish( |
@@ -736,7 +753,7 @@ pub fn run(config: &Config, args: &[String]) -> i32 { |
736 | 753 | let verb = args.first().map(|s| s.as_str()); |
737 | 754 | let rest = if args.is_empty() { &[][..] } else { &args[1..] }; |
738 | 755 | let result = match verb { |
739 | | - Some("status") => verb_status(config), |
| 756 | + Some("status") => verb_status(config, rest), |
740 | 757 | Some("launch") => verb_launch(config, rest), |
741 | 758 | Some("enqueue") => verb_enqueue(config, rest), |
742 | 759 | Some(other) => Err(usage(format!( |
@@ -836,6 +853,27 @@ mod tests { |
836 | 853 | assert_eq!(dechunked_len(b"4\r\nWi"), None); |
837 | 854 | } |
838 | 855 |
|
| 856 | + #[test] |
| 857 | + fn status_help_and_rejection_need_no_service() { |
| 858 | + // Help and argument rejection return before any transport is |
| 859 | + // opened (the default config's transport would try the |
| 860 | + // loopback probe / proxy egress), so these calls double as |
| 861 | + // the no-network pins: a regression that dials out first |
| 862 | + // fails or hangs here instead of returning promptly. |
| 863 | + let config = Config::default(); |
| 864 | + assert_eq!( |
| 865 | + verb_status(&config, &strings(&["--help"])).unwrap(), |
| 866 | + Value::Null |
| 867 | + ); |
| 868 | + assert_eq!( |
| 869 | + verb_status(&config, &strings(&["-h"])).unwrap(), |
| 870 | + Value::Null |
| 871 | + ); |
| 872 | + let err = verb_status(&config, &strings(&["--bogus"])).unwrap_err(); |
| 873 | + assert_eq!(err.exit_code(), EXIT_USAGE); |
| 874 | + assert!(err.message().contains("--bogus")); |
| 875 | + } |
| 876 | + |
839 | 877 | #[test] |
840 | 878 | fn usage_errors_exit_2_and_transport_3() { |
841 | 879 | assert_eq!(usage("x").exit_code(), 2); |
|