Changeset 94240 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Mar 15, 2022 10:10:24 AM (3 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
r93115 r94240 36 36 #include <VBox/sup.h> 37 37 #include <VBox/log.h> 38 38 #include <VBox/version.h> 39 40 #include <iprt/buildconfig.h> 39 41 #include <iprt/ctype.h> 40 42 #include <iprt/file.h> … … 131 133 } HOSTPARTITIONS, *PHOSTPARTITIONS; 132 134 133 /** flag whether we're in internal mode */134 bool g_fInternalMode;135 135 136 136 /** 137 137 * Print the usage info. 138 138 */ 139 void printUsageInternal(USAGECATEGORY enmCommand, PRTSTREAM pStrm)139 static void printUsageInternal(USAGECATEGORY enmCommand, PRTSTREAM pStrm) 140 140 { 141 141 Assert(enmCommand != USAGE_INVALID); … … 288 288 } 289 289 290 291 /** 292 * Print a usage synopsis and the syntax error message. 293 * @returns RTEXITCODE_SYNTAX. 294 */ 295 static RTEXITCODE errorSyntaxInternal(USAGECATEGORY enmCommand, const char *pszFormat, ...) 296 { 297 va_list args; 298 showLogo(g_pStdErr); // show logo even if suppressed 299 300 printUsageInternal(enmCommand, g_pStdErr); 301 302 va_start(args, pszFormat); 303 RTStrmPrintf(g_pStdErr, Internal::tr("\nSyntax error: %N\n"), pszFormat, &args); 304 va_end(args); 305 return RTEXITCODE_SYNTAX; 306 } 307 308 309 /** 310 * errorSyntaxInternal for RTGetOpt users. 311 * 312 * @returns RTEXITCODE_SYNTAX. 313 * 314 * @param enmCommand The command. 315 * @param rc The RTGetOpt return code. 316 * @param pValueUnion The value union. 317 */ 318 static RTEXITCODE errorGetOptInternal(USAGECATEGORY enmCommand, int rc, union RTGETOPTUNION const *pValueUnion) 319 { 320 /* 321 * Check if it is an unhandled standard option. 322 */ 323 if (rc == 'V') 324 { 325 RTPrintf("%sr%d\n", VBOX_VERSION_STRING, RTBldCfgRevision()); 326 return RTEXITCODE_SUCCESS; 327 } 328 329 if (rc == 'h') 330 { 331 showLogo(g_pStdErr); 332 printUsageInternal(enmCommand, g_pStdOut); 333 return RTEXITCODE_SUCCESS; 334 } 335 336 /* 337 * General failure. 338 */ 339 showLogo(g_pStdErr); // show logo even if suppressed 340 341 printUsageInternal(enmCommand, g_pStdErr); 342 343 if (rc == VINF_GETOPT_NOT_OPTION) 344 return RTMsgErrorExit(RTEXITCODE_SYNTAX, Internal::tr("Invalid parameter '%s'"), pValueUnion->psz); 345 if (rc > 0) 346 { 347 if (RT_C_IS_PRINT(rc)) 348 return RTMsgErrorExit(RTEXITCODE_SYNTAX, Internal::tr("Invalid option -%c"), rc); 349 return RTMsgErrorExit(RTEXITCODE_SYNTAX, Internal::tr("Invalid option case %i"), rc); 350 } 351 if (rc == VERR_GETOPT_UNKNOWN_OPTION) 352 return RTMsgErrorExit(RTEXITCODE_SYNTAX, Internal::tr("Unknown option: %s"), pValueUnion->psz); 353 if (rc == VERR_GETOPT_INVALID_ARGUMENT_FORMAT) 354 return RTMsgErrorExit(RTEXITCODE_SYNTAX, Internal::tr("Invalid argument format: %s"), pValueUnion->psz); 355 if (pValueUnion->pDef) 356 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "%s: %Rrs", pValueUnion->pDef->pszLong, rc); 357 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "%Rrs", rc); 358 } 359 360 290 361 /** @todo this is no longer necessary, we can enumerate extra data */ 291 362 /** … … 650 721 uuidType = HDUUID; 651 722 if (argc != 3 && argc != 2) 652 return errorSyntax (USAGE_I_SETHDUUID, Internal::tr("Not enough parameters"));723 return errorSyntaxInternal(USAGE_I_SETHDUUID, Internal::tr("Not enough parameters")); 653 724 /* if specified, take UUID, otherwise generate a new one */ 654 725 if (argc == 3) 655 726 { 656 727 if (RT_FAILURE(RTUuidFromStr(&rtuuid, argv[2]))) 657 return errorSyntax (USAGE_I_SETHDUUID, Internal::tr("Invalid UUID parameter"));728 return errorSyntaxInternal(USAGE_I_SETHDUUID, Internal::tr("Invalid UUID parameter")); 658 729 uuid = argv[2]; 659 730 } else … … 664 735 uuidType = HDPARENTUUID; 665 736 if (argc != 3) 666 return errorSyntax (USAGE_I_SETHDPARENTUUID, Internal::tr("Not enough parameters"));737 return errorSyntaxInternal(USAGE_I_SETHDPARENTUUID, Internal::tr("Not enough parameters")); 667 738 if (RT_FAILURE(RTUuidFromStr(&rtuuid, argv[2]))) 668 return errorSyntax (USAGE_I_SETHDPARENTUUID, Internal::tr("Invalid UUID parameter"));739 return errorSyntaxInternal(USAGE_I_SETHDPARENTUUID, Internal::tr("Invalid UUID parameter")); 669 740 uuid = argv[2]; 670 741 } 671 742 else 672 return errorSyntax (USAGE_I_SETHDUUID, Internal::tr("Invalid invocation"));743 return errorSyntaxInternal(USAGE_I_SETHDUUID, Internal::tr("Invalid invocation")); 673 744 674 745 /* just try it */ … … 722 793 if (argc != 1) 723 794 { 724 return errorSyntax (USAGE_I_DUMPHDINFO, Internal::tr("Not enough parameters"));795 return errorSyntaxInternal(USAGE_I_DUMPHDINFO, Internal::tr("Not enough parameters")); 725 796 } 726 797 … … 1116 1187 else 1117 1188 { 1118 return errorSyntax (USAGE_I_LISTPARTITIONS, Internal::tr("Invalid parameter '%s'"), argv[i]);1189 return errorSyntaxInternal(USAGE_I_LISTPARTITIONS, Internal::tr("Invalid parameter '%s'"), argv[i]); 1119 1190 } 1120 1191 } 1121 1192 1122 1193 if (rawdisk.isEmpty()) 1123 return errorSyntax (USAGE_I_LISTPARTITIONS, Internal::tr("Mandatory parameter -rawdisk missing"));1194 return errorSyntaxInternal(USAGE_I_LISTPARTITIONS, Internal::tr("Mandatory parameter -rawdisk missing")); 1124 1195 1125 1196 RTFILE hRawFile; … … 1233 1304 #endif /* RT_OS_LINUX || RT_OS_FREEBSD */ 1234 1305 else 1235 return errorSyntax (USAGE_I_CREATERAWVMDK, Internal::tr("Invalid parameter '%s'"), argv[i]);1306 return errorSyntaxInternal(USAGE_I_CREATERAWVMDK, Internal::tr("Invalid parameter '%s'"), argv[i]); 1236 1307 } 1237 1308 1238 1309 if (filename.isEmpty()) 1239 return errorSyntax (USAGE_I_CREATERAWVMDK, Internal::tr("Mandatory parameter -filename missing"));1310 return errorSyntaxInternal(USAGE_I_CREATERAWVMDK, Internal::tr("Mandatory parameter -filename missing")); 1240 1311 if (rawdisk.isEmpty()) 1241 return errorSyntax (USAGE_I_CREATERAWVMDK, Internal::tr("Mandatory parameter -rawdisk missing"));1312 return errorSyntaxInternal(USAGE_I_CREATERAWVMDK, Internal::tr("Mandatory parameter -rawdisk missing")); 1242 1313 if (!pszPartitions && pszMBRFilename) 1243 return errorSyntax (USAGE_I_CREATERAWVMDK,1314 return errorSyntaxInternal(USAGE_I_CREATERAWVMDK, 1244 1315 Internal::tr("The parameter -mbr is only valid when the parameter -partitions is also present")); 1245 1316 … … 1924 1995 else 1925 1996 { 1926 return errorSyntax (USAGE_I_RENAMEVMDK, Internal::tr("Invalid parameter '%s'"), argv[i]);1997 return errorSyntaxInternal(USAGE_I_RENAMEVMDK, Internal::tr("Invalid parameter '%s'"), argv[i]); 1927 1998 } 1928 1999 } 1929 2000 1930 2001 if (src.isEmpty()) 1931 return errorSyntax (USAGE_I_RENAMEVMDK, Internal::tr("Mandatory parameter -from missing"));2002 return errorSyntaxInternal(USAGE_I_RENAMEVMDK, Internal::tr("Mandatory parameter -from missing")); 1932 2003 if (dst.isEmpty()) 1933 return errorSyntax (USAGE_I_RENAMEVMDK, Internal::tr("Mandatory parameter -to missing"));2004 return errorSyntaxInternal(USAGE_I_RENAMEVMDK, Internal::tr("Mandatory parameter -to missing")); 1934 2005 1935 2006 PVDISK pDisk = NULL; … … 1997 2068 else 1998 2069 { 1999 return errorSyntax (USAGE_I_CONVERTTORAW, Internal::tr("Invalid parameter '%s'"), argv[i]);2070 return errorSyntaxInternal(USAGE_I_CONVERTTORAW, Internal::tr("Invalid parameter '%s'"), argv[i]); 2000 2071 } 2001 2072 } 2002 2073 2003 2074 if (src.isEmpty()) 2004 return errorSyntax (USAGE_I_CONVERTTORAW, Internal::tr("Mandatory filename parameter missing"));2075 return errorSyntaxInternal(USAGE_I_CONVERTTORAW, Internal::tr("Mandatory filename parameter missing")); 2005 2076 if (dst.isEmpty()) 2006 return errorSyntax (USAGE_I_CONVERTTORAW, Internal::tr("Mandatory outputfile parameter missing"));2077 return errorSyntaxInternal(USAGE_I_CONVERTTORAW, Internal::tr("Mandatory outputfile parameter missing")); 2007 2078 2008 2079 PVDISK pDisk = NULL; … … 2165 2236 else 2166 2237 { 2167 return errorSyntax (USAGE_I_CONVERTHD, Internal::tr("Invalid parameter '%s'"), argv[i]);2238 return errorSyntaxInternal(USAGE_I_CONVERTHD, Internal::tr("Invalid parameter '%s'"), argv[i]); 2168 2239 } 2169 2240 } 2170 2241 2171 2242 if (src.isEmpty()) 2172 return errorSyntax (USAGE_I_CONVERTHD, Internal::tr("Mandatory input image parameter missing"));2243 return errorSyntaxInternal(USAGE_I_CONVERTHD, Internal::tr("Mandatory input image parameter missing")); 2173 2244 if (dst.isEmpty()) 2174 return errorSyntax (USAGE_I_CONVERTHD, Internal::tr("Mandatory output image parameter missing"));2245 return errorSyntaxInternal(USAGE_I_CONVERTHD, Internal::tr("Mandatory output image parameter missing")); 2175 2246 2176 2247 … … 2286 2357 else 2287 2358 { 2288 return errorSyntax (USAGE_I_REPAIRHD, Internal::tr("Invalid parameter '%s'"), argv[i]);2359 return errorSyntaxInternal(USAGE_I_REPAIRHD, Internal::tr("Invalid parameter '%s'"), argv[i]); 2289 2360 } 2290 2361 } 2291 2362 2292 2363 if (image.isEmpty()) 2293 return errorSyntax (USAGE_I_REPAIRHD, Internal::tr("Mandatory input image parameter missing"));2364 return errorSyntaxInternal(USAGE_I_REPAIRHD, Internal::tr("Mandatory input image parameter missing")); 2294 2365 2295 2366 PVDINTERFACE pVDIfs = NULL; … … 2366 2437 */ 2367 2438 if (argc < 1) 2368 return errorSyntax (USAGE_I_DEBUGLOG, Internal::tr("Missing VM name/UUID"));2439 return errorSyntaxInternal(USAGE_I_DEBUGLOG, Internal::tr("Missing VM name/UUID")); 2369 2440 2370 2441 ComPtr<IMachine> ptrMachine; … … 2454 2525 2455 2526 default: 2456 return errorGetOpt (USAGE_I_DEBUGLOG, ch, &ValueUnion);2527 return errorGetOptInternal(USAGE_I_DEBUGLOG, ch, &ValueUnion); 2457 2528 } 2458 2529 } … … 2482 2553 /* one parameter, the password to hash */ 2483 2554 if (argc != 1) 2484 return errorSyntax (USAGE_I_PASSWORDHASH, Internal::tr("password to hash required"));2555 return errorSyntaxInternal(USAGE_I_PASSWORDHASH, Internal::tr("password to hash required")); 2485 2556 2486 2557 uint8_t abDigest[RTSHA256_HASH_SIZE]; … … 2501 2572 /* one parameter, guest name */ 2502 2573 if (argc < 1) 2503 return errorSyntax (USAGE_I_GUESTSTATS, Internal::tr("Missing VM name/UUID"));2574 return errorSyntaxInternal(USAGE_I_GUESTSTATS, Internal::tr("Missing VM name/UUID")); 2504 2575 2505 2576 /* … … 2526 2597 2527 2598 default: 2528 return errorGetOpt (USAGE_I_GUESTSTATS, ch, &ValueUnion);2599 return errorGetOptInternal(USAGE_I_GUESTSTATS, ch, &ValueUnion); 2529 2600 } 2530 2601 } 2531 2602 2532 2603 if (argc > 1 && aUpdateInterval == 0) 2533 return errorSyntax (USAGE_I_GUESTSTATS, Internal::tr("Invalid update interval specified"));2604 return errorSyntaxInternal(USAGE_I_GUESTSTATS, Internal::tr("Invalid update interval specified")); 2534 2605 2535 2606 RTPrintf(Internal::tr("argc=%d interval=%u\n"), argc, aUpdateInterval); … … 2582 2653 RTEXITCODE handleInternalCommands(HandlerArg *a) 2583 2654 { 2584 g_fInternalMode = true;2585 2586 2655 /* at least a command is required */ 2587 2656 if (a->argc < 1) 2588 return errorSyntax (USAGE_S_ALL, Internal::tr("Command missing"));2657 return errorSyntaxInternal(USAGE_S_ALL, Internal::tr("Command missing")); 2589 2658 2590 2659 /* … … 2626 2695 2627 2696 /* default: */ 2628 return errorSyntax (USAGE_S_ALL, Internal::tr("Invalid command '%s'"), a->argv[0]);2629 } 2697 return errorSyntaxInternal(USAGE_S_ALL, Internal::tr("Invalid command '%s'"), a->argv[0]); 2698 } -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r94234 r94240 758 758 return RTEXITCODE_SUCCESS; 759 759 } 760 return errorSyntax( USAGE_S_ALL,VBoxManage::tr("Invalid command '%s'"), argv[iCmd]);760 return errorSyntax(VBoxManage::tr("Invalid command '%s'"), argv[iCmd]); 761 761 } 762 762 -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
r94234 r94240 130 130 }; 131 131 132 /** flag whether we're in internal mode */133 extern bool g_fInternalMode;134 132 135 133 /** showVMInfo details */ … … 160 158 161 159 /* VBoxManageHelp.cpp */ 162 163 160 /* Legacy help infrastructure, to be replaced by new one using generated help. */ 164 161 void printUsage(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, PRTSTREAM pStrm); 165 RTEXITCODE errorSyntax(USAGECATEGORY enmCommand, const char *pszFormat, ...);166 RTEXITCODE errorSyntaxEx(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, const char *pszFormat, ...);167 RTEXITCODE errorGetOpt(USAGECATEGORY enmCommand, int rc, union RTGETOPTUNION const *pValueUnion);168 RTEXITCODE errorGetOptEx(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, int rc, union RTGETOPTUNION const *pValueUnion);169 170 void printUsageInternal(USAGECATEGORY enmCommand, PRTSTREAM pStrm);171 162 172 163 void setCurrentCommand(enum HELP_CMD_VBOXMANAGE enmCommand); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r94235 r94240 561 561 } 562 562 } 563 564 /**565 * Print a usage synopsis and the syntax error message.566 * @returns RTEXITCODE_SYNTAX.567 */568 RTEXITCODE errorSyntax(USAGECATEGORY enmCommand, const char *pszFormat, ...)569 {570 va_list args;571 showLogo(g_pStdErr); // show logo even if suppressed572 573 if (g_fInternalMode)574 printUsageInternal(enmCommand, g_pStdErr);575 else if (g_enmCurCommand == HELP_CMD_VBOXMANAGE_INVALID)576 printUsage(enmCommand, RTMSGREFENTRYSTR_SCOPE_GLOBAL, g_pStdErr);577 else578 printUsage(g_pStdErr);579 580 va_start(args, pszFormat);581 RTStrmPrintf(g_pStdErr, Help::tr("\nSyntax error: %N\n"), pszFormat, &args);582 va_end(args);583 return RTEXITCODE_SYNTAX;584 }585 586 /**587 * Print a usage synopsis and the syntax error message.588 * @returns RTEXITCODE_SYNTAX.589 */590 RTEXITCODE errorSyntaxEx(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, const char *pszFormat, ...)591 {592 va_list args;593 showLogo(g_pStdErr); // show logo even if suppressed594 595 if (g_fInternalMode)596 printUsageInternal(enmCommand, g_pStdErr);597 else if (g_enmCurCommand == HELP_CMD_VBOXMANAGE_INVALID)598 printUsage(enmCommand, fSubcommandScope, g_pStdErr);599 else600 printUsage(g_pStdErr);601 602 va_start(args, pszFormat);603 RTStrmPrintf(g_pStdErr, Help::tr("\nSyntax error: %N\n"), pszFormat, &args);604 va_end(args);605 return RTEXITCODE_SYNTAX;606 }607 608 /**609 * errorSyntax for RTGetOpt users.610 *611 * @returns RTEXITCODE_SYNTAX.612 *613 * @param enmCommand The command.614 * @param fSubcommandScope The subcommand scope, REFENTRYSTR_SCOPE_GLOBAL615 * for all.616 * @param rc The RTGetOpt return code.617 * @param pValueUnion The value union.618 */619 RTEXITCODE errorGetOptEx(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, int rc, union RTGETOPTUNION const *pValueUnion)620 {621 /*622 * Check if it is an unhandled standard option.623 */624 if (rc == 'V')625 {626 RTPrintf("%sr%d\n", VBOX_VERSION_STRING, RTBldCfgRevision());627 return RTEXITCODE_SUCCESS;628 }629 630 if (rc == 'h')631 {632 showLogo(g_pStdErr);633 634 if (g_fInternalMode)635 printUsageInternal(enmCommand, g_pStdOut);636 else if (g_enmCurCommand == HELP_CMD_VBOXMANAGE_INVALID)637 printUsage(enmCommand, fSubcommandScope, g_pStdOut);638 else639 printUsage(g_pStdErr);640 641 return RTEXITCODE_SUCCESS;642 }643 644 /*645 * General failure.646 */647 showLogo(g_pStdErr); // show logo even if suppressed648 649 if (g_fInternalMode)650 printUsageInternal(enmCommand, g_pStdErr);651 else if (g_enmCurCommand == HELP_CMD_VBOXMANAGE_INVALID)652 printUsage(enmCommand, fSubcommandScope, g_pStdErr);653 else654 printUsage(g_pStdErr);655 656 if (rc == VINF_GETOPT_NOT_OPTION)657 return RTMsgErrorExit(RTEXITCODE_SYNTAX, Help::tr("Invalid parameter '%s'"), pValueUnion->psz);658 if (rc > 0)659 {660 if (RT_C_IS_PRINT(rc))661 return RTMsgErrorExit(RTEXITCODE_SYNTAX, Help::tr("Invalid option -%c"), rc);662 return RTMsgErrorExit(RTEXITCODE_SYNTAX, Help::tr("Invalid option case %i"), rc);663 }664 if (rc == VERR_GETOPT_UNKNOWN_OPTION)665 return RTMsgErrorExit(RTEXITCODE_SYNTAX, Help::tr("Unknown option: %s"), pValueUnion->psz);666 if (rc == VERR_GETOPT_INVALID_ARGUMENT_FORMAT)667 return RTMsgErrorExit(RTEXITCODE_SYNTAX, Help::tr("Invalid argument format: %s"), pValueUnion->psz);668 if (pValueUnion->pDef)669 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "%s: %Rrs", pValueUnion->pDef->pszLong, rc);670 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "%Rrs", rc);671 }672 673 674 /**675 * errorSyntax for RTGetOpt users.676 *677 * @returns RTEXITCODE_SYNTAX.678 *679 * @param enmCommand The command.680 * @param rc The RTGetOpt return code.681 * @param pValueUnion The value union.682 */683 RTEXITCODE errorGetOpt(USAGECATEGORY enmCommand, int rc, union RTGETOPTUNION const *pValueUnion)684 {685 return errorGetOptEx(enmCommand, RTMSGREFENTRYSTR_SCOPE_GLOBAL, rc, pValueUnion);686 }687
Note:
See TracChangeset
for help on using the changeset viewer.