本文整理汇总了C++中Cmdline类的典型用法代码示例。如果您正苦于以下问题:C++ Cmdline类的具体用法?C++ Cmdline怎么用?C++ Cmdline使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cmdline类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execute
int CpCommand::execute (Cmdline const & cl)
{
if (cl.arguments.size () != 2)
{
throw invalid_argument ("wrong number of arguments, 2 needed");
}
KeySet conf;
Key sourceKey = cl.createKey (0);
if (!sourceKey.isValid ())
{
throw invalid_argument ("Source given is not a valid keyname");
}
Key destKey = cl.createKey (1);
if (!destKey.isValid ())
{
throw invalid_argument ("Destination given is not a valid keyname");
}
string newDirName = destKey.getName ();
kdb.get (conf, sourceKey);
kdb.get (conf, destKey);
KeySet tmpConf = conf;
KeySet oldConf;
oldConf.append (tmpConf.cut (sourceKey));
KeySet newConf;
oldConf.rewind ();
std::string sourceName = sourceKey.getName ();
if (cl.verbose) cout << "common name: " << sourceName << endl;
if (cl.recursive)
{
// copy all keys with new name
Key k;
while ((k = oldConf.next ()))
{
Key rk = rename_key (k, sourceName, newDirName, cl.verbose);
copySingleKey (cl, rk, tmpConf, newConf);
}
}
else
{
// just copy one key
Key k = oldConf.next ();
Key rk = rename_key (k, sourceName, newDirName, cl.verbose);
copySingleKey (cl, rk, tmpConf, newConf);
}
newConf.append (tmpConf); // these are unrelated keys
newConf.append (oldConf); // these are the original keys
newConf.rewind ();
kdb.set (newConf, destKey);
return 0;
}
示例2: execute
int FstabCommand::execute (Cmdline const & cl)
{
int argc = cl.arguments.size ();
if (argc != 5 && argc != 6 && argc != 7)
{
throw invalid_argument ("number of arguments not correct, need 5, 6 or 7");
}
KeySet conf;
Key parentKey = cl.createKey (0);
kdb.get (conf, parentKey);
printWarnings (cerr, parentKey);
Key k = conf.lookup (parentKey);
if (!k)
{
k = cl.createKey (0);
conf.append (k);
}
std::string keyname = k.getName ();
string dumpfreq = "0";
if (argc >= 6)
{
dumpfreq = cl.arguments[5].c_str ();
}
string passno = "0";
if (argc >= 7)
{
passno = cl.arguments[6].c_str ();
}
kdb::KeySet config (20, *kdb::Key (keyname + "/ZZZNewFstabName", KEY_END),
*kdb::Key (keyname + "/ZZZNewFstabName/device", KEY_VALUE, cl.arguments[1].c_str (), KEY_END),
*kdb::Key (keyname + "/ZZZNewFstabName/mpoint", KEY_VALUE, cl.arguments[2].c_str (), KEY_END),
*kdb::Key (keyname + "/ZZZNewFstabName/type", KEY_VALUE, cl.arguments[3].c_str (), KEY_END),
*kdb::Key (keyname + "/ZZZNewFstabName/options", KEY_VALUE, cl.arguments[4].c_str (), KEY_END),
*kdb::Key (keyname + "/ZZZNewFstabName/dumpfreq", KEY_VALUE, dumpfreq.c_str (), KEY_END),
*kdb::Key (keyname + "/ZZZNewFstabName/passno", KEY_VALUE, passno.c_str (), KEY_END), KS_END);
conf.append (config);
if (cl.verbose)
{
cout << conf;
}
kdb.set (conf, parentKey);
printWarnings (cerr, parentKey);
return 0;
}
示例3: execute
int LsCommand::execute (Cmdline const & cl)
{
checkArguments (cl);
printWarnings (cerr, root);
root = cl.createKey (0);
kdb.get (ks, root);
if (cl.verbose) cout << "size of all keys in mountpoint: " << ks.size () << endl;
KeySet part (ks.cut (root));
if (cl.verbose) cout << "size of requested keys: " << part.size () << endl;
cout.setf (std::ios_base::unitbuf);
if (cl.null)
{
cout.unsetf (std::ios_base::skipws);
}
printResults (part, getDepth (root), cl);
printWarnings (cerr, root);
return 0;
}
示例4: execute
int FileCommand::execute (Cmdline const & cl)
{
if (cl.arguments.size () != 1) throw invalid_argument ("Need one argument");
KeySet conf;
Key x = cl.createKey (0);
if (x.getName ()[0] == '/')
{
x.setName (cl.ns + x.getName ());
std::cerr << "Using name " << x.getName () << std::endl;
}
if (!x.isValid ())
{
throw invalid_argument (cl.arguments[0] + " is not a valid keyname");
}
kdb.get (conf, x);
cout << x.getString ();
if (!cl.noNewline)
{
cout << endl;
}
return 0;
}
示例5: execute
int GetCommand::execute (Cmdline const & cl)
{
if (cl.arguments.size () != 1) throw invalid_argument ("Need one argument");
KeySet conf;
kdb::Key root = cl.createKey (0);
kdb::KDB kdb (root);
std::string n;
if (cl.all)
{
n = root.getName ();
root.setName ("/");
}
kdb.get (conf, root);
if (cl.all)
{
root.setName (n);
}
// do a lookup without tracer to warm up default cache
conf.lookup (root);
root.setCallback (warnOnMeta);
if (cl.verbose)
{
cout << "got " << conf.size () << " keys" << std::endl;
root.setCallback (printTrace);
}
Key k = conf.lookup (root);
int ret = 0;
if (k)
{
if (cl.verbose)
{
cout << "The resulting keyname is " << k.getName () << std::endl;
}
cout << k.getString ();
}
else
{
cerr << "Did not find key";
ret = 1;
}
if (!cl.noNewline)
{
cout << endl;
}
printWarnings (cerr, root);
printError (cerr, root);
return ret;
}
示例6: buildBackend
void MountCommand::buildBackend (Cmdline const & cl)
{
MountBackendBuilder backend;
Key mpk (mp, KEY_CASCADING_NAME, KEY_END);
if (!mpk.isValid ())
{
throw invalid_argument (mp + " is not a valid mountpoint");
}
backend.setMountpoint (mpk, mountConf);
backend.setBackendConfig (cl.getPluginsConfig ("system/"));
PluginSpec resolver (cl.resolver);
if (cl.debug)
{
cout << "Trying to load the resolver plugin " << resolver.getName () << endl;
}
backend.addPlugin (PluginSpec (resolver));
if (cl.interactive)
{
cout << endl;
cout << "Enter a path to a file in the filesystem." << endl;
cout << "The path must either not exist or be a file." << endl;
cout << "For user or cascading mountpoints it must be a relative path." << endl;
cout << "Then, the path will be resolved dynamically." << endl;
cout << "Path: ";
cin >> path;
}
示例7: execute
int LsCommand::execute (Cmdline const & cl)
{
if (cl.arguments.size () != 1)
{
throw invalid_argument ("1 argument required");
}
printWarnings (cerr, root);
root = cl.createKey (0);
kdb.get (ks, root);
if (cl.verbose) cout << "size of all keys in mountpoint: " << ks.size () << endl;
KeySet part (ks.cut (root));
if (cl.verbose) cout << "size of requested keys: " << part.size () << endl;
cout.setf (std::ios_base::unitbuf);
if (cl.null)
{
cout.unsetf (std::ios_base::skipws);
}
cout << part;
printWarnings (cerr, root);
return 0;
}
示例8: execute
int MetaRemoveCommand::execute (Cmdline const & cl)
{
if (cl.arguments.size () != 2)
{
throw invalid_argument ("Need 2 arguments");
}
Key parentKey = cl.createKey (0);
string metaname = cl.arguments[1];
KeySet conf;
kdb.get (conf, parentKey);
printWarnings (cerr, parentKey);
Key k = conf.lookup (parentKey);
if (!k)
{
cerr << "Key not found" << endl;
return 1;
}
k.delMeta (metaname);
kdb.set (conf, parentKey);
return 0;
}
示例9: execute
int ExportCommand::execute (Cmdline const & cl)
{
size_t argc = cl.arguments.size ();
if (argc != 1 && argc != 2 && argc != 3)
{
throw invalid_argument ("need 1 to 3 arguments");
}
Key root = cl.createKey (0);
kdb.get (ks, root);
printWarnings (cerr, root);
KeySet part (ks.cut (root));
if (cl.withoutElektra)
{
Key systemElektra ("system/elektra", KEY_END);
part.cut (systemElektra);
}
string format = cl.format;
if (argc > 1) format = cl.arguments[1];
#ifdef _WIN32
string file = "CON";
#else
string file = "/dev/stdout";
#endif
if (argc > 2 && cl.arguments[2] != "-") file = cl.arguments[2];
Modules modules;
PluginPtr plugin = modules.load (format, cl.getPluginsConfig ());
Key errorKey (root);
errorKey.setString (file);
plugin->set (part, errorKey);
printWarnings (cerr, errorKey);
printError (cerr, errorKey);
return 0;
}
示例10: execute
int MetaSetCommand::execute (Cmdline const & cl)
{
if (cl.arguments.size () < 2 || cl.arguments.size () > 3)
{
throw invalid_argument ("Need 2 or 3 arguments");
}
string metaname = cl.arguments[1];
Key parentKey = cl.createKey (0);
string keyname = parentKey.getName ();
if (keyname[0] == '/')
{
// fix name for lookup
keyname = "spec" + keyname;
if (!cl.quiet) std::cout << "Using keyname " << keyname << std::endl;
// fix k for kdb.set later
parentKey.setName (keyname);
}
KeySet conf;
kdb.get (conf, parentKey);
Key k = conf.lookup (parentKey);
if (!k)
{
k = Key (keyname, KEY_END);
// k.setBinary(0, 0); // conceptually maybe better, but would have confusing "binary" metadata
conf.append (k);
if (cl.verbose) cout << "Creating key " << keyname << endl;
}
if (!k.isValid ())
{
cerr << "Could not create key " << keyname << endl;
return 1;
}
if (cl.arguments.size () == 2)
{
if (!cl.quiet) cout << "Only two arguments, thus deleting metaname " << metaname << endl;
k.delMeta (metaname);
}
else
{
std::string metavalue = cl.arguments[2];
if (metaname == "atime" || metaname == "mtime" || metaname == "ctime")
{
stringstream str (metavalue);
time_t t;
str >> t;
if (!str.good ()) throw "conversion failure";
k.setMeta<time_t> (metaname, t);
}
else
{
示例11: setMountpoint
void SpecMountCommand::setMountpoint (Cmdline const & cl)
{
if (cl.arguments.empty ())
{
throw invalid_argument ("you need to provide one argument: spec-mountpoint");
}
mp = cl.createKey (0).getName ();
if (mp.at (0) != '/')
{
throw invalid_argument (mp + " is not a cascading mountpoint");
}
}
示例12: DecideMove
Move
DecideMove(NodePtr& parent,
NodePtr& bestChild,
Position& currPosition, Piece::Color color,
Cmdline const & cmdline,
int & nLeavesEvaluated)
{
Trace t("DecideMove()");
Move bestMove;
double bestValue;
double alphaBetaPruneValue = g_bigval[color];
bestChild = parent->MinMaxValue(bestValue, &bestMove, currPosition,
cmdline.MaxDepth(),
alphaBetaPruneValue, nLeavesEvaluated);
return bestMove;
}
示例13: buildBackend
void SpecMountCommand::buildBackend (Cmdline const & cl)
{
SpecReader sr;
kdb::KeySet specToRead;
kdb.get (specToRead, "spec" + mp);
specToRead = specToRead.cut (Key ("spec" + mp, KEY_END));
sr.readSpecification (specToRead);
SpecReader::Backends const & backends = sr.getBackends ();
for (auto & p : backends)
{
auto backend = p.second;
if (cl.verbose)
{
std::cout << "Got mountpoint from " << p.first.getName () << " with " << backend.nodes
<< " nodes, configfile: " << backend.getConfigFile () << " and mountpoint: " << backend.getMountpoint ()
<< std::endl;
}
backend.setBackendConfig (cl.getPluginsConfig ("system/"));
backend.needPlugin (cl.resolver);
backend.needPlugin ("storage");
backend.addPlugins (parseArguments (cl.plugins));
const int alreadyRead = 1; // we already read mountpoint
if (cl.arguments.size () <= alreadyRead)
{
backend.addPlugins (parseArguments (cl.arguments.begin () + alreadyRead, cl.arguments.end ()));
}
// Call it a day
outputMissingRecommends (backend.resolveNeeds (cl.withRecommends));
Backends::umount (backend.getMountpoint (), mountConf);
backend.serialize (mountConf);
}
if (!cl.quiet && backends.empty ())
{
std::cout << "No metadata \"mountpoint\" found below spec" << mp << std::endl;
}
}
示例14: execute
int MetaLsCommand::execute (Cmdline const & cl)
{
int ret = 0;
if (cl.arguments.size () != 1)
{
throw invalid_argument ("1 argument required");
}
Key root = cl.createKey (0);
kdb.get (ks, root);
Key k = ks.lookup (root);
if (k)
{
if (cl.verbose)
{
std::cout << "Got key " << k.getName () << std::endl;
}
k.rewindMeta ();
while (const Key meta = k.nextMeta ())
{
cout << meta.getName ();
if (cl.null)
{
cout << '\0' << std::flush;
}
else
{
cout << endl;
}
}
}
else
{
std::cerr << "Did not find key" << std::endl;
ret = 1;
}
printWarnings (cerr, root);
return ret;
}
示例15: execute
int TestCommand::execute(Cmdline const& cl)
{
if (cl.arguments.size() < 1)
{
throw invalid_argument ("need at least one argument");
}
// do a basic check on every argument
for (size_t i=1; i<cl.arguments.size(); ++i)
{
string name = " ";
name += cl.arguments[i];
name += " ";
if (testNames.find(name) == std::string::npos)
{
throw invalid_argument ("test name " +
cl.arguments[i] +
" does not exist in:" +
testNames);
}
}
printWarnings(cerr, root);
root = cl.createKey(0);
KDB kdb;
KeySet original;
kdb.get(original, root);
original.rewind();
doTests(cl.arguments);
cerr << "We got " << nrError << " errors in " << nrTest << " testcases." << endl;
cout << "Test suite is now finished." << endl;
cout << "Now restoring the original keyset." << endl;
kdb.set(original, root);
printWarnings(cerr, root);
return nrError;
}