GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(fleet-dispatch): status honors --help and rejects stray arguments… · developing-today/code@d3fb961

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pkgs/fleet/crates/fleet-dispatch/src
    • lib.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkgs/fleet/crates/fleet-dispatch/src/lib.rs‎

Copy file name to clipboardExpand all lines: pkgs/fleet/crates/fleet-dispatch/src/lib.rs
+40-2Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,24 @@ fn bearer_token(config: &Config) -> Result<SecretValue> {
445445
// Verbs
446446
// ---------------------------------------------------------------------------
447447

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+
}
449466
let transport_sel = pick_transport(config)?;
450467
let described = transport_sel.describe();
451468
let body = finish(
@@ -736,7 +753,7 @@ pub fn run(config: &Config, args: &[String]) -> i32 {
736753
let verb = args.first().map(|s| s.as_str());
737754
let rest = if args.is_empty() { &[][..] } else { &args[1..] };
738755
let result = match verb {
739-
Some("status") => verb_status(config),
756+
Some("status") => verb_status(config, rest),
740757
Some("launch") => verb_launch(config, rest),
741758
Some("enqueue") => verb_enqueue(config, rest),
742759
Some(other) => Err(usage(format!(
@@ -836,6 +853,27 @@ mod tests {
836853
assert_eq!(dechunked_len(b"4\r\nWi"), None);
837854
}
838855

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+
839877
#[test]
840878
fn usage_errors_exit_2_and_transport_3() {
841879
assert_eq!(usage("x").exit_code(), 2);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.