blob: b393f052be59fa44ac508524a077db7af65bf4a8 [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
24Status 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
34Status 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
51void 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