From e9a9b0cb95fe8a8585665437aa754f518100034e Mon Sep 17 00:00:00 2001 From: Damian Meden Date: Wed, 29 Oct 2025 12:01:49 +0000 Subject: [PATCH 1/2] tools - traffic_ctl, traffic_layout: use ArgParse groups to handle mutually exclusive options. traffic_ctl: Usage: traffic_ctl [OPTIONS] CMD [ARGS ...] Commands ---------------------- Description ----------------------- drain Drain the requests Options ======================= Default ===== Description ============= Group (drain_mode) -N, --no-new-connection Wait for new connections down to threshold before starting draining -U, --undo Recover server from the drain mode traffic_layout: Usage: traffic_layout CMD [OPTIONS] Commands ---------------------- Description ----------------------- info Show the layout as default Options ======================= Default ===== Description ============= -j, --json Produce output in JSON format (when supported) Group (display_mode) --features Show the compiled features --versions Show various library and other versioning information --- src/traffic_ctl/traffic_ctl.cc | 14 +++++++++----- src/traffic_layout/traffic_layout.cc | 11 ++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/traffic_ctl/traffic_ctl.cc b/src/traffic_ctl/traffic_ctl.cc index 5599bd64c9a..4350627cfa0 100644 --- a/src/traffic_ctl/traffic_ctl.cc +++ b/src/traffic_ctl/traffic_ctl.cc @@ -177,11 +177,15 @@ main([[maybe_unused]] int argc, const char **argv) // server commands server_command.add_command("backtrace", "Show a full stack trace of the traffic_server process", [&]() { CtrlUnimplementedCommand("backtrace"); }); - server_command.add_command("status", "Show the proxy status", Command_Execute).add_example_usage("traffic_ctl server status"); - server_command.add_command("drain", "Drain the requests", Command_Execute) - .add_example_usage("traffic_ctl server drain [OPTIONS]") - .add_option("--no-new-connection", "-N", "Wait for new connections down to threshold before starting draining") - .add_option("--undo", "-U", "Recover server from the drain mode"); + server_command.add_command("status", "Show the proxy status", [&]() { command->execute(); }) + .add_example_usage("traffic_ctl server status"); + auto &drain_cmd = server_command.add_command("drain", "Drain the requests", [&]() { command->execute(); }); + drain_cmd.add_example_usage("traffic_ctl server drain [OPTIONS]"); + + // Mutually exclusive drain mode options (auto-creates group) + drain_cmd.add_option_to_group("drain_mode", "--no-new-connection", "-N", + "Wait for new connections down to threshold before starting draining"); + drain_cmd.add_option_to_group("drain_mode", "--undo", "-U", "Recover server from the drain mode"); auto &debug_command = server_command.add_command("debug", "Enable/Disable ATS for diagnostic messages at runtime").require_commands(); diff --git a/src/traffic_layout/traffic_layout.cc b/src/traffic_layout/traffic_layout.cc index fa28fb5ef29..6246900b600 100644 --- a/src/traffic_layout/traffic_layout.cc +++ b/src/traffic_layout/traffic_layout.cc @@ -45,11 +45,12 @@ main([[maybe_unused]] int argc, const char **argv) .add_option("--version", "-V", "Print version string"); // info command - engine.parser.add_command("info", "Show the layout as default", [&]() { engine.info(); }) - .add_option("--features", "", "Show the compiled features") - .add_option("--versions", "", "Show various library and other versioning information") - .add_option("--json", "-j", "Produce output in JSON format (when supported)") - .set_default(); + auto &info_cmd = engine.parser.add_command("info", "Show the layout as default", [&]() { engine.info(); }); + // Mutually exclusive display modes + info_cmd.add_option_to_group("display_mode", "--features", "", "Show the compiled features"); + info_cmd.add_option_to_group("display_mode", "--versions", "", "Show various library and other versioning information"); + + info_cmd.add_option("--json", "-j", "Produce output in JSON format (when supported)").set_default(); // init command engine.parser.add_command("init", "Initialize(create) the runroot sandbox", [&]() { engine.create_runroot(); }) .add_option("--absolute", "-a", "Produce absolute path in the runroot.yaml") From 826c4aec119577c429bd48167cd845368cf33568 Mon Sep 17 00:00:00 2001 From: Damian Meden Date: Wed, 5 Nov 2025 13:09:12 +0000 Subject: [PATCH 2/2] Use add_mutex_group fn --- src/traffic_ctl/traffic_ctl.cc | 2 +- src/traffic_layout/traffic_layout.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/traffic_ctl/traffic_ctl.cc b/src/traffic_ctl/traffic_ctl.cc index 4350627cfa0..b094e6649ac 100644 --- a/src/traffic_ctl/traffic_ctl.cc +++ b/src/traffic_ctl/traffic_ctl.cc @@ -182,7 +182,7 @@ main([[maybe_unused]] int argc, const char **argv) auto &drain_cmd = server_command.add_command("drain", "Drain the requests", [&]() { command->execute(); }); drain_cmd.add_example_usage("traffic_ctl server drain [OPTIONS]"); - // Mutually exclusive drain mode options (auto-creates group) + drain_cmd.add_mutex_group("drain_mode", false, "Drain mode options"); drain_cmd.add_option_to_group("drain_mode", "--no-new-connection", "-N", "Wait for new connections down to threshold before starting draining"); drain_cmd.add_option_to_group("drain_mode", "--undo", "-U", "Recover server from the drain mode"); diff --git a/src/traffic_layout/traffic_layout.cc b/src/traffic_layout/traffic_layout.cc index 6246900b600..dcd1465dd47 100644 --- a/src/traffic_layout/traffic_layout.cc +++ b/src/traffic_layout/traffic_layout.cc @@ -46,7 +46,7 @@ main([[maybe_unused]] int argc, const char **argv) // info command auto &info_cmd = engine.parser.add_command("info", "Show the layout as default", [&]() { engine.info(); }); - // Mutually exclusive display modes + info_cmd.add_mutex_group("display_mode", false, "Display mode options"); info_cmd.add_option_to_group("display_mode", "--features", "", "Show the compiled features"); info_cmd.add_option_to_group("display_mode", "--versions", "", "Show various library and other versioning information");