Skip to content

Commit bb4b904

Browse files
authored
tools - traffic_ctl, traffic_layout: use ArgParse groups to handle mutually exclusive options. (#12623)
* 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
1 parent 40b99c7 commit bb4b904

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/traffic_ctl/traffic_ctl.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,15 @@ main([[maybe_unused]] int argc, const char **argv)
183183
// server commands
184184
server_command.add_command("backtrace", "Show a full stack trace of the traffic_server process",
185185
[&]() { CtrlUnimplementedCommand("backtrace"); });
186-
server_command.add_command("status", "Show the proxy status", Command_Execute).add_example_usage("traffic_ctl server status");
187-
server_command.add_command("drain", "Drain the requests", Command_Execute)
188-
.add_example_usage("traffic_ctl server drain [OPTIONS]")
189-
.add_option("--no-new-connection", "-N", "Wait for new connections down to threshold before starting draining")
190-
.add_option("--undo", "-U", "Recover server from the drain mode");
186+
server_command.add_command("status", "Show the proxy status", [&]() { command->execute(); })
187+
.add_example_usage("traffic_ctl server status");
188+
auto &drain_cmd = server_command.add_command("drain", "Drain the requests", [&]() { command->execute(); });
189+
drain_cmd.add_example_usage("traffic_ctl server drain [OPTIONS]");
190+
191+
drain_cmd.add_mutex_group("drain_mode", false, "Drain mode options");
192+
drain_cmd.add_option_to_group("drain_mode", "--no-new-connection", "-N",
193+
"Wait for new connections down to threshold before starting draining");
194+
drain_cmd.add_option_to_group("drain_mode", "--undo", "-U", "Recover server from the drain mode");
191195

192196
auto &debug_command =
193197
server_command.add_command("debug", "Enable/Disable ATS for diagnostic messages at runtime").require_commands();

src/traffic_layout/traffic_layout.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ main([[maybe_unused]] int argc, const char **argv)
4545
.add_option("--version", "-V", "Print version string");
4646

4747
// info command
48-
engine.parser.add_command("info", "Show the layout as default", [&]() { engine.info(); })
49-
.add_option("--features", "", "Show the compiled features")
50-
.add_option("--versions", "", "Show various library and other versioning information")
51-
.add_option("--json", "-j", "Produce output in JSON format (when supported)")
52-
.set_default();
48+
auto &info_cmd = engine.parser.add_command("info", "Show the layout as default", [&]() { engine.info(); });
49+
info_cmd.add_mutex_group("display_mode", false, "Display mode options");
50+
info_cmd.add_option_to_group("display_mode", "--features", "", "Show the compiled features");
51+
info_cmd.add_option_to_group("display_mode", "--versions", "", "Show various library and other versioning information");
52+
53+
info_cmd.add_option("--json", "-j", "Produce output in JSON format (when supported)").set_default();
5354
// init command
5455
engine.parser.add_command("init", "Initialize(create) the runroot sandbox", [&]() { engine.create_runroot(); })
5556
.add_option("--absolute", "-a", "Produce absolute path in the runroot.yaml")

0 commit comments

Comments
 (0)