Yifan Hong | a8bedc6 | 2017-09-08 18:00:31 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #include "HelpCommand.h" |
| 18 | |
| 19 | #include "Lshal.h" |
| 20 | |
| 21 | namespace android { |
| 22 | namespace lshal { |
| 23 | |
| 24 | Status HelpCommand::main(const Arg &arg) { |
| 25 | if (optind >= arg.argc) { |
| 26 | // `lshal help` prints global usage. |
| 27 | mLshal.usage(); |
| 28 | return OK; |
| 29 | } |
| 30 | (void)usageOfCommand(arg.argv[optind]); |
| 31 | return OK; |
| 32 | } |
| 33 | |
| 34 | Status HelpCommand::usageOfCommand(const std::string& c) const { |
| 35 | if (c.empty()) { |
| 36 | mLshal.usage(); |
| 37 | return USAGE; |
| 38 | } |
| 39 | auto command = mLshal.selectCommand(c); |
| 40 | if (command == nullptr) { |
| 41 | // from HelpCommand::main, `lshal help unknown` |
| 42 | mLshal.usage(); |
| 43 | return USAGE; |
| 44 | } |
| 45 | |
| 46 | command->usage(); |
| 47 | return USAGE; |
| 48 | |
| 49 | } |
| 50 | |
| 51 | void HelpCommand::usage() const { |
| 52 | static const std::string help = |
| 53 | "help:\n" |
| 54 | " lshal -h\n" |
| 55 | " lshal --help\n" |
| 56 | " lshal help\n" |
| 57 | " Print this help message\n" |
| 58 | " lshal help list\n" |
| 59 | " Print help message for list\n" |
| 60 | " lshal help debug\n" |
| 61 | " Print help message for debug\n"; |
| 62 | |
| 63 | mLshal.err() << help; |
| 64 | } |
| 65 | |
| 66 | } // namespace lshal |
| 67 | } // namespace android |
| 68 | |