2 * Copyright (C) 2015 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <base/logging.h>
25 class HelpCommand : public Command {
28 : Command("help", "print help information for simpleperf",
29 "Usage: simpleperf help [subcommand]\n"
30 " Without subcommand, print short help string for every subcommand.\n"
31 " With subcommand, print long help string for the subcommand.\n\n") {
34 bool Run(const std::vector<std::string>& args) override;
37 void PrintShortHelp();
38 void PrintLongHelpForOneCommand(const Command& cmd);
41 bool HelpCommand::Run(const std::vector<std::string>& args) {
45 Command* cmd = Command::FindCommandByName(args[0]);
47 LOG(ERROR) << "malformed command line: can't find help string for unknown command " << args[0];
48 LOG(ERROR) << "try using \"--help\"";
51 PrintLongHelpForOneCommand(*cmd);
57 void HelpCommand::PrintShortHelp() {
58 printf("Usage: simpleperf [--help] subcommand [args_for_subcommand]\n\n");
59 for (auto& command : Command::GetAllCommands()) {
60 printf("%-20s%s\n", command->Name().c_str(), command->ShortHelpString().c_str());
64 void HelpCommand::PrintLongHelpForOneCommand(const Command& command) {
65 printf("%s\n", command.LongHelpString().c_str());
68 HelpCommand help_command;