From 283724686e99cd70fcb3b1ed827112ea1b621552 Mon Sep 17 00:00:00 2001 From: Chad Reynolds Date: Wed, 29 Jan 2025 18:12:33 -0800 Subject: [PATCH] Handle invocations like `cvd -h` or `cvd --help` Treating it at `cvd help` uses existing logic, rather than trying to force the handling into selectors parsing or handle it as a "driver" flag (how `verbosity` is handled in `main`). The selector flags are already processed by this point and do not interfere. Bug: 387539609 Test: cvd -h Test: cvd --help Test: cvd -help version Test: cvd --instance_name=test -h Test: cvd --selector_typo=test -h --- .../cuttlefish/host/commands/cvd/cli/command_request.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/command_request.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/command_request.cpp index d8d8f28d09..10742c5fad 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/command_request.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/command_request.cpp @@ -20,6 +20,7 @@ #include #include "common/libs/utils/files.h" +#include "common/libs/utils/flag_parser.h" #include "common/libs/utils/result.h" #include "host/commands/cvd/cli/command_request.h" #include "host/commands/cvd/cli/selector/selector_common_parser.h" @@ -44,6 +45,12 @@ CommandRequest::CommandRequest(cvd_common::Args args, cvd_common::Envs env, subcommand_ = subcommand_arguments_[0]; subcommand_arguments_.erase(subcommand_arguments_.begin()); } + + // transform `cvd -h` or `cvd --help` requests into `cvd help` + Result is_top_level_help_flag = HasHelpFlag({subcommand_}); + if (is_top_level_help_flag.ok() && *is_top_level_help_flag) { + subcommand_ = "help"; + } } CommandRequestBuilder& CommandRequestBuilder::AddArguments(