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.
22 #include <android-base/logging.h>
27 int main(int argc, char** argv) {
28 InitLogging(argv, android::base::StderrLogger);
29 std::vector<std::string> args;
30 android::base::LogSeverity log_severity = android::base::WARNING;
32 for (int i = 1; i < argc; ++i) {
33 if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
34 args.insert(args.begin(), "help");
35 } else if (strcmp(argv[i], "--log") == 0) {
38 if (!GetLogSeverity(argv[i], &log_severity)) {
39 LOG(ERROR) << "Unknown log severity: " << argv[i];
43 LOG(ERROR) << "Missing argument for --log option.\n";
47 args.push_back(argv[i]);
50 android::base::ScopedLogSeverity severity(log_severity);
53 args.push_back("help");
55 std::unique_ptr<Command> command = CreateCommandInstance(args[0]);
56 if (command == nullptr) {
57 LOG(ERROR) << "malformed command line: unknown command " << args[0];
60 std::string command_name = args[0];
61 args.erase(args.begin());
63 LOG(DEBUG) << "command '" << command_name << "' starts running";
64 bool result = command->Run(args);
65 LOG(DEBUG) << "command '" << command_name << "' "
66 << (result ? "finished successfully" : "failed");
67 return result ? 0 : 1;