2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Mateusz Malicki <m.malicki2@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
21 * @author Mateusz Malicki (m.malicki2@samsung.com)
22 * @brief Declaration of CommandLineInterface class
25 #include "command-line-interface.hpp"
33 using namespace vasum::cli;
37 std::map<std::string, CommandLineInterface> commands = {
41 "set_active_zone zone_id",
42 "Set active (foreground) zone",
43 {{"zone_id", "id zone name"}}
49 "create_zone zone_id",
50 "Create and add zone",
51 {{"zone_id", "id zone name"}}
57 "destroy_zone zone_id",
59 {{"zone_id", "id zone name"}}
65 "shutdown_zone zone_id",
67 {{"zone_id", "id zone name"}}
75 {{"zone_id", "id zone name"}}
83 {{"zone_id", "id zone name"}}
89 "unlock_zone zone_id",
91 {{"zone_id", "id zone name"}}
95 "lookup_zone_by_id", {
97 "lookup_zone_by_id zone_id",
98 "Prints informations about zone",
99 {{"zone_id", "id zone name"}}
105 "grant_device zone_id device_name",
106 "Grants access to the given device",
107 {{"zone_id", "id zone name"},
108 {"device_name", " device name"}}
114 "revoke_device zone_id device_name",
115 "Revokes access to the given device",
116 {{"zone_id", "id zone name"},
117 {"device_name", " device name"}}
122 void printUsage(std::ostream& out, const std::string& name)
124 out << "Usage: " << name << " [command [args]]\n\n"
125 << "command can be one of the following:\n";
127 for (const auto& command : commands) {
128 command.second.printUsage(out);
134 int main(const int argc, const char** argv)
137 printUsage(std::cout, argv[0]);
140 if (commands.count(argv[1]) == 0) {
141 printUsage(std::cout, argv[0]);
145 CommandLineInterface& command = commands[argv[1]];
147 command.execute(1, argc, argv);
148 } catch (const std::runtime_error& ex) {
149 std::cerr << ex.what() << std::endl;