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 int main(int argc, char** argv) {
26 InitLogging(argv, android::base::StderrLogger);
27 std::vector<std::string> args;
29 if (argc == 1 || (argc == 2 && strcmp(argv[1], "--help") == 0)) {
30 args.push_back("help");
32 for (int i = 1; i < argc; ++i) {
33 args.push_back(argv[i]);
37 Command* command = Command::FindCommandByName(args[0]);
38 if (command == nullptr) {
39 LOG(ERROR) << "malformed command line: unknown command " << args[0];
42 std::string command_name = args[0];
43 args.erase(args.begin());
45 LOG(DEBUG) << "command '" << command_name << "' starts running";
46 bool result = command->Run(args);
47 LOG(DEBUG) << "command '" << command_name << "' "
48 << (result ? "finished successfully" : "failed");
49 return result ? 0 : 1;