From e17105e146dd179c4f2cb756022cc995ad4cddec Mon Sep 17 00:00:00 2001 From: Krzysztof Dynowski Date: Thu, 20 Aug 2015 16:10:52 +0200 Subject: [PATCH] vsm: update network related help, formating changes [Feature] clarify help for net-create command [Cause] poor help on how to create virtual network [Solution] extend description format, inerpretation [Verification] Build, install, run vsm net-create help Change-Id: I09b877d090607fb9f8d3c5b367f6f6b2d1a7ed85 --- cli/command-line-interface.cpp | 37 +++++++++++++++++++++++++++--------- cli/main.cpp | 43 +++++++++++++++++++++++++++--------------- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/cli/command-line-interface.cpp b/cli/command-line-interface.cpp index 86bc808..93201c3 100644 --- a/cli/command-line-interface.cpp +++ b/cli/command-line-interface.cpp @@ -143,6 +143,18 @@ void buildZoneList(std::vector& list) vsm_array_string_free(ids); } +void buildNetdevList(const std::string& zone,std::vector& list) +{ + using namespace std::placeholders; + VsmArrayString ids; + + CommandLineInterface::executeCallback(bind(vsm_zone_get_netdevs, _1, zone.c_str(), &ids)); + for (VsmString* id = ids; *id; ++id) { + list.push_back(*id); + } + vsm_array_string_free(ids); +} + } // namespace const std::vector CommandLineInterface::buildCompletionList(const Args& a) const @@ -165,9 +177,7 @@ const std::vector CommandLineInterface::buildCompletionList(const A buildZoneList(v); } else if (ss == "{NETDEV}") { - //TODO: get list of available interfaces - v.push_back("lo"); - v.push_back("eth0"); + buildNetdevList(a[a.size()-2],v); // zone name must precede netdev } else if (ss.length() > 0) { v.push_back(ss); @@ -242,19 +252,28 @@ const std::string& CommandLineInterface::getDescription() const void CommandLineInterface::printUsage(std::ostream& out) const { - out << mName; + out << "Syntax\n"; + out << "\t" << mName; for (const auto& args : mArgsSpec) { out << " " << args.name; } out << "\n\n" - << "\tDescription\n" - << "\t\t" << mDescription << "\n"; + "Description\n" + "\t" << mDescription << "\n"; if (!mArgsSpec.empty()) { - out << "\n\tOptions\n"; + out << "\n" + "Options\n"; for (const auto& args : mArgsSpec) { - out << "\t\t" << args.name << " -- " << args.description << "\n"; + out << "\t" << args.name << " -- "; + const std::string& d=args.description; + std::stringstream ss(d); + std::string item; + std::getline(ss, item); + out << item << std::endl; + while (std::getline(ss, item)) + out << "\t\t" << item << std::endl; } } out << "\n"; @@ -484,7 +503,7 @@ void create_netdev(const Args& argv) { using namespace std::placeholders; - if (argv.size() < 2) { + if (argv.size() < 3) { throw runtime_error("Not enough parameters"); } diff --git a/cli/main.cpp b/cli/main.cpp index 739d293..528c4c8 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -153,14 +153,24 @@ std::vector commands = { { create_netdev, "net-create", - "Create network interface in zone", + "Create network virtualization for the zone", MODE_COMMAND_LINE | MODE_INTERACTIVE, { {"zone_id", "zone name", "{ZONE}"}, - {"netdevtype", "interface type", "macvlan|phys|veth"}, + {"netdevtype", "interface type (veth, macvlan, phys)\n" + " veth - create new zone iface and bridge to host\n" + "macvlan - create new zone slave iface briged to master with specified mode\n" + " phys - move existing iface from host to zone (no way to move it back)", + "veth|macvlan|phys" + }, {"zone_netdev", "interface name (eth0)", "eth0|eth1"}, {"host_netdev", "bridge name (virbr0)", "virbr0|virbr1"}, - {"mode", "macvlan mode (private, vepa, bridge, passthru)", "private|vepa|bridge|passthru"}} + {"mode", "macvlan mode (private, vepa, bridge, passthru)\n" + " private - bridge but no comunicate with otheri vlan\n" + " vepa - ethernet switch\n" + " bridge - light weight to other vlan\n" + "passthru - only one vlan device", + "private|vepa|bridge|passthru"}} }, { destroy_netdev, @@ -242,14 +252,14 @@ void printUsage(std::ostream& out, const std::string& name, unsigned int mode) n = name + " "; } + out << "Usage: " << n << "[-h|help|-f |[ [-h|help|]]]\n\n"; if (mode == MODE_COMMAND_LINE) { - out << "Usage: " << n << "[-h|-f |[ [-h|]]\n" - << "Called without parameters enters interactive mode.\n" + out << "Description:\n" + << "\tCommand line tool to manage vasum containers.\n" + << "\tCalled without parameters enters interactive mode.\n" << "Options:\n" - << "-h print help\n" - << "-f read and execute commands from file\n\n"; - } else { - out << "Usage: [-h| [-h|]]\n\n"; + << "\t-h,help print this help\n" + << "\t-f read and execute commands from file\n\n"; } out << "command can be one of the following:\n"; @@ -258,12 +268,16 @@ void printUsage(std::ostream& out, const std::string& name, unsigned int mode) if (std::find(addLineBefore.begin(), addLineBefore.end(), command.getName()) != addLineBefore.end()) { out << std::endl; } - out << " " << std::setw(25) << std::left << command.getName() - << command.getDescription() << std::endl; + out << " " << std::setw(20) << std::left << command.getName(); + const std::string& d = command.getDescription(); + std::stringstream ss(d); + std::string item; + std::getline(ss, item); + out << item << std::endl; } } - out << "\nSee " << n << "command -h to read about a specific one.\n"; + out << "\nType '" << n << "command help' to read about a specific one.\n"; } int connect() @@ -303,8 +317,7 @@ int executeCommand(const Args& argv, int mode) return EXIT_FAILURE; } - auto it = std::find(argv.begin(), argv.end(), std::string("-h")); - if (it != argv.end()) { + if (argv.size() > 1 && (argv[1] == "-h" || argv[1] == "help")) { command.printUsage(std::cout); return EXIT_SUCCESS; } @@ -466,7 +479,7 @@ int bashComplMode(int argc, const char *argv[]) int cliMode(const int argc, const char** argv) { - if (std::string(argv[1]) == "-h") { + if (std::string(argv[1]) == "-h" || std::string(argv[1]) == "help") { printUsage(std::cout, argv[0], MODE_COMMAND_LINE); return EXIT_SUCCESS; } -- 2.7.4