Changeset 34338 in vbox
- Timestamp:
- Nov 24, 2010 7:54:45 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp
r34337 r34338 1217 1217 return errorSyntax(USAGE_GUESTCONTROL, "Incorrect parameters"); 1218 1218 1219 static const RTGETOPTDEF s_aOptions[] = 1220 { 1221 //{ "--flags", 'f', RTGETOPT_REQ_STRING }, 1222 { "--mode", 'm', RTGETOPT_REQ_UINT32 }, 1223 { "--parents", 'P', RTGETOPT_REQ_NOTHING }, 1224 { "--password", 'p', RTGETOPT_REQ_STRING }, 1225 { "--username", 'u', RTGETOPT_REQ_STRING }, 1226 { "--verbose", 'v', RTGETOPT_REQ_NOTHING } 1227 }; 1228 1229 int ch; 1230 RTGETOPTUNION ValueUnion; 1231 RTGETOPTSTATE GetState; 1232 RTGetOptInit(&GetState, a->argc, a->argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0); 1233 1219 1234 Utf8Str Utf8Directory(a->argv[1]); 1220 1235 Utf8Str Utf8UserName; … … 1223 1238 uint32_t uMode = 0; 1224 1239 bool fVerbose = false; 1225 /** @todo r=bird: Use RTGetOpt here, no new code using strcmp-if-switching! */ 1226 1227 /* Iterate through all possible commands (if available). */ 1228 bool usageOK = true; 1229 for (int i = 3; usageOK && i < a->argc; i++) 1230 { 1231 if ( !strcmp(a->argv[i], "--username") 1232 || !strcmp(a->argv[i], "--user")) 1233 { 1234 if (i + 1 >= a->argc) 1235 usageOK = false; 1236 else 1237 { 1238 Utf8UserName = a->argv[i + 1]; 1239 ++i; 1240 } 1241 } 1242 else if ( !strcmp(a->argv[i], "--password") 1243 || !strcmp(a->argv[i], "--pwd")) 1244 { 1245 if (i + 1 >= a->argc) 1246 usageOK = false; 1247 else 1248 { 1249 Utf8Password = a->argv[i + 1]; 1250 ++i; 1251 } 1252 } 1253 else if ( !strcmp(a->argv[i], "--parents") 1254 || !strcmp(a->argv[i], "-p")) 1255 { 1256 uFlags |= CreateDirectoryFlag_Parents; 1257 } 1258 else if ( !strcmp(a->argv[i], "--mode") 1259 || !strcmp(a->argv[i], "-m")) 1260 { 1261 if (i + 1 >= a->argc 1262 || RTStrToUInt32Full(a->argv[i + 1], 8 /* Base, octal */, &uMode) != VINF_SUCCESS) 1263 usageOK = false; 1264 else 1265 { 1266 ++i; 1267 } 1268 } 1269 else if (!strcmp(a->argv[i], "--flags")) 1270 { 1271 if (i + 1 >= a->argc) 1272 usageOK = false; 1273 else 1274 { 1240 1241 int vrc = VINF_SUCCESS; 1242 bool fUsageOK = true; 1243 while ( (ch = RTGetOpt(&GetState, &ValueUnion)) 1244 && RT_SUCCESS(vrc)) 1245 { 1246 /* For options that require an argument, ValueUnion has received the value. */ 1247 switch (ch) 1248 { 1249 case 'f': /* Flags */ 1275 1250 /* Nothing to do here yet. */ 1276 ++i; 1277 } 1278 } 1279 else if (!strcmp(a->argv[i], "--verbose")) 1280 fVerbose = true; 1281 else 1282 return errorSyntax(USAGE_GUESTCONTROL, 1283 "Invalid parameter '%s'", Utf8Str(a->argv[i]).c_str()); 1284 } 1285 1286 if (!usageOK) 1251 break; 1252 1253 case 'm': /* Mode */ 1254 uMode = ValueUnion.u32; 1255 break; 1256 1257 case 'P': /* Create parents */ 1258 uFlags |= CreateDirectoryFlag_Parents; 1259 break; 1260 1261 case 'p': /* Password */ 1262 Utf8Password = ValueUnion.psz; 1263 break; 1264 1265 case 'u': /* User name */ 1266 Utf8UserName = ValueUnion.psz; 1267 break; 1268 1269 case 'v': /* Verbose */ 1270 fVerbose = true; 1271 break; 1272 1273 case VINF_GETOPT_NOT_OPTION: 1274 { 1275 Utf8Directory = ValueUnion.psz; 1276 break; 1277 } 1278 1279 default: 1280 return RTGetOptPrintError(ch, &ValueUnion); 1281 } 1282 } 1283 1284 if (!fUsageOK) 1287 1285 return errorSyntax(USAGE_GUESTCONTROL, "Incorrect parameters"); 1288 1286 1289 1287 if (Utf8Directory.isEmpty()) 1290 1288 return errorSyntax(USAGE_GUESTCONTROL, 1291 "No directory specified!");1289 "No directory to create specified!"); 1292 1290 1293 1291 if (Utf8UserName.isEmpty()) … … 1297 1295 HRESULT rc = S_OK; 1298 1296 ComPtr<IGuest> guest; 1299 intvrc = ctrlInitVM(a, a->argv[0] /* VM Name */, &guest);1297 vrc = ctrlInitVM(a, a->argv[0] /* VM Name */, &guest); 1300 1298 if (RT_SUCCESS(vrc)) 1301 1299 { … … 1489 1487 1490 1488 /* switch (cmd) */ 1491 if ( ! strcmp(a->argv[0], "exec")1492 || ! strcmp(a->argv[0], "execute"))1489 if ( !RTStrICmp(a->argv[0], "exec") 1490 || !RTStrICmp(a->argv[0], "execute")) 1493 1491 { 1494 1492 return handleCtrlExecProgram(&arg); 1495 1493 } 1496 else if ( ! strcmp(a->argv[0], "copyto")1497 || ! strcmp(a->argv[0], "cp"))1494 else if ( !RTStrICmp(a->argv[0], "copyto") 1495 || !RTStrICmp(a->argv[0], "cp")) 1498 1496 { 1499 1497 return handleCtrlCopyTo(&arg); 1500 1498 } 1501 else if ( ! strcmp(a->argv[0], "createdirectory")1502 || ! strcmp(a->argv[0], "createdir")1503 || ! strcmp(a->argv[0], "mkdir")1504 || ! strcmp(a->argv[0], "md"))1499 else if ( !RTStrICmp(a->argv[0], "createdirectory") 1500 || !RTStrICmp(a->argv[0], "createdir") 1501 || !RTStrICmp(a->argv[0], "mkdir") 1502 || !RTStrICmp(a->argv[0], "md")) 1505 1503 { 1506 1504 return handleCtrlCreateDirectory(&arg); 1507 1505 } 1508 else if ( ! strcmp(a->argv[0], "updateadditions")1509 || ! strcmp(a->argv[0], "updateadds"))1506 else if ( !RTStrICmp(a->argv[0], "updateadditions") 1507 || !RTStrICmp(a->argv[0], "updateadds")) 1510 1508 { 1511 1509 return handleCtrlUpdateAdditions(&arg);
Note:
See TracChangeset
for help on using the changeset viewer.