Changeset 23569 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Oct 6, 2009 12:31:40 AM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
r22911 r23569 140 140 void printUsage(USAGECATEGORY u64Cmd); 141 141 int errorSyntax(USAGECATEGORY u64Cmd, const char *pszFormat, ...); 142 int errorGetOpt(USAGECATEGORY u64Cmd, int rc, union RTGETOPTUNION const *pValueUnion); 142 143 int errorArgument(const char *pszFormat, ...); 143 144 -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r23504 r23569 20 20 */ 21 21 22 #include <iprt/ctype.h> 23 #include <iprt/getopt.h> 22 24 #include <iprt/stream.h> 23 #include <iprt/getopt.h>24 25 25 26 #include "VBoxManage.h" … … 335 336 { 336 337 RTPrintf("VBoxManage snapshot <uuid>|<name>\n" 337 " take <name> [--description <desc>] |\n"338 " take <name> [--description <desc>] [--pause] |\n" 338 339 " discard <uuid>|<name> |\n" 339 340 " discardcurrent --state|--all |\n" … … 589 590 590 591 /** 592 * errorSyntax for RTGetOpt users. 593 * 594 * @returns 1. 595 * 596 * @param fUsageCategory The usage category of the command. 597 * @param rc The RTGetOpt return code. 598 * @param pValueUnion The value union. 599 */ 600 int errorGetOpt(USAGECATEGORY fUsageCategory, int rc, union RTGETOPTUNION const *pValueUnion) 601 { 602 showLogo(); // show logo even if suppressed 603 #ifndef VBOX_ONLY_DOCS 604 if (g_fInternalMode) 605 printUsageInternal(fUsageCategory); 606 else 607 printUsage(fUsageCategory); 608 #endif /* !VBOX_ONLY_DOCS */ 609 610 if (rc == VINF_GETOPT_NOT_OPTION) 611 return RTPrintf("error: Invalid parameter '%s'", pValueUnion->psz); 612 if (rc > 0) 613 { 614 if (RT_C_IS_PRINT(rc)) 615 return RTPrintf("error: Invalid option -%c", rc); 616 return RTPrintf("error: Invalid option case %i", rc); 617 } 618 if (rc == VERR_GETOPT_UNKNOWN_OPTION) 619 return RTPrintf("error: unknown option: %s\n", pValueUnion->psz); 620 if (pValueUnion->pDef) 621 return RTPrintf("error: %s: %Rrs", pValueUnion->pDef->pszLong, rc); 622 return RTPrintf("error: %Rrs", rc); 623 } 624 625 /** 591 626 * Print an error message without the syntax stuff. 592 627 */ -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageSnapshot.cpp
r20928 r23569 78 78 } 79 79 Bstr name(a->argv[2]); 80 if ((a->argc > 3) && ( (a->argc != 5) 81 || ( strcmp(a->argv[3], "--description") 82 && strcmp(a->argv[3], "-description") 83 && strcmp(a->argv[3], "-desc")))) 84 { 85 errorSyntax(USAGE_SNAPSHOT, "Incorrect description format"); 86 rc = E_FAIL; 87 break; 88 } 80 81 /* parse the optional arguments */ 89 82 Bstr desc; 90 if (a->argc == 5) 91 desc = a->argv[4]; 83 bool fPause = false; 84 static const RTGETOPTDEF s_aTakeOptions[] = 85 { 86 { "--description", 'd', RTGETOPT_REQ_STRING }, 87 { "-description", 'd', RTGETOPT_REQ_STRING }, 88 { "-desc", 'd', RTGETOPT_REQ_STRING }, 89 { "--pause", 'p', RTGETOPT_REQ_NOTHING } 90 }; 91 RTGETOPTSTATE GetOptState; 92 RTGetOptInit(&GetOptState, a->argc, a->argv, s_aTakeOptions, RT_ELEMENTS(s_aTakeOptions), 3, 0 /*fFlags*/); 93 int ch; 94 RTGETOPTUNION Value; 95 while ( SUCCEEDED(rc) 96 && (ch = RTGetOpt(&GetOptState, &Value))) 97 { 98 switch (ch) 99 { 100 case 'p': 101 fPause = true; 102 break; 103 104 case 'd': 105 desc = Value.psz; 106 break; 107 108 default: 109 errorGetOpt(USAGE_SNAPSHOT, ch, &Value); 110 rc = E_FAIL; 111 break; 112 } 113 } 114 if (FAILED(rc)) 115 break; 116 117 if (fPause) 118 { 119 MachineState_T machineState; 120 CHECK_ERROR_BREAK(console, COMGETTER(State)(&machineState)); 121 if (machineState == MachineState_Running) 122 CHECK_ERROR_BREAK(console, Pause()); 123 else 124 fPause = false; 125 } 126 92 127 ComPtr<IProgress> progress; 93 128 CHECK_ERROR_BREAK(console, TakeSnapshot(name, desc, progress.asOutParam())); … … 105 140 RTPrintf("Error: failed to take snapshot. No error message available!\n"); 106 141 } 142 143 if (fPause) 144 { 145 MachineState_T machineState; 146 CHECK_ERROR_BREAK(console, COMGETTER(State)(&machineState)); 147 if (machineState == MachineState_Paused) 148 { 149 if (SUCCEEDED(rc)) 150 CHECK_ERROR_BREAK(console, Resume()); 151 else 152 console->Pause(); 153 } 154 } 107 155 } 108 156 else if (!strcmp(a->argv[1], "discard"))
Note:
See TracChangeset
for help on using the changeset viewer.