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"}}
98 "Get list of zone with some useful informations (id, state, terminal, root path)",
111 "get_active_zone_id", {
113 "get_active_zone_id",
114 "Get active (foreground) zone ids",
119 "lookup_zone_by_id", {
121 "lookup_zone_by_id zone_id",
122 "Prints informations about zone",
123 {{"zone_id", "id zone name"}}
129 "grant_device zone_id device_name",
130 "Grants access to the given device",
131 {{"zone_id", "id zone name"},
132 {"device_name", " device name"}}
138 "revoke_device zone_id device_name",
139 "Revokes access to the given device",
140 {{"zone_id", "id zone name"},
141 {"device_name", " device name"}}
146 void printUsage(std::ostream& out, const std::string& name)
148 out << "Usage: " << name << " [command [args]]\n\n"
149 << "command can be one of the following:\n";
151 for (const auto& command : commands) {
152 command.second.printUsage(out);
158 int main(const int argc, const char** argv)
161 printUsage(std::cout, argv[0]);
164 if (commands.count(argv[1]) == 0) {
165 printUsage(std::cout, argv[0]);
169 CommandLineInterface& command = commands[argv[1]];
171 command.execute(1, argc, argv);
172 } catch (const std::runtime_error& ex) {
173 std::cerr << ex.what() << std::endl;