tool/main.cpp
changeset 1151 1fc1535dec29
parent 1144 7dbfdd61812c
child 1158 f65164fa4a58
equal deleted inserted replaced
1150:c589b54ade01 1151:1fc1535dec29
    39 Command::StringVector commandArgs;
    39 Command::StringVector commandArgs;
    40 
    40 
    41 // option variables
    41 // option variables
    42 unsigned int masterIndex = 0;
    42 unsigned int masterIndex = 0;
    43 int slavePosition = -1;
    43 int slavePosition = -1;
       
    44 int slaveAlias = -1;
    44 int domainIndex = -1;
    45 int domainIndex = -1;
    45 string dataTypeStr;
    46 string dataTypeStr;
    46 Command::Verbosity verbosity = Command::Normal;
    47 Command::Verbosity verbosity = Command::Normal;
    47 bool force = false;
    48 bool force = false;
    48 bool helpRequested = false;
    49 bool helpRequested = false;
    96 {
    97 {
    97     int c, argCount, optionIndex, number;
    98     int c, argCount, optionIndex, number;
    98 	char *remainder;
    99 	char *remainder;
    99 
   100 
   100     static struct option longOptions[] = {
   101     static struct option longOptions[] = {
   101         //name,     has_arg,           flag, val
   102         //name,      has_arg,           flag, val
   102         {"master",  required_argument, NULL, 'm'},
   103         {"master",   required_argument, NULL, 'm'},
   103         {"slave",   required_argument, NULL, 's'},
   104         {"alias",    required_argument, NULL, 'a'},
   104         {"domain",  required_argument, NULL, 'd'},
   105         {"position", required_argument, NULL, 'p'},
   105         {"type",    required_argument, NULL, 't'},
   106         {"domain",   required_argument, NULL, 'd'},
   106         {"force",   no_argument,       NULL, 'f'},
   107         {"type",     required_argument, NULL, 't'},
   107         {"quiet",   no_argument,       NULL, 'q'},
   108         {"force",    no_argument,       NULL, 'f'},
   108         {"verbose", no_argument,       NULL, 'v'},
   109         {"quiet",    no_argument,       NULL, 'q'},
   109         {"help",    no_argument,       NULL, 'h'},
   110         {"verbose",  no_argument,       NULL, 'v'},
       
   111         {"help",     no_argument,       NULL, 'h'},
   110         {}
   112         {}
   111     };
   113     };
   112 
   114 
   113     do {
   115     do {
   114         c = getopt_long(argc, argv, "m:s:d:t:fqvh", longOptions, &optionIndex);
   116         c = getopt_long(argc, argv, "m:a:p:d:t:fqvh",
       
   117                 longOptions, &optionIndex);
   115 
   118 
   116         switch (c) {
   119         switch (c) {
   117             case 'm':
   120             case 'm':
   118                 number = strtoul(optarg, &remainder, 0);
   121                 number = strtoul(optarg, &remainder, 0);
   119                 if (remainder == optarg || *remainder || number < 0) {
   122                 if (remainder == optarg || *remainder || number < 0) {
   122                     exit(1);
   125                     exit(1);
   123                 }
   126                 }
   124 				masterIndex = number;
   127 				masterIndex = number;
   125                 break;
   128                 break;
   126 
   129 
   127             case 's':
   130             case 'a':
       
   131                 if (!strcmp(optarg, "all")) {
       
   132                     slaveAlias = -1;
       
   133                 } else {
       
   134                     number = strtoul(optarg, &remainder, 0);
       
   135                     if (remainder == optarg || *remainder
       
   136                             || number < 0 || number > 0xFFFF) {
       
   137                         cerr << "Invalid slave alias " << optarg << "!"
       
   138                             << endl << endl << usage();
       
   139                         exit(1);
       
   140                     }
       
   141                     slaveAlias = number;
       
   142                 }
       
   143                 break;
       
   144 
       
   145             case 'p':
   128                 if (!strcmp(optarg, "all")) {
   146                 if (!strcmp(optarg, "all")) {
   129                     slavePosition = -1;
   147                     slavePosition = -1;
   130                 } else {
   148                 } else {
   131                     number = strtoul(optarg, &remainder, 0);
   149                     number = strtoul(optarg, &remainder, 0);
   132                     if (remainder == optarg || *remainder
   150                     if (remainder == optarg || *remainder
   263         if (matchingCommands.size() == 1) {
   281         if (matchingCommands.size() == 1) {
   264             cmd = matchingCommands.front();
   282             cmd = matchingCommands.front();
   265             if (!helpRequested) {
   283             if (!helpRequested) {
   266                 try {
   284                 try {
   267                     cmd->setVerbosity(verbosity);
   285                     cmd->setVerbosity(verbosity);
       
   286                     cmd->setAlias(slaveAlias);
       
   287                     cmd->setPosition(slavePosition);
   268                     cmd->execute(masterDev, commandArgs);
   288                     cmd->execute(masterDev, commandArgs);
   269                 } catch (InvalidUsageException &e) {
   289                 } catch (InvalidUsageException &e) {
   270                     cerr << e.what() << endl << endl;
   290                     cerr << e.what() << endl << endl;
   271                     cerr << binaryBaseName << " " << cmd->helpString();
   291                     cerr << binaryBaseName << " " << cmd->helpString();
   272                     retval = 1;
   292                     retval = 1;