コード例 #1
0
Package* HelpCommandParser::constructPackageFromLine(int argc, const char **argv, std::string packageID)
{
	if(argc == 1)
	{
		std::cout<<"Possible commands are:"<<std::endl;
		for(std::map<std::string, CommandParser*>::iterator iter = commands->begin(); iter != commands->end(); iter++)
		{
			if(iter->second)
			{
				std::cout<<"\t"<<std::left<<std::setw(maxCommandNameLength)<<iter->second->getCommand()<<"\t"<<std::setw(0)<<iter->second->getDescription()<<std::endl;
			}
		}
	}
	else if(argc > 1)
	{
		CommandParser *parser = retrieveCommandParser(std::string(argv[1]));
		if(parser)
		{
			parser->printParameterHelp();
		}
		else
		{
			std::cout<<"help: the specified command doesn't exist"<<std::endl;
		}
	}
	return NULL;
}
コード例 #2
0
ファイル: Application.cpp プロジェクト: wws2003/Research
int main(int argc, char* argv[]) {
	mreal::initPrecision();
	mreal::initRand();

	CommandParser commandParser;
	initCommands(&commandParser);

	CommandFactory commandFactory;

	try {
		int commandCode = UNKNOWN_COMMAND;
		CommandParams commandParams;
		commandParser.getCommandCodeAndParams(argc, argv, commandCode, commandParams);

		ContextPtr pContext = Context::setup(DRY_MODE, ".3app");
		CommandPtr pCommand = commandFactory.getCommand(commandCode, commandParams);
		pCommand->execute();
		_destroy(pCommand);

		delete pContext;
	}
	catch(std::exception const& e) {
		std::cout << e.what() << std::endl;
		printSyntaxMessage();
	}
}
コード例 #3
0
ファイル: status.cpp プロジェクト: cawka/NFD
void
registerStatusCommands(CommandParser& parser)
{
  CommandDefinition defStatusReport("status", "report");
  defStatusReport
    .setTitle("print full status report")
    .addArg("format", ArgValueType::REPORT_FORMAT, Required::NO, Positional::YES);
  parser.addCommand(defStatusReport, &reportStatusComprehensive);

  CommandDefinition defStatusShow("status", "show");
  defStatusShow
    .setTitle("print general status");
  parser.addCommand(defStatusShow, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantForwarderGeneral));
  parser.addAlias("status", "show", "");

  CommandDefinition defChannelList("channel", "list");
  defChannelList
    .setTitle("print channel list");
  parser.addCommand(defChannelList, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantChannels));
  parser.addAlias("channel", "list", "");

  CommandDefinition defFibList("fib", "list");
  defFibList
    .setTitle("print FIB entries");
  parser.addCommand(defFibList, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantFib));
  parser.addAlias("fib", "list", "");

  CommandDefinition defCsInfo("cs", "info");
  defCsInfo
    .setTitle("print CS information");
  parser.addCommand(defCsInfo, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantCs));
  parser.addAlias("cs", "info", "");
}
コード例 #4
0
ファイル: completer.cpp プロジェクト: cfillion/island
void Completer::completeName(const CommandParser &parser)
{
  m_startIndex = parser.nameStart();
  m_endIndex = parser.nameEnd();

  const auto list = Command::findCommands(parser.name());

  for(const CommandEntry *entry : list) {
    addItem(entry->name);

    if(entry->hasFlag(CO_FORCE))
      addItem(entry->name + "!");
  }
}
コード例 #5
0
ファイル: dmiparser.cpp プロジェクト: mariusroets/Audit-Agent
void DMIParser::exec()
{
    bool readDescription = false;
    bool readFeatureList = true;
    std::string currentFeature = "";
    int currentIndex = -1;
    CommandParser *parser = CommandParser::Instance();
    std::stringstream o;
    o << "--type " << mType;
    parser->parse( "dmidecode", o.str(), true);
    std::vector<std::string> lines = parser->lines();
    parser->split(":");
    std::vector<std::vector<std::string> > fields = parser->fields();
    // Process the lines one by one
    for (unsigned int i = 0; i < lines.size() ; ++i) {
        if (readDescription) {
            mFrames[currentIndex].Description = lines[i];
            readDescription = false;
            continue;
        }
        if (lines[i].substr(0,6) == "Handle") {
            // Start new Frame
            Frame f;
            f.Handle = lines[i];
            mFrames.push_back(f);
            currentIndex++;
            readDescription = true;
            readFeatureList = false;
            continue;
        }
        if (currentIndex < 0)
            continue;
        if (lines[i].find(":") != std::string::npos) {
            readFeatureList = false;
        } else if (readFeatureList) {
            mFrames[currentIndex].FeatureData[currentFeature].push_back(lines[i]);
        }
        if (fields[i].size() == 2) {
            // Simple field
            readFeatureList = false;
            mFrames[currentIndex].Data[fields[i][0]] = fields[i][1];
        } else if (fields[i].size() == 1) {
            // Possible Feature list type field
            boost::trim(fields[i][0]);
            currentFeature = fields[i][0];
            readFeatureList = true;
        }

    }
}
コード例 #6
0
ファイル: main.cpp プロジェクト: saidinesh5/ModularMadness
int main()
{
    CommandParser commandParser;
    string input;

    while ( !cin.eof() )
    {
        getline( cin, input );
        if(!commandParser.parse( input ))
        {
            LOGME( "Error executing: "<< input << endl );
        }
    }
    return 0;
}
コード例 #7
0
ファイル: controller.cpp プロジェクト: profmaad/yonderboy
void Controller::parseSpecFile(std::string file)
{
	std::string expandedFilename;
	if(file[0] == '~')
	{
		file.erase(0,1);
		expandedFilename = std::string(getenv("HOME"));
		expandedFilename += file;
	}
	else
	{
		expandedFilename = file;
	}

	std::ifstream specFile(expandedFilename.c_str());
	
	if(!specFile.fail())
	{
		YAML::Parser specParser(specFile);
		YAML::Node specDoc;
		specParser.GetNextDocument(specDoc);
		
		for(int i=0; i<specDoc["commands"].size(); i++)
		{
			if(specDoc["commands"][i]["command"].GetType() == YAML::CT_SCALAR && specDoc["commands"][i]["source"].GetType() == YAML::CT_SEQUENCE)
			{
				std::string command;
				specDoc["commands"][i]["command"] >> command;
				
				// lets check whether this command is for us
				for(int s=0; s<specDoc["commands"][i]["source"].size(); s++)
				{
					std::string source;
					specDoc["commands"][i]["source"][s] >> source;
					
					if(source == "controller")
					{
						CommandParser *parser = new CommandParser(specDoc["commands"][i]);
						commands->insert(std::make_pair(command, parser));

						if(parser->getCommand().length() > maxCommandNameLength)
						{
							maxCommandNameLength = parser->getCommand().length();
						}
					}
				}
			}
		}
コード例 #8
0
void
registerLegacyStatusCommand(CommandParser& parser)
{
  CommandDefinition defLegacyNfdStatus("legacy-nfd-status", "");
  defLegacyNfdStatus
    .addArg("args", ArgValueType::ANY, Required::NO, Positional::YES);
  parser.addCommand(defLegacyNfdStatus, &legacyNfdStatus, AVAILABLE_IN_ALL & ~AVAILABLE_IN_HELP);
}
コード例 #9
0
void MacSoftware::read()
{
    Util::exec("pkgutil --package > /tmp/pkgutil.txt");
    CommandParser *c = CommandParser::Instance();
    c->parse("cat", "/tmp/pkgutil.txt");
    vector<string> lines = c->lines();
    for (int i = 0; i < (int)lines.size(); i++) {
        mSoftwareList.push_back(SoftwarePackage());
        mSoftwareList[i].name = lines[i];
        c->parse("pkgutil", "--pkg-info " + lines[i]);
        vector<string> lines2 = c->lines();
        c->split(":");
        vector<vector<string> > fields = c->fields();
        for (int j = 0; j < (int)lines2.size(); j++) {
            if (fields[j][0] == "version") {
                mSoftwareList[i].version = fields[j][1];
            }
            if (fields[j][0] == "install-time") {
                //TODO: Format the time which is a time_t to a string
                // and poplulate mSoftwareList[i].install_time
                //mSoftwareList[i].install_time = fields[j][1];
            }

        }
    }
}
コード例 #10
0
ファイル: kernel.cpp プロジェクト: ZakharBondia/AnOs
#include <idt.h>
#include <gdt.h>
#include <isrs.h>
#include <timer.h>
#include <irq.h>
#include "keyboard.h"
#include <terminal.h>
#include <Array.h>
#include <commandparser.h>
#include <system.h>
#include <vector.h>
#include "printf.h"
#include "types.h"
#include "callrealmode.h"
#include "multiboot.h"
#include "fat_filelib.h"
#include "filesystem.h"
#include "heap.h"
#include "std/string.h"
#include "include/assert.h"

extern "C" /* Use C link age for kernel_main. */
    void
    kernel_main()
{
    Terminal::install(Terminal::VgaColor::Blue, Terminal::VgaColor::Cyan);
    GDT::install();
    IDT::install();
    ISRs::install();
    IRQ::install();
    Timer::install();
    Keyboard::install();
    FileSystem::install();
    Heap::install();

    CommandParser commandParser;
    commandParser.start();

    ENDLESS_LOOP;
}
コード例 #11
0
ファイル: execute-command-fixture.hpp プロジェクト: cawka/NFD
  void
  execute(const std::string& cmd)
  {
    std::vector<std::string> args;
    boost::split(args, cmd, boost::is_any_of(" "));

    CommandParser parser;
    registerCommands(parser);

    std::string noun, verb;
    CommandArguments ca;
    ExecuteCommand execute;
    std::tie(noun, verb, ca, execute) = parser.parse(args, ParseMode::ONE_SHOT);

    Controller controller(face, m_keyChain);
    ExecuteContext ctx{noun, verb, ca, 0, out, err, face, m_keyChain, controller};
    execute(ctx);
    exitCode = ctx.exitCode;
  }
コード例 #12
0
ファイル: parser_test.cpp プロジェクト: XiaominZhang/raf
TEST(parser, parseToCmd) {

  std::string storeConfig = "services/store/test/data_store.conf";
  ResultCode code = ::idgs::util::singleton<DataStore>::getInstance().initialize(storeConfig);

  //string insert_cmd = "store.service insert {\"store_name\":\"Customer\"} key={\"c_custkey\":\"234000\"} value={\"c_name\":\"Tom0\",\"c_nationkey\":\"10\",\"c_phone\":\"13500000000\"}";
  string insert_cmd = "store.service insert {\"store_name\":\"Orders\"} key={\"o_orderkey\":\"100000\"} value={\"o_custkey\":\"234000\",\"o_orderstatus\":\"2\",\"o_totalprice\":\"200.55\",\"o_orderdate\":\"2013-02-01\"}";

  CommandParser parser;
  Command command;
  code = parser.parse(insert_cmd, &command);
  ASSERT_EQ(RC_SUCCESS, code);
  ASSERT_EQ("store.service", command.actorId);
  ASSERT_EQ("insert", command.opName);
  ASSERT_EQ("{\"store_name\":\"Orders\"}", command.payload);
/*  for(auto it = command.attachments.begin(); it!=command.attachments.end(); ++it) {
    LOG(INFO) << "get Attachment " << it->first << " | " << it->second;
  }*/
}
コード例 #13
0
void HistoryHandler::addEvent (CommandParser& test)
{
	int index = masterList[0].dateDifference(test.getDateObj());
	if (masterList.size()<=index)
		fillDates(index);
	
	masterList[index].addEvent(	test.getId(), 
								test.getInputName(), 
								test.getInputLocation(), 
								test.getStartTimeObj(), 
								test.getEndTimeObj(), 
								test.getInputEventType(), 
								test.getEventStatus());	
}
コード例 #14
0
void CommandCC110LPrint::parse(CommandParser & cmdParser) {
	//bool           boolParam;
	//float          floatParam;
	//double         doubleParam;
	//int            intParam;
	//unsigned int   uintParam;
	//std::string    stringParam;

	// default value true
	this->mExecutable = true;

	// test reversed
	cmdParser.read("-", this->mWhat);
}
コード例 #15
0
ファイル: linuxos.cpp プロジェクト: mariusroets/Audit-Agent
void LinuxOS::read()
{

    mName = Util::exec("uname -s");
    boost::trim(mName);
    std::string kernel = Util::exec("uname -r");
    boost::trim(kernel);
    std::vector<std::string> tokens;
    boost::split(tokens, kernel, boost::is_any_of("."));
    mMajorVersion = tokens[0];
    mMinorVersion = tokens[1];
    mBuild = tokens[2];


    CommandParser *c = CommandParser::Instance();
    c->parse("lsb_release", " -a");
    c->split(":");
    std::vector<std::vector<std::string> > fields2 = c->fields();
    for (unsigned int i = 0; i < fields2.size() ; ++i) {
        if (fields2[i].size() <= 0)
            continue;
        if (fields2[i][0] == "Description") {
            mName = fields2[i][1];
        }
        if (fields2[i][0] == "Release") {
            mMajorVersion = fields2[i][1];
            mMinorVersion = "";
            mBuild = kernel;
        }
    }

    c->parse("cat", "/etc/*-release");
    c->split("=");
    std::vector<std::vector<std::string> > fields = c->fields();
    for (unsigned int i = 0; i < fields.size() ; ++i) {
        if (fields[i].size() <= 0)
            continue;
        if (fields[i][0] == "PATCHLEVEL") {
            mMinorVersion = fields[i][1];
        }
    }
    
    /*
     * Slackware: /etc/slackware-version
Mandrake: /etc/mandrake-release
Red Hat: /etc/redhat-release
Fedora: /etc/fedora-release
Suse :  /etc/SuSE-release
United : /etc/UnitedLinux-release
Debian : /etc/debian_version
*/
}
コード例 #16
0
ファイル: cmdtest.cpp プロジェクト: JasonXsy/TextAdventure
int main()
{
  std::string str;
  CommandParser cp;
  std::string response;

  std::cout<<response <<std::endl;
  while(1){
    std::cout << "enter a command: ";
    std::getline(std::cin, str);
    response = cp.processCommand(str);
    // std::cout<<"getting response.."<<std::endl;
    std::cout<<response<<std::endl;
  }

  // std::vector<std::string> tokenized_stuff = cp.tokenizeInput(str);
  // for(std::vector<std::string>::iterator itr = tokenized_stuff.begin(); itr != tokenized_stuff.end(); ++itr){
  //   std::cout<< *itr<< " ";
  //   std::cout<< std::endl;
  // }
  /*check the first word == the words in enum*/
  // std::cout<< isMatch(tokenized_stuff[0]);
  return EXIT_SUCCESS;
}
コード例 #17
0
void HistoryHandler::deleteEvent (CommandParser& test)
{
	int displayIndex, i;
		
	displayIndex=atoi(test.getInputIndex().c_str());
	string eventId = displayList[displayIndex-1].getId();
	string date=eventId.substr(0,8);
	Date dateObj=masterList[0].dateStringToObject(date);
	int dateIndex=masterList[0].dateDifference(dateObj);
	int indexToDelete=masterList[dateIndex].getIndex(eventId);
			
	commandOrder.push("Delete");
	eventOrder.push(masterList[dateIndex].getEvent(indexToDelete));
	masterList[dateIndex].deleteEvent(indexToDelete);
}
コード例 #18
0
void HistoryHandler::showEvents (CommandParser test)
{
	Date date;
	if (test.hasName())
	{
		displayList.clear();
		searchInputParameter(test.getInputName(), "name");
	}
	
	else if (test.hasDate())
	{
		showParticularDate(test.getDateObj());
	}

	else if (test.hasLocation())
	{
		displayList.clear();
		searchInputParameter(test.getInputLocation(), "location");
	}
}
コード例 #19
0
ファイル: main.cpp プロジェクト: xaanimus/emacs_config
int main(int ac, const char *av[]) {
    std::vector<std::string> argv(&av[1], &av[ac]);

    // stick to STL streams, no mix of C and C++ for IO operations
    std::ios_base::sync_with_stdio(false);

    bool interactiveMode = false;

    Irony irony;

    if (ac == 1) {
        printHelp();
        return 1;
    }

    std::ofstream logFile;

    // When logging to a specific file, std::clog.rdbuf() is replaced by the log
    // file's one. When we return from the main, this buffer is deleted (at the
    // same time as logFile) but std::clog is still active, and will try to
    // release the rdbuf() which has already been released in logFile's
    // destructor. To avoid this we restore std::clog()'s original rdbuf on exit.
    RestoreClogOnExit clogBufferRestorer;

    unsigned optCount = 0;
    while (optCount < argv.size()) {
        const std::string &opt = argv[optCount];

        if (opt.c_str()[0] != '-')
            break;

        if (opt == "--help" || opt == "-h") {
            printHelp();
            return 0;
        }

        if (opt == "--version" || opt == "-v") {
            printVersion();
            return 0;
        }

        if (opt == "--interactive" || opt == "-i") {
            interactiveMode = true;
        } else if (opt == "--debug" || opt == "-d") {
            irony.setDebug(true);
        } else if (opt == "--log-file" && (optCount + 1) < argv.size()) {
            ++optCount;
            logFile.open(argv[optCount]);
            std::clog.rdbuf(logFile.rdbuf());
        } else {
            std::cerr << "error: invalid option '" << opt << "'\n";
            return 1;
        }

        ++optCount;
    }

    argv.erase(argv.begin(), argv.begin() + optCount);

    CommandParser commandParser;
    std::unique_ptr<CommandProviderInterface> commandProvider;

    if (interactiveMode) {
        commandProvider.reset(new InteractiveCommandProvider());
    } else {
        commandProvider.reset(new CommandLineCommandProvider(argv));
    }

    while (Command *c = commandParser.parse(commandProvider->nextCommand())) {
        if (c->action != Command::Exit) {
            std::clog << "execute: " << *c << std::endl;

            if (irony.isDebugEnabled()) {
                dumpUnsavedFiles(*c);
            }
        }

        switch (c->action) {
        case Command::Help:
            printHelp();
            break;

        case Command::Diagnostics:
            irony.diagnostics();
            break;

        case Command::Complete:
            irony.complete(c->file, c->line, c->column, c->flags, c->cxUnsavedFiles);
            break;

        case Command::Exit:
            return 0;

        case Command::Parse:
            irony.parse(c->file, c->flags, c->cxUnsavedFiles);
            break;

        case Command::SetDebug:
            irony.setDebug(c->opt);
            break;

        case Command::GetCompileOptions:
            irony.getCompileOptions(c->dir, c->file);
            break;

        case Command::Unknown:
            assert(0 && "unreacheable code...reached!");
            break;
        }

        std::cout << "\n;;EOT\n" << std::flush;
    }

    return 1;
}
コード例 #20
0
ファイル: completer.cpp プロジェクト: cfillion/island
void Completer::completeArgument(const CommandParser &parser)
{
  m_startIndex = parser.argumentStart();
  m_endIndex = parser.argumentEnd();
}
コード例 #21
0
void HistoryHandler::editEvent (CommandParser& test)
{
	int displayIndex=atoi(test.getInputIndex().c_str());
	if(displayIndex>displayList.size())
		throw TempusException(TempusException::INVALID_INDEX_EXCEPTION);
	if(!test.hasWords())
		throw TempusException(TempusException::INVALID_EDIT_EXCEPTION, "No Details Entered");
	if(!test.hasDate())
		throw TempusException(TempusException::INVALID_EDIT_EXCEPTION, "Only Date Can Be Edited In Archive");
	string id = displayList[displayIndex-1].getId();
	string date=id.substr(0,8);
	Date dateObj=masterList[0].dateStringToObject(date);
	int dateIndex=masterList[0].dateDifference(dateObj);
	int indexToEdit=masterList[dateIndex].getIndex(id);

	assert(indexToEdit!=-1);

	Event eventObj2 = masterList[dateIndex].getEvent(indexToEdit);
	if (test.hasTime() && !test.hasDate())
		throw TempusException(TempusException::INVALID_EDIT_EXCEPTION, "Cannot Edit Time In Archive");
	deleteEvent(test);
		
	stringstream input;
	input << eventObj2.getName();
	if (eventObj2.getLocation()!="")
		input << " Location " << eventObj2.getLocation();
	input << " Date " << test.getInputDate();
	if (eventObj2.getEventType()!="d")
		input << " Time ";
	else
		input << " By ";
	
	if (test.hasTime())
		input << test.getStartTimeObj().formatCompleteTime(test.getEndTimeObj());
	else
		input  << eventObj2.getStartTime().formatCompleteTime(eventObj2.getEndTime());

	test.setStatus(eventObj2.getEventStatus());
	test.setInputDetails(input.str());
}
コード例 #22
0
void Console::register_save_commands()
{
	CommandParser saveParser;
	saveParser.register_command("level", save_level());
	register_command("save", saveParser);
}