lasync命令模块实用工具cmdutils

来源:互联网 发布:吉林大学网络教育电话 编辑:程序博客网 时间:2024/06/05 06:02
//cmdutils.cpp#include <iostream>#include "cmdutils.h"int LaCmdUtils::parse_args(int argc, char** argv, char* args, int& cmd, std::string& dest){    int opt = 0;    while((opt = getopt(argc, argv, args)) != -1)    {        switch(opt)        {            //file sync            case 'f':                cmd |= 1;                break;            //package install            case 'p':                cmd |= 1<< 1;                break;            //upgrade            case 'u':                cmd |= 1<< 2;                break;            //node list            case 'm':                dest = optarg;                break;            //argument error, show error message            default:                LaCmdUtils::usage();                return -1;        }    }    return 0;}void LaCmdUtils::usage(){    const char* usage = "\t-f:synchronize file\n\t-p:synchronize package\                         \n\t-u:upgrade package\n\t-m:node list to do above \                         actions, if no -m all node will be synchronized\n";    cerr << usage << endl;}

测试代码:

//utcmdutils.cpp#include <iostream>using namespace std;#include "../lib/cmdutils.h"int main(int argc, char** argv){    int cmd = 0;    std::string dest;    LaCmdUtils::parse_args(argc, argv, "fpum:", cmd, dest);    cout << cmd << endl;    cout << dest << endl;    return 0;}

测试结果
这里写图片描述


源码见https://github.com/zhangzhuo233/lasync

1 0
原创粉丝点击