blob: 6773ace6d2484d43434027de0939782a4f15a856 [file] [log] [blame]
Yifan Honga8bedc62017-09-08 18:00:31 -07001/*
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
21namespace android {
22namespace lshal {
23
Yifan Hong795b6ec2017-09-13 11:25:28 -070024std::string HelpCommand::GetName() {
25 return "help";
26}
27
28std::string HelpCommand::getSimpleDescription() const {
29 return "Print help message.";
30}
31
Yifan Honga8bedc62017-09-08 18:00:31 -070032Status HelpCommand::main(const Arg &arg) {
33 if (optind >= arg.argc) {
34 // `lshal help` prints global usage.
35 mLshal.usage();
36 return OK;
37 }
38 (void)usageOfCommand(arg.argv[optind]);
39 return OK;
40}
41
42Status HelpCommand::usageOfCommand(const std::string& c) const {
43 if (c.empty()) {
44 mLshal.usage();
45 return USAGE;
46 }
47 auto command = mLshal.selectCommand(c);
48 if (command == nullptr) {
49 // from HelpCommand::main, `lshal help unknown`
50 mLshal.usage();
51 return USAGE;
52 }
53
54 command->usage();
55 return USAGE;
56
57}
58
59void HelpCommand::usage() const {
Yifan Hong795b6ec2017-09-13 11:25:28 -070060 mLshal.err()
61 << "help:" << std::endl
62 << " lshal -h" << std::endl
63 << " lshal --help" << std::endl
64 << " lshal help" << std::endl
65 << " Print this help message" << std::endl;
66 mLshal.forEachCommand([&](const Command* e) {
67 mLshal.err() << " lshal help " << e->getName() << std::endl
68 << " Print help message for " << e->getName() << std::endl;
69 });
Yifan Honga8bedc62017-09-08 18:00:31 -070070
Yifan Honga8bedc62017-09-08 18:00:31 -070071}
72
73} // namespace lshal
74} // namespace android
75