1 | /* $Id: VBoxManageHelp.cpp 92842 2021-12-09 09:51:57Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxManage - help and other message output.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #include <VBox/version.h>
|
---|
23 |
|
---|
24 | #include <iprt/asm.h>
|
---|
25 | #include <iprt/buildconfig.h>
|
---|
26 | #include <iprt/ctype.h>
|
---|
27 | #include <iprt/assert.h>
|
---|
28 | #include <iprt/env.h>
|
---|
29 | #include <iprt/err.h>
|
---|
30 | #include <iprt/getopt.h>
|
---|
31 | #include <iprt/stream.h>
|
---|
32 | #include <iprt/message.h>
|
---|
33 |
|
---|
34 | #include "VBoxManage.h"
|
---|
35 |
|
---|
36 |
|
---|
37 | /*********************************************************************************************************************************
|
---|
38 | * Defined Constants And Macros *
|
---|
39 | *********************************************************************************************************************************/
|
---|
40 | /** If the usage is the given number of length long or longer, the error is
|
---|
41 | * repeated so the user can actually see it. */
|
---|
42 | #define ERROR_REPEAT_AFTER_USAGE_LENGTH 16
|
---|
43 |
|
---|
44 |
|
---|
45 | /*********************************************************************************************************************************
|
---|
46 | * Global Variables *
|
---|
47 | *********************************************************************************************************************************/
|
---|
48 | DECLARE_TRANSLATION_CONTEXT(Help);
|
---|
49 |
|
---|
50 | #ifndef VBOX_ONLY_DOCS
|
---|
51 | static enum HELP_CMD_VBOXMANAGE g_enmCurCommand = HELP_CMD_VBOXMANAGE_INVALID;
|
---|
52 | /** The scope mask for the current subcommand. */
|
---|
53 | static uint64_t g_fCurSubcommandScope = RTMSGREFENTRYSTR_SCOPE_GLOBAL;
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Sets the current command.
|
---|
57 | *
|
---|
58 | * This affects future calls to error and help functions.
|
---|
59 | *
|
---|
60 | * @param enmCommand The command.
|
---|
61 | */
|
---|
62 | void setCurrentCommand(enum HELP_CMD_VBOXMANAGE enmCommand)
|
---|
63 | {
|
---|
64 | Assert(g_enmCurCommand == HELP_CMD_VBOXMANAGE_INVALID);
|
---|
65 | g_enmCurCommand = enmCommand;
|
---|
66 | g_fCurSubcommandScope = RTMSGREFENTRYSTR_SCOPE_GLOBAL;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Sets the current subcommand.
|
---|
72 | *
|
---|
73 | * This affects future calls to error and help functions.
|
---|
74 | *
|
---|
75 | * @param fSubcommandScope The subcommand scope.
|
---|
76 | */
|
---|
77 | void setCurrentSubcommand(uint64_t fSubcommandScope)
|
---|
78 | {
|
---|
79 | g_fCurSubcommandScope = fSubcommandScope;
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Takes first char and make it uppercase.
|
---|
85 | *
|
---|
86 | * @returns pointer to string starting from next char.
|
---|
87 | * @param pszSrc Source string.
|
---|
88 | * @param pszFirstCharBuffer Pointer to buffer to place first char uppercase
|
---|
89 | */
|
---|
90 | static const char *firstCharUppercase(const char *pszSrc, char *pszFirstCharBuffer)
|
---|
91 | {
|
---|
92 | RTUNICP Cp;
|
---|
93 | RTStrGetCpEx(&pszSrc, &Cp);
|
---|
94 | char *pszBuffer = RTStrPutCp(pszFirstCharBuffer, Cp);
|
---|
95 | RTStrToUpper(pszBuffer);
|
---|
96 | pszBuffer[0] = 0;
|
---|
97 | return pszSrc;
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Prints brief help for a command or subcommand.
|
---|
103 | *
|
---|
104 | * @returns Number of lines written.
|
---|
105 | * @param enmCommand The command.
|
---|
106 | * @param fSubcommandScope The subcommand scope, REFENTRYSTR_SCOPE_GLOBAL
|
---|
107 | * for all.
|
---|
108 | * @param pStrm The output stream.
|
---|
109 | */
|
---|
110 | static uint32_t printBriefCommandOrSubcommandHelp(enum HELP_CMD_VBOXMANAGE enmCommand, uint64_t fSubcommandScope, PRTSTREAM pStrm)
|
---|
111 | {
|
---|
112 | uint32_t cLinesWritten = 0;
|
---|
113 | uint32_t cPendingBlankLines = 0;
|
---|
114 | uint32_t cFound = 0;
|
---|
115 | #ifdef VBOX_WITH_VBOXMANAGE_NLS
|
---|
116 | PHELP_LANG_ENTRY pHelpLangEntry[2] = {ASMAtomicReadPtrT(&g_pHelpLangEntry, PHELP_LANG_ENTRY), &g_apHelpLangEntries[0] };
|
---|
117 | #else
|
---|
118 | PHELP_LANG_ENTRY pHelpLangEntry[1] = {(PHELP_LANG_ENTRY)g_pHelpLangEntry};
|
---|
119 | #endif
|
---|
120 | /* Try to find translated, then untranslated */
|
---|
121 | for (uint32_t k = 0; k < RT_ELEMENTS(pHelpLangEntry) && cFound == 0; k++)
|
---|
122 | {
|
---|
123 | /* skip if english is used */
|
---|
124 | if (k > 0 && pHelpLangEntry[k] == pHelpLangEntry[0])
|
---|
125 | break;
|
---|
126 | for (uint32_t i = 0; i < pHelpLangEntry[k]->cHelpEntries; i++)
|
---|
127 | {
|
---|
128 | PCRTMSGREFENTRY pHelp = pHelpLangEntry[k]->papHelpEntries[i];
|
---|
129 | if (pHelp->idInternal == (int64_t)enmCommand)
|
---|
130 | {
|
---|
131 | cFound++;
|
---|
132 | if (cFound == 1)
|
---|
133 | {
|
---|
134 | if (fSubcommandScope == RTMSGREFENTRYSTR_SCOPE_GLOBAL)
|
---|
135 | {
|
---|
136 | char szFirstChar[16] = {0};
|
---|
137 | const char *pszNext = firstCharUppercase(pHelp->pszBrief, szFirstChar);
|
---|
138 | RTStrmPrintf(pStrm, Help::tr("Usage - %s%s:\n"), szFirstChar, pszNext);
|
---|
139 | }
|
---|
140 | else
|
---|
141 | RTStrmPrintf(pStrm, Help::tr("Usage:\n"));
|
---|
142 | }
|
---|
143 | RTMsgRefEntryPrintStringTable(pStrm, &pHelp->Synopsis, fSubcommandScope, &cPendingBlankLines, &cLinesWritten);
|
---|
144 | if (!cPendingBlankLines)
|
---|
145 | cPendingBlankLines = 1;
|
---|
146 | }
|
---|
147 | }
|
---|
148 | }
|
---|
149 | Assert(cFound > 0);
|
---|
150 | return cLinesWritten;
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * Prints the brief usage information for the current (sub)command.
|
---|
156 | *
|
---|
157 | * @param pStrm The output stream.
|
---|
158 | */
|
---|
159 | void printUsage(PRTSTREAM pStrm)
|
---|
160 | {
|
---|
161 | printBriefCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, pStrm);
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Prints full help for a command or subcommand.
|
---|
167 | *
|
---|
168 | * @param enmCommand The command.
|
---|
169 | * @param fSubcommandScope The subcommand scope, REFENTRYSTR_SCOPE_GLOBAL
|
---|
170 | * for all.
|
---|
171 | * @param pStrm The output stream.
|
---|
172 | */
|
---|
173 | static void printFullCommandOrSubcommandHelp(enum HELP_CMD_VBOXMANAGE enmCommand, uint64_t fSubcommandScope, PRTSTREAM pStrm)
|
---|
174 | {
|
---|
175 | uint32_t cPendingBlankLines = 0;
|
---|
176 | uint32_t cFound = 0;
|
---|
177 | #ifdef VBOX_WITH_VBOXMANAGE_NLS
|
---|
178 | PHELP_LANG_ENTRY pHelpLangEntry[2] = {ASMAtomicReadPtrT(&g_pHelpLangEntry, PHELP_LANG_ENTRY), &g_apHelpLangEntries[0] };
|
---|
179 | #else
|
---|
180 | PHELP_LANG_ENTRY pHelpLangEntry[1] = {(PHELP_LANG_ENTRY)g_pHelpLangEntry};
|
---|
181 | #endif
|
---|
182 | /* Try to find translated, then untranslated */
|
---|
183 | for (uint32_t k = 0; k < RT_ELEMENTS(pHelpLangEntry) && cFound == 0; k++)
|
---|
184 | {
|
---|
185 | /* skip if english is used */
|
---|
186 | if (k > 0 && pHelpLangEntry[k] == pHelpLangEntry[0])
|
---|
187 | break;
|
---|
188 | for (uint32_t i = 0; i < pHelpLangEntry[k]->cHelpEntries; i++)
|
---|
189 | {
|
---|
190 | PCRTMSGREFENTRY pHelp = pHelpLangEntry[k]->papHelpEntries[i];
|
---|
191 |
|
---|
192 | if ( pHelp->idInternal == (int64_t)enmCommand
|
---|
193 | || enmCommand == HELP_CMD_VBOXMANAGE_INVALID)
|
---|
194 | {
|
---|
195 | cFound++;
|
---|
196 | RTMsgRefEntryPrintStringTable(pStrm, &pHelp->Help, fSubcommandScope, &cPendingBlankLines, NULL /*pcLinesWritten*/);
|
---|
197 | if (cPendingBlankLines < 2)
|
---|
198 | cPendingBlankLines = 2;
|
---|
199 | }
|
---|
200 | }
|
---|
201 | }
|
---|
202 | Assert(cFound > 0);
|
---|
203 | }
|
---|
204 |
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Prints the full help for the current (sub)command.
|
---|
208 | *
|
---|
209 | * @param pStrm The output stream.
|
---|
210 | */
|
---|
211 | void printHelp(PRTSTREAM pStrm)
|
---|
212 | {
|
---|
213 | printFullCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, pStrm);
|
---|
214 | }
|
---|
215 |
|
---|
216 |
|
---|
217 | /**
|
---|
218 | * Display no subcommand error message and current command usage.
|
---|
219 | *
|
---|
220 | * @returns RTEXITCODE_SYNTAX.
|
---|
221 | */
|
---|
222 | RTEXITCODE errorNoSubcommand(void)
|
---|
223 | {
|
---|
224 | Assert(g_enmCurCommand != HELP_CMD_VBOXMANAGE_INVALID);
|
---|
225 | Assert(g_fCurSubcommandScope == RTMSGREFENTRYSTR_SCOPE_GLOBAL);
|
---|
226 |
|
---|
227 | return errorSyntax(Help::tr("No subcommand specified"));
|
---|
228 | }
|
---|
229 |
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * Display unknown subcommand error message and current command usage.
|
---|
233 | *
|
---|
234 | * May show full command help instead if the subcommand is a common help option.
|
---|
235 | *
|
---|
236 | * @returns RTEXITCODE_SYNTAX, or RTEXITCODE_SUCCESS if common help option.
|
---|
237 | * @param pszSubcommand The name of the alleged subcommand.
|
---|
238 | */
|
---|
239 | RTEXITCODE errorUnknownSubcommand(const char *pszSubcommand)
|
---|
240 | {
|
---|
241 | Assert(g_enmCurCommand != HELP_CMD_VBOXMANAGE_INVALID);
|
---|
242 | Assert(g_fCurSubcommandScope == RTMSGREFENTRYSTR_SCOPE_GLOBAL);
|
---|
243 |
|
---|
244 | /* check if help was requested. */
|
---|
245 | if ( strcmp(pszSubcommand, "--help") == 0
|
---|
246 | || strcmp(pszSubcommand, "-h") == 0
|
---|
247 | || strcmp(pszSubcommand, "-?") == 0)
|
---|
248 | {
|
---|
249 | printFullCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, g_pStdOut);
|
---|
250 | return RTEXITCODE_SUCCESS;
|
---|
251 | }
|
---|
252 |
|
---|
253 | return errorSyntax(Help::tr("Unknown subcommand: %s"), pszSubcommand);
|
---|
254 | }
|
---|
255 |
|
---|
256 |
|
---|
257 | /**
|
---|
258 | * Display too many parameters error message and current command usage.
|
---|
259 | *
|
---|
260 | * May show full command help instead if the subcommand is a common help option.
|
---|
261 | *
|
---|
262 | * @returns RTEXITCODE_SYNTAX, or RTEXITCODE_SUCCESS if common help option.
|
---|
263 | * @param papszArgs The first unwanted parameter. Terminated by
|
---|
264 | * NULL entry.
|
---|
265 | */
|
---|
266 | RTEXITCODE errorTooManyParameters(char **papszArgs)
|
---|
267 | {
|
---|
268 | Assert(g_enmCurCommand != HELP_CMD_VBOXMANAGE_INVALID);
|
---|
269 | Assert(g_fCurSubcommandScope != RTMSGREFENTRYSTR_SCOPE_GLOBAL);
|
---|
270 |
|
---|
271 | /* check if help was requested. */
|
---|
272 | if (papszArgs)
|
---|
273 | {
|
---|
274 | for (uint32_t i = 0; papszArgs[i]; i++)
|
---|
275 | if ( strcmp(papszArgs[i], "--help") == 0
|
---|
276 | || strcmp(papszArgs[i], "-h") == 0
|
---|
277 | || strcmp(papszArgs[i], "-?") == 0)
|
---|
278 | {
|
---|
279 | printFullCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, g_pStdOut);
|
---|
280 | return RTEXITCODE_SUCCESS;
|
---|
281 | }
|
---|
282 | else if (!strcmp(papszArgs[i], "--"))
|
---|
283 | break;
|
---|
284 | }
|
---|
285 |
|
---|
286 | return errorSyntax(Help::tr("Too many parameters"));
|
---|
287 | }
|
---|
288 |
|
---|
289 |
|
---|
290 | /**
|
---|
291 | * Display current (sub)command usage and the custom error message.
|
---|
292 | *
|
---|
293 | * @returns RTEXITCODE_SYNTAX.
|
---|
294 | * @param pszFormat Custom error message format string.
|
---|
295 | * @param va Format arguments.
|
---|
296 | */
|
---|
297 | RTEXITCODE errorSyntaxV(const char *pszFormat, va_list va)
|
---|
298 | {
|
---|
299 | Assert(g_enmCurCommand != HELP_CMD_VBOXMANAGE_INVALID);
|
---|
300 |
|
---|
301 | showLogo(g_pStdErr);
|
---|
302 |
|
---|
303 | va_list vaCopy;
|
---|
304 | va_copy(vaCopy, va);
|
---|
305 | RTMsgErrorV(pszFormat, vaCopy);
|
---|
306 | va_end(vaCopy);
|
---|
307 |
|
---|
308 | RTStrmPutCh(g_pStdErr, '\n');
|
---|
309 | if ( printBriefCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, g_pStdErr)
|
---|
310 | >= ERROR_REPEAT_AFTER_USAGE_LENGTH)
|
---|
311 | {
|
---|
312 | /* Usage was very long, repeat the error message. */
|
---|
313 | RTStrmPutCh(g_pStdErr, '\n');
|
---|
314 | RTMsgErrorV(pszFormat, va);
|
---|
315 | }
|
---|
316 | return RTEXITCODE_SYNTAX;
|
---|
317 | }
|
---|
318 |
|
---|
319 |
|
---|
320 | /**
|
---|
321 | * Display current (sub)command usage and the custom error message.
|
---|
322 | *
|
---|
323 | * @returns RTEXITCODE_SYNTAX.
|
---|
324 | * @param pszFormat Custom error message format string.
|
---|
325 | * @param ... Format arguments.
|
---|
326 | */
|
---|
327 | RTEXITCODE errorSyntax(const char *pszFormat, ...)
|
---|
328 | {
|
---|
329 | va_list va;
|
---|
330 | va_start(va, pszFormat);
|
---|
331 | RTEXITCODE rcExit = errorSyntaxV(pszFormat, va);
|
---|
332 | va_end(va);
|
---|
333 | return rcExit;
|
---|
334 | }
|
---|
335 |
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Display current (sub)command usage and the custom error message.
|
---|
339 | *
|
---|
340 | * @returns E_INVALIDARG
|
---|
341 | * @param pszFormat Custom error message format string.
|
---|
342 | * @param ... Format arguments.
|
---|
343 | */
|
---|
344 | HRESULT errorSyntaxHr(const char *pszFormat, ...)
|
---|
345 | {
|
---|
346 | va_list va;
|
---|
347 | va_start(va, pszFormat);
|
---|
348 | errorSyntaxV(pszFormat, va);
|
---|
349 | va_end(va);
|
---|
350 | return E_INVALIDARG;
|
---|
351 | }
|
---|
352 |
|
---|
353 |
|
---|
354 | /**
|
---|
355 | * Print an error message without the syntax stuff.
|
---|
356 | *
|
---|
357 | * @returns RTEXITCODE_SYNTAX.
|
---|
358 | */
|
---|
359 | RTEXITCODE errorArgument(const char *pszFormat, ...)
|
---|
360 | {
|
---|
361 | va_list args;
|
---|
362 | va_start(args, pszFormat);
|
---|
363 | RTMsgErrorV(pszFormat, args);
|
---|
364 | va_end(args);
|
---|
365 | return RTEXITCODE_SYNTAX;
|
---|
366 | }
|
---|
367 |
|
---|
368 |
|
---|
369 | /**
|
---|
370 | * Print an error message without the syntax stuff.
|
---|
371 | *
|
---|
372 | * @returns E_INVALIDARG.
|
---|
373 | */
|
---|
374 | HRESULT errorArgumentHr(const char *pszFormat, ...)
|
---|
375 | {
|
---|
376 | va_list args;
|
---|
377 | va_start(args, pszFormat);
|
---|
378 | RTMsgErrorV(pszFormat, args);
|
---|
379 | va_end(args);
|
---|
380 | return E_INVALIDARG;
|
---|
381 | }
|
---|
382 |
|
---|
383 |
|
---|
384 | /**
|
---|
385 | * Worker for errorGetOpt.
|
---|
386 | *
|
---|
387 | * @param rcGetOpt The RTGetOpt return value.
|
---|
388 | * @param pValueUnion The value union returned by RTGetOpt.
|
---|
389 | */
|
---|
390 | static void errorGetOptWorker(int rcGetOpt, union RTGETOPTUNION const *pValueUnion)
|
---|
391 | {
|
---|
392 | if (rcGetOpt == VINF_GETOPT_NOT_OPTION)
|
---|
393 | RTMsgError(Help::tr("Invalid parameter '%s'"), pValueUnion->psz);
|
---|
394 | else if (rcGetOpt > 0)
|
---|
395 | {
|
---|
396 | if (RT_C_IS_PRINT(rcGetOpt))
|
---|
397 | RTMsgError(Help::tr("Invalid option -%c"), rcGetOpt);
|
---|
398 | else
|
---|
399 | RTMsgError(Help::tr("Invalid option case %i"), rcGetOpt);
|
---|
400 | }
|
---|
401 | else if (rcGetOpt == VERR_GETOPT_UNKNOWN_OPTION)
|
---|
402 | RTMsgError(Help::tr("Unknown option: %s"), pValueUnion->psz);
|
---|
403 | else if (rcGetOpt == VERR_GETOPT_INVALID_ARGUMENT_FORMAT)
|
---|
404 | RTMsgError(Help::tr("Invalid argument format: %s"), pValueUnion->psz);
|
---|
405 | else if (pValueUnion->pDef)
|
---|
406 | RTMsgError("%s: %Rrs", pValueUnion->pDef->pszLong, rcGetOpt);
|
---|
407 | else
|
---|
408 | RTMsgError("%Rrs", rcGetOpt);
|
---|
409 | }
|
---|
410 |
|
---|
411 |
|
---|
412 | /**
|
---|
413 | * For use to deal with RTGetOptFetchValue failures.
|
---|
414 | *
|
---|
415 | * @retval RTEXITCODE_SYNTAX
|
---|
416 | * @param iValueNo The value number being fetched, counting the
|
---|
417 | * RTGetOpt value as zero and the first
|
---|
418 | * RTGetOptFetchValue call as one.
|
---|
419 | * @param pszOption The option being parsed.
|
---|
420 | * @param rcGetOptFetchValue The status returned by RTGetOptFetchValue.
|
---|
421 | * @param pValueUnion The value union returned by the fetch.
|
---|
422 | */
|
---|
423 | RTEXITCODE errorFetchValue(int iValueNo, const char *pszOption, int rcGetOptFetchValue, union RTGETOPTUNION const *pValueUnion)
|
---|
424 | {
|
---|
425 | Assert(g_enmCurCommand != HELP_CMD_VBOXMANAGE_INVALID);
|
---|
426 | showLogo(g_pStdErr);
|
---|
427 | if (rcGetOptFetchValue == VERR_GETOPT_REQUIRED_ARGUMENT_MISSING)
|
---|
428 | RTMsgError(Help::tr("Missing the %u%s value for option %s"),
|
---|
429 | iValueNo,
|
---|
430 | iValueNo == 1 ? Help::tr("st")
|
---|
431 | : iValueNo == 2 ? Help::tr("nd")
|
---|
432 | : iValueNo == 3 ? Help::tr("rd")
|
---|
433 | : Help::tr("th"),
|
---|
434 | pszOption);
|
---|
435 | else
|
---|
436 | errorGetOptWorker(rcGetOptFetchValue, pValueUnion);
|
---|
437 | return RTEXITCODE_SYNTAX;
|
---|
438 |
|
---|
439 | }
|
---|
440 |
|
---|
441 |
|
---|
442 | /**
|
---|
443 | * Handled an RTGetOpt error or common option.
|
---|
444 | *
|
---|
445 | * This implements the 'V' and 'h' cases. It reports appropriate syntax errors
|
---|
446 | * for other @a rcGetOpt values.
|
---|
447 | *
|
---|
448 | * @retval RTEXITCODE_SUCCESS if help or version request.
|
---|
449 | * @retval RTEXITCODE_SYNTAX if not help or version request.
|
---|
450 | * @param rcGetOpt The RTGetOpt return value.
|
---|
451 | * @param pValueUnion The value union returned by RTGetOpt.
|
---|
452 | */
|
---|
453 | RTEXITCODE errorGetOpt(int rcGetOpt, union RTGETOPTUNION const *pValueUnion)
|
---|
454 | {
|
---|
455 | Assert(g_enmCurCommand != HELP_CMD_VBOXMANAGE_INVALID);
|
---|
456 |
|
---|
457 | /*
|
---|
458 | * Check if it is an unhandled standard option.
|
---|
459 | */
|
---|
460 | if (rcGetOpt == 'V')
|
---|
461 | {
|
---|
462 | RTPrintf("%sr%d\n", VBOX_VERSION_STRING, RTBldCfgRevision());
|
---|
463 | return RTEXITCODE_SUCCESS;
|
---|
464 | }
|
---|
465 |
|
---|
466 | if (rcGetOpt == 'h')
|
---|
467 | {
|
---|
468 | printFullCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, g_pStdOut);
|
---|
469 | return RTEXITCODE_SUCCESS;
|
---|
470 | }
|
---|
471 |
|
---|
472 | /*
|
---|
473 | * We failed.
|
---|
474 | */
|
---|
475 | showLogo(g_pStdErr);
|
---|
476 | errorGetOptWorker(rcGetOpt, pValueUnion);
|
---|
477 | if ( printBriefCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, g_pStdErr)
|
---|
478 | >= ERROR_REPEAT_AFTER_USAGE_LENGTH)
|
---|
479 | {
|
---|
480 | /* Usage was very long, repeat the error message. */
|
---|
481 | RTStrmPutCh(g_pStdErr, '\n');
|
---|
482 | errorGetOptWorker(rcGetOpt, pValueUnion);
|
---|
483 | }
|
---|
484 | return RTEXITCODE_SYNTAX;
|
---|
485 | }
|
---|
486 |
|
---|
487 | #endif /* !VBOX_ONLY_DOCS */
|
---|
488 |
|
---|
489 |
|
---|
490 |
|
---|
491 | void showLogo(PRTSTREAM pStrm)
|
---|
492 | {
|
---|
493 | static bool s_fShown; /* show only once */
|
---|
494 |
|
---|
495 | if (!s_fShown)
|
---|
496 | {
|
---|
497 | RTStrmPrintf(pStrm, VBOX_PRODUCT " Command Line Management Interface Version "
|
---|
498 | VBOX_VERSION_STRING "\n"
|
---|
499 | "(C) 2005-" VBOX_C_YEAR " " VBOX_VENDOR "\n"
|
---|
500 | "All rights reserved.\n"
|
---|
501 | "\n");
|
---|
502 | s_fShown = true;
|
---|
503 | }
|
---|
504 | }
|
---|
505 |
|
---|
506 |
|
---|
507 |
|
---|
508 |
|
---|
509 | void printUsage(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, PRTSTREAM pStrm)
|
---|
510 | {
|
---|
511 | bool fDumpOpts = false;
|
---|
512 | #ifdef RT_OS_LINUX
|
---|
513 | bool fLinux = true;
|
---|
514 | #else
|
---|
515 | bool fLinux = false;
|
---|
516 | #endif
|
---|
517 | #ifdef RT_OS_WINDOWS
|
---|
518 | bool fWin = true;
|
---|
519 | #else
|
---|
520 | bool fWin = false;
|
---|
521 | #endif
|
---|
522 | #ifdef RT_OS_SOLARIS
|
---|
523 | bool fSolaris = true;
|
---|
524 | #else
|
---|
525 | bool fSolaris = false;
|
---|
526 | #endif
|
---|
527 | #ifdef RT_OS_FREEBSD
|
---|
528 | bool fFreeBSD = true;
|
---|
529 | #else
|
---|
530 | bool fFreeBSD = false;
|
---|
531 | #endif
|
---|
532 | #ifdef RT_OS_DARWIN
|
---|
533 | bool fDarwin = true;
|
---|
534 | #else
|
---|
535 | bool fDarwin = false;
|
---|
536 | #endif
|
---|
537 | #ifdef VBOX_WITH_VBOXSDL
|
---|
538 | bool fVBoxSDL = true;
|
---|
539 | #else
|
---|
540 | bool fVBoxSDL = false;
|
---|
541 | #endif
|
---|
542 |
|
---|
543 | Assert(enmCommand != USAGE_INVALID);
|
---|
544 | Assert(enmCommand != USAGE_S_NEWCMD);
|
---|
545 |
|
---|
546 | if (enmCommand == USAGE_S_DUMPOPTS)
|
---|
547 | {
|
---|
548 | fDumpOpts = true;
|
---|
549 | fLinux = true;
|
---|
550 | fWin = true;
|
---|
551 | fSolaris = true;
|
---|
552 | fFreeBSD = true;
|
---|
553 | fDarwin = true;
|
---|
554 | fVBoxSDL = true;
|
---|
555 | enmCommand = USAGE_S_ALL;
|
---|
556 | }
|
---|
557 |
|
---|
558 | RTStrmPrintf(pStrm,
|
---|
559 | Help::tr("Usage:\n"
|
---|
560 | "\n"));
|
---|
561 |
|
---|
562 | if (enmCommand == USAGE_S_ALL)
|
---|
563 | RTStrmPrintf(pStrm,
|
---|
564 | " VBoxManage [<general option>] <command>\n"
|
---|
565 | "\n"
|
---|
566 | "\n"
|
---|
567 | "General Options:\n"
|
---|
568 | "\n"
|
---|
569 | " [-V|--version] print version number and exit\n"
|
---|
570 | " [--dump-build-type] print build type and exit\n"
|
---|
571 | " [-q|--nologo] suppress the logo\n"
|
---|
572 | " [--settingspw <pw>] provide the settings password\n"
|
---|
573 | " [--settingspwfile <file>] provide a file containing the settings password\n"
|
---|
574 | " [@<response-file>] load arguments from the given response file (bourne style)\n"
|
---|
575 | "\n"
|
---|
576 | "\n"
|
---|
577 | "Commands:\n"
|
---|
578 | "\n");
|
---|
579 |
|
---|
580 | const char *pcszSep1 = " ";
|
---|
581 | const char *pcszSep2 = " ";
|
---|
582 | if (enmCommand != USAGE_S_ALL)
|
---|
583 | {
|
---|
584 | pcszSep1 = "VBoxManage";
|
---|
585 | pcszSep2 = "";
|
---|
586 | }
|
---|
587 |
|
---|
588 | #define SEP pcszSep1, pcszSep2
|
---|
589 |
|
---|
590 | if (enmCommand == USAGE_STARTVM || enmCommand == USAGE_S_ALL)
|
---|
591 | {
|
---|
592 | RTStrmPrintf(pStrm,
|
---|
593 | "%s startvm %s <uuid|vmname>...\n"
|
---|
594 | " [--type gui", SEP);
|
---|
595 | if (fVBoxSDL)
|
---|
596 | RTStrmPrintf(pStrm, "|sdl");
|
---|
597 | RTStrmPrintf(pStrm, "|headless|separate]\n");
|
---|
598 | RTStrmPrintf(pStrm,
|
---|
599 | " [-E|--putenv <NAME>[=<VALUE>]]\n"
|
---|
600 | "\n");
|
---|
601 | }
|
---|
602 |
|
---|
603 | if (enmCommand == USAGE_CONTROLVM || enmCommand == USAGE_S_ALL)
|
---|
604 | {
|
---|
605 | RTStrmPrintf(pStrm,
|
---|
606 | "%s controlvm %s <uuid|vmname>\n"
|
---|
607 | " pause|resume|reset|poweroff|savestate|\n", SEP);
|
---|
608 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
609 | RTStrmPrintf(pStrm,
|
---|
610 | " reboot|shutdown [--force]|\n");
|
---|
611 | #endif
|
---|
612 | RTStrmPrintf(pStrm,
|
---|
613 | " acpipowerbutton|acpisleepbutton|\n"
|
---|
614 | " keyboardputscancode <hex> [<hex> ...]|\n"
|
---|
615 | " keyboardputstring <string1> [<string2> ...]|\n"
|
---|
616 | " keyboardputfile <filename>|\n"
|
---|
617 | " setlinkstate<1-N> on|off |\n");
|
---|
618 | #if defined(VBOX_WITH_NETFLT)
|
---|
619 | RTStrmPrintf(pStrm,
|
---|
620 | " nic<1-N> null|nat|bridged|intnet|hostonly|generic|\n"
|
---|
621 | " natnetwork [<devicename>] |\n");
|
---|
622 | #else /* !VBOX_WITH_NETFLT */
|
---|
623 | RTStrmPrintf(pStrm,
|
---|
624 | " nic<1-N> null|nat|bridged|intnet|generic|natnetwork\n"
|
---|
625 | " [<devicename>] |\n");
|
---|
626 | #endif /* !VBOX_WITH_NETFLT */
|
---|
627 | RTStrmPrintf(pStrm,
|
---|
628 | " nictrace<1-N> on|off |\n"
|
---|
629 | " nictracefile<1-N> <filename> |\n"
|
---|
630 | " nicproperty<1-N> name=[value] |\n"
|
---|
631 | " nicpromisc<1-N> deny|allow-vms|allow-all |\n"
|
---|
632 | " natpf<1-N> [<rulename>],tcp|udp,[<hostip>],\n"
|
---|
633 | " <hostport>,[<guestip>],<guestport> |\n"
|
---|
634 | " natpf<1-N> delete <rulename> |\n"
|
---|
635 | " guestmemoryballoon <balloonsize in MB> |\n"
|
---|
636 | " usbattach <uuid>|<address>\n"
|
---|
637 | " [--capturefile <filename>] |\n"
|
---|
638 | " usbdetach <uuid>|<address> |\n"
|
---|
639 | " audioin on|off |\n"
|
---|
640 | " audioout on|off |\n");
|
---|
641 | #ifdef VBOX_WITH_SHARED_CLIPBOARD
|
---|
642 | RTStrmPrintf(pStrm,
|
---|
643 | " clipboard mode disabled|hosttoguest|guesttohost|\n"
|
---|
644 | " bidirectional |\n");
|
---|
645 | # ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
|
---|
646 | RTStrmPrintf(pStrm,
|
---|
647 | " clipboard filetransfers enabled|disabled |\n");
|
---|
648 | # endif
|
---|
649 | #endif
|
---|
650 | RTStrmPrintf(pStrm,
|
---|
651 | " draganddrop disabled|hosttoguest|guesttohost|\n"
|
---|
652 | " bidirectional |\n"
|
---|
653 | " vrde on|off |\n"
|
---|
654 | " vrdeport <port> |\n"
|
---|
655 | " vrdeproperty <name=[value]> |\n"
|
---|
656 | " vrdevideochannelquality <percent> |\n"
|
---|
657 | " setvideomodehint <xres> <yres> <bpp>\n"
|
---|
658 | " [[<display>] [<enabled:yes|no> |\n"
|
---|
659 | " [<xorigin> <yorigin>]]] |\n"
|
---|
660 | " setscreenlayout <display> on|primary <xorigin> <yorigin> <xres> <yres> <bpp> | off\n"
|
---|
661 | " screenshotpng <file> [display] |\n");
|
---|
662 | #ifdef VBOX_WITH_RECORDING
|
---|
663 | RTStrmPrintf(pStrm,
|
---|
664 | " recording on|off |\n"
|
---|
665 | " recording screens all|none|<screen>,[<screen>...] |\n"
|
---|
666 | " recording filename <file> |\n"
|
---|
667 | " recording videores <width>x<height> |\n"
|
---|
668 | " recording videorate <rate> |\n"
|
---|
669 | " recording videofps <fps> |\n"
|
---|
670 | " recording maxtime <s> |\n"
|
---|
671 | " recording maxfilesize <MB> |\n");
|
---|
672 | #endif /* VBOX_WITH_RECORDING */
|
---|
673 | RTStrmPrintf(pStrm,
|
---|
674 | " setcredentials <username>\n"
|
---|
675 | " --passwordfile <file> | <password>\n"
|
---|
676 | " <domain>\n"
|
---|
677 | " [--allowlocallogon <yes|no>] |\n"
|
---|
678 | " teleport --host <name> --port <port>\n"
|
---|
679 | " [--maxdowntime <msec>]\n"
|
---|
680 | " [--passwordfile <file> |\n"
|
---|
681 | " --password <password>] |\n"
|
---|
682 | " plugcpu <id> |\n"
|
---|
683 | " unplugcpu <id> |\n"
|
---|
684 | " cpuexecutioncap <1-100>\n"
|
---|
685 | " webcam <attach [path [settings]]> | <detach [path]> | <list>\n"
|
---|
686 | " addencpassword <id>\n"
|
---|
687 | " <password file>|-\n"
|
---|
688 | " [--removeonsuspend <yes|no>]\n"
|
---|
689 | " removeencpassword <id>\n"
|
---|
690 | " removeallencpasswords\n"
|
---|
691 | " changeuartmode<1-N> disconnected|\n"
|
---|
692 | " server <pipe>|\n"
|
---|
693 | " client <pipe>|\n"
|
---|
694 | " tcpserver <port>|\n"
|
---|
695 | " tcpclient <hostname:port>|\n"
|
---|
696 | " file <file>|\n"
|
---|
697 | " <devicename>\n"
|
---|
698 | " vm-process-priority default|flat|low|normal|high\n"
|
---|
699 | " autostart-enabled on|off\n"
|
---|
700 | " autostart-delay <seconds>\n"
|
---|
701 | "\n");
|
---|
702 | }
|
---|
703 |
|
---|
704 | if (enmCommand == USAGE_DISCARDSTATE || enmCommand == USAGE_S_ALL)
|
---|
705 | RTStrmPrintf(pStrm,
|
---|
706 | "%s discardstate %s <uuid|vmname>\n"
|
---|
707 | "\n", SEP);
|
---|
708 |
|
---|
709 | if (enmCommand == USAGE_ADOPTSTATE || enmCommand == USAGE_S_ALL)
|
---|
710 | RTStrmPrintf(pStrm,
|
---|
711 | "%s adoptstate %s <uuid|vmname> <state_file>\n"
|
---|
712 | "\n", SEP);
|
---|
713 |
|
---|
714 | if (enmCommand == USAGE_CLOSEMEDIUM || enmCommand == USAGE_S_ALL)
|
---|
715 | RTStrmPrintf(pStrm,
|
---|
716 | "%s closemedium %s [disk|dvd|floppy] <uuid|filename>\n"
|
---|
717 | " [--delete]\n"
|
---|
718 | "\n", SEP);
|
---|
719 |
|
---|
720 | if (enmCommand == USAGE_STORAGEATTACH || enmCommand == USAGE_S_ALL)
|
---|
721 | RTStrmPrintf(pStrm,
|
---|
722 | "%s storageattach %s <uuid|vmname>\n"
|
---|
723 | " --storagectl <name>\n"
|
---|
724 | " [--port <number>]\n"
|
---|
725 | " [--device <number>]\n"
|
---|
726 | " [--type dvddrive|hdd|fdd]\n"
|
---|
727 | " [--medium none|emptydrive|additions|\n"
|
---|
728 | " <uuid|filename>|host:<drive>|iscsi]\n"
|
---|
729 | " [--mtype normal|writethrough|immutable|shareable|\n"
|
---|
730 | " readonly|multiattach]\n"
|
---|
731 | " [--comment <text>]\n"
|
---|
732 | " [--setuuid <uuid>]\n"
|
---|
733 | " [--setparentuuid <uuid>]\n"
|
---|
734 | " [--passthrough on|off]\n"
|
---|
735 | " [--tempeject on|off]\n"
|
---|
736 | " [--nonrotational on|off]\n"
|
---|
737 | " [--discard on|off]\n"
|
---|
738 | " [--hotpluggable on|off]\n"
|
---|
739 | " [--bandwidthgroup <name>]\n"
|
---|
740 | " [--forceunmount]\n"
|
---|
741 | " [--server <name>|<ip>]\n"
|
---|
742 | " [--target <target>]\n"
|
---|
743 | " [--tport <port>]\n"
|
---|
744 | " [--lun <lun>]\n"
|
---|
745 | " [--encodedlun <lun>]\n"
|
---|
746 | " [--username <username>]\n"
|
---|
747 | " [--password <password>]\n"
|
---|
748 | " [--passwordfile <file>]\n"
|
---|
749 | " [--initiator <initiator>]\n"
|
---|
750 | " [--intnet]\n"
|
---|
751 | "\n", SEP);
|
---|
752 |
|
---|
753 | if (enmCommand == USAGE_STORAGECONTROLLER || enmCommand == USAGE_S_ALL)
|
---|
754 | RTStrmPrintf(pStrm,
|
---|
755 | "%s storagectl %s <uuid|vmname>\n"
|
---|
756 | " --name <name>\n"
|
---|
757 | " [--add ide|sata|scsi|floppy|sas|usb|pcie|virtio]\n"
|
---|
758 | " [--controller LSILogic|LSILogicSAS|BusLogic|\n"
|
---|
759 | " IntelAHCI|PIIX3|PIIX4|ICH6|I82078|\n"
|
---|
760 | " [ USB|NVMe|VirtIO]\n"
|
---|
761 | " [--portcount <1-n>]\n"
|
---|
762 | " [--hostiocache on|off]\n"
|
---|
763 | " [--bootable on|off]\n"
|
---|
764 | " [--rename <name>]\n"
|
---|
765 | " [--remove]\n"
|
---|
766 | "\n", SEP);
|
---|
767 |
|
---|
768 | if (enmCommand == USAGE_BANDWIDTHCONTROL || enmCommand == USAGE_S_ALL)
|
---|
769 | RTStrmPrintf(pStrm,
|
---|
770 | "%s bandwidthctl %s <uuid|vmname>\n"
|
---|
771 | " add <name> --type disk|network\n"
|
---|
772 | " --limit <megabytes per second>[k|m|g|K|M|G] |\n"
|
---|
773 | " set <name>\n"
|
---|
774 | " --limit <megabytes per second>[k|m|g|K|M|G] |\n"
|
---|
775 | " remove <name> |\n"
|
---|
776 | " list [--machinereadable]\n"
|
---|
777 | " (limit units: k=kilobit, m=megabit, g=gigabit,\n"
|
---|
778 | " K=kilobyte, M=megabyte, G=gigabyte)\n"
|
---|
779 | "\n", SEP);
|
---|
780 |
|
---|
781 | if (enmCommand == USAGE_SHOWMEDIUMINFO || enmCommand == USAGE_S_ALL)
|
---|
782 | RTStrmPrintf(pStrm,
|
---|
783 | "%s showmediuminfo %s [disk|dvd|floppy] <uuid|filename>\n"
|
---|
784 | "\n", SEP);
|
---|
785 |
|
---|
786 | if (enmCommand == USAGE_CREATEMEDIUM || enmCommand == USAGE_S_ALL)
|
---|
787 | RTStrmPrintf(pStrm,
|
---|
788 | "%s createmedium %s [disk|dvd|floppy] --filename <filename>\n"
|
---|
789 | " [--size <megabytes>|--sizebyte <bytes>]\n"
|
---|
790 | " [--diffparent <uuid>|<filename>]\n"
|
---|
791 | " [--format VDI|VMDK|VHD] (default: VDI)]\n"
|
---|
792 | " [--variant Standard,Fixed,Split2G,Stream,ESX,\n"
|
---|
793 | " Formatted,RawDisk]\n"
|
---|
794 | " [[--property <name>=<value>] --property <name>=<value>\n"
|
---|
795 | " --property-file <name>=</path/to/file/with/value>]...\n"
|
---|
796 | "\n", SEP);
|
---|
797 |
|
---|
798 | if (enmCommand == USAGE_MODIFYMEDIUM || enmCommand == USAGE_S_ALL)
|
---|
799 | RTStrmPrintf(pStrm,
|
---|
800 | "%s modifymedium %s [disk|dvd|floppy] <uuid|filename>\n"
|
---|
801 | " [--type normal|writethrough|immutable|shareable|\n"
|
---|
802 | " readonly|multiattach]\n"
|
---|
803 | " [--autoreset on|off]\n"
|
---|
804 | " [--property <name=[value]>]\n"
|
---|
805 | " [--compact]\n"
|
---|
806 | " [--resize <megabytes>|--resizebyte <bytes>]\n"
|
---|
807 | " [--move <path>]\n"
|
---|
808 | " [--setlocation <path>]\n"
|
---|
809 | " [--description <description string>]"
|
---|
810 | "\n", SEP);
|
---|
811 |
|
---|
812 | if (enmCommand == USAGE_CLONEMEDIUM || enmCommand == USAGE_S_ALL)
|
---|
813 | RTStrmPrintf(pStrm,
|
---|
814 | "%s clonemedium %s [disk|dvd|floppy] <uuid|inputfile> <uuid|outputfile>\n"
|
---|
815 | " [--format VDI|VMDK|VHD|RAW|<other>]\n"
|
---|
816 | " [--variant Standard,Fixed,Split2G,Stream,ESX]\n"
|
---|
817 | " [--existing]\n"
|
---|
818 | "\n", SEP);
|
---|
819 |
|
---|
820 | if (enmCommand == USAGE_MEDIUMPROPERTY || enmCommand == USAGE_S_ALL)
|
---|
821 | RTStrmPrintf(pStrm,
|
---|
822 | "%s mediumproperty %s [disk|dvd|floppy] set <uuid|filename>\n"
|
---|
823 | " <property> <value>\n"
|
---|
824 | "\n"
|
---|
825 | " [disk|dvd|floppy] get <uuid|filename>\n"
|
---|
826 | " <property>\n"
|
---|
827 | "\n"
|
---|
828 | " [disk|dvd|floppy] delete <uuid|filename>\n"
|
---|
829 | " <property>\n"
|
---|
830 | "\n", SEP);
|
---|
831 |
|
---|
832 | if (enmCommand == USAGE_ENCRYPTMEDIUM || enmCommand == USAGE_S_ALL)
|
---|
833 | RTStrmPrintf(pStrm,
|
---|
834 | "%s encryptmedium %s <uuid|filename>\n"
|
---|
835 | " [--newpassword <file>|-]\n"
|
---|
836 | " [--oldpassword <file>|-]\n"
|
---|
837 | " [--cipher <cipher identifier>]\n"
|
---|
838 | " [--newpasswordid <password identifier>]\n"
|
---|
839 | "\n", SEP);
|
---|
840 |
|
---|
841 | if (enmCommand == USAGE_MEDIUMENCCHKPWD || enmCommand == USAGE_S_ALL)
|
---|
842 | RTStrmPrintf(pStrm,
|
---|
843 | "%s checkmediumpwd %s <uuid|filename>\n"
|
---|
844 | " <pwd file>|-\n"
|
---|
845 | "\n", SEP);
|
---|
846 |
|
---|
847 | if (enmCommand == USAGE_CONVERTFROMRAW || enmCommand == USAGE_S_ALL)
|
---|
848 | RTStrmPrintf(pStrm,
|
---|
849 | "%s convertfromraw %s <filename> <outputfile>\n"
|
---|
850 | " [--format VDI|VMDK|VHD]\n"
|
---|
851 | " [--variant Standard,Fixed,Split2G,Stream,ESX]\n"
|
---|
852 | " [--uuid <uuid>]\n"
|
---|
853 | "%s convertfromraw %s stdin <outputfile> <bytes>\n"
|
---|
854 | " [--format VDI|VMDK|VHD]\n"
|
---|
855 | " [--variant Standard,Fixed,Split2G,Stream,ESX]\n"
|
---|
856 | " [--uuid <uuid>]\n"
|
---|
857 | "\n", SEP, SEP);
|
---|
858 |
|
---|
859 | if (enmCommand == USAGE_GETEXTRADATA || enmCommand == USAGE_S_ALL)
|
---|
860 | RTStrmPrintf(pStrm,
|
---|
861 | "%s getextradata %s global|<uuid|vmname>\n"
|
---|
862 | " <key>|[enumerate]\n"
|
---|
863 | "\n", SEP);
|
---|
864 |
|
---|
865 | if (enmCommand == USAGE_SETEXTRADATA || enmCommand == USAGE_S_ALL)
|
---|
866 | RTStrmPrintf(pStrm,
|
---|
867 | "%s setextradata %s global|<uuid|vmname>\n"
|
---|
868 | " <key>\n"
|
---|
869 | " [<value>] (no value deletes key)\n"
|
---|
870 | "\n", SEP);
|
---|
871 |
|
---|
872 | if (enmCommand == USAGE_SETPROPERTY || enmCommand == USAGE_S_ALL)
|
---|
873 | RTStrmPrintf(pStrm,
|
---|
874 | "%s setproperty %s machinefolder default|<folder> |\n"
|
---|
875 | " hwvirtexclusive on|off |\n"
|
---|
876 | " vrdeauthlibrary default|<library> |\n"
|
---|
877 | " websrvauthlibrary default|null|<library> |\n"
|
---|
878 | " vrdeextpack null|<library> |\n"
|
---|
879 | " autostartdbpath null|<folder> |\n"
|
---|
880 | " loghistorycount <value>\n"
|
---|
881 | " defaultfrontend default|<name>\n"
|
---|
882 | " logginglevel <log setting>\n"
|
---|
883 | " proxymode system|noproxy|manual\n"
|
---|
884 | " proxyurl <url>\n", SEP);
|
---|
885 | #ifdef VBOX_WITH_MAIN_NLS
|
---|
886 | RTStrmPrintf(pStrm,
|
---|
887 | " language <language id>\n");
|
---|
888 | #endif
|
---|
889 | RTStrmPrintf(pStrm,
|
---|
890 | "\n");
|
---|
891 |
|
---|
892 | if (enmCommand == USAGE_USBFILTER || enmCommand == USAGE_S_ALL)
|
---|
893 | {
|
---|
894 | if (fSubcommandScope & HELP_SCOPE_USBFILTER_ADD)
|
---|
895 | RTStrmPrintf(pStrm,
|
---|
896 | "%s usbfilter %s add <index,0-N>\n"
|
---|
897 | " --target <uuid|vmname>|global\n"
|
---|
898 | " --name <string>\n"
|
---|
899 | " --action ignore|hold (global filters only)\n"
|
---|
900 | " [--active yes|no] (yes)\n"
|
---|
901 | " [--vendorid <XXXX>] (null)\n"
|
---|
902 | " [--productid <XXXX>] (null)\n"
|
---|
903 | " [--revision <IIFF>] (null)\n"
|
---|
904 | " [--manufacturer <string>] (null)\n"
|
---|
905 | " [--product <string>] (null)\n"
|
---|
906 | " [--remote yes|no] (null, VM filters only)\n"
|
---|
907 | " [--serialnumber <string>] (null)\n"
|
---|
908 | " [--maskedinterfaces <XXXXXXXX>]\n"
|
---|
909 | "\n", SEP);
|
---|
910 |
|
---|
911 | if (fSubcommandScope & HELP_SCOPE_USBFILTER_MODIFY)
|
---|
912 | RTStrmPrintf(pStrm,
|
---|
913 | "%s usbfilter %s modify <index,0-N>\n"
|
---|
914 | " --target <uuid|vmname>|global\n"
|
---|
915 | " [--name <string>]\n"
|
---|
916 | " [--action ignore|hold] (global filters only)\n"
|
---|
917 | " [--active yes|no]\n"
|
---|
918 | " [--vendorid <XXXX>|\"\"]\n"
|
---|
919 | " [--productid <XXXX>|\"\"]\n"
|
---|
920 | " [--revision <IIFF>|\"\"]\n"
|
---|
921 | " [--manufacturer <string>|\"\"]\n"
|
---|
922 | " [--product <string>|\"\"]\n"
|
---|
923 | " [--remote yes|no] (null, VM filters only)\n"
|
---|
924 | " [--serialnumber <string>|\"\"]\n"
|
---|
925 | " [--maskedinterfaces <XXXXXXXX>]\n"
|
---|
926 | "\n", SEP);
|
---|
927 |
|
---|
928 | if (fSubcommandScope & HELP_SCOPE_USBFILTER_REMOVE)
|
---|
929 | RTStrmPrintf(pStrm,
|
---|
930 | "%s usbfilter %s remove <index,0-N>\n"
|
---|
931 | " --target <uuid|vmname>|global\n"
|
---|
932 | "\n", SEP);
|
---|
933 | }
|
---|
934 |
|
---|
935 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
936 | if (enmCommand == USAGE_GUESTPROPERTY || enmCommand == USAGE_S_ALL)
|
---|
937 | usageGuestProperty(pStrm, SEP);
|
---|
938 | #endif /* VBOX_WITH_GUEST_PROPS defined */
|
---|
939 |
|
---|
940 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
941 | if (enmCommand == USAGE_GUESTCONTROL || enmCommand == USAGE_S_ALL)
|
---|
942 | usageGuestControl(pStrm, SEP, fSubcommandScope);
|
---|
943 | #endif /* VBOX_WITH_GUEST_CONTROL defined */
|
---|
944 |
|
---|
945 | if (enmCommand == USAGE_METRICS || enmCommand == USAGE_S_ALL)
|
---|
946 | RTStrmPrintf(pStrm,
|
---|
947 | "%s metrics %s list [*|host|<vmname> [<metric_list>]]\n"
|
---|
948 | " (comma-separated)\n\n"
|
---|
949 | "%s metrics %s setup\n"
|
---|
950 | " [--period <seconds>] (default: 1)\n"
|
---|
951 | " [--samples <count>] (default: 1)\n"
|
---|
952 | " [--list]\n"
|
---|
953 | " [*|host|<vmname> [<metric_list>]]\n\n"
|
---|
954 | "%s metrics %s query [*|host|<vmname> [<metric_list>]]\n\n"
|
---|
955 | "%s metrics %s enable\n"
|
---|
956 | " [--list]\n"
|
---|
957 | " [*|host|<vmname> [<metric_list>]]\n\n"
|
---|
958 | "%s metrics %s disable\n"
|
---|
959 | " [--list]\n"
|
---|
960 | " [*|host|<vmname> [<metric_list>]]\n\n"
|
---|
961 | "%s metrics %s collect\n"
|
---|
962 | " [--period <seconds>] (default: 1)\n"
|
---|
963 | " [--samples <count>] (default: 1)\n"
|
---|
964 | " [--list]\n"
|
---|
965 | " [--detach]\n"
|
---|
966 | " [*|host|<vmname> [<metric_list>]]\n"
|
---|
967 | "\n", SEP, SEP, SEP, SEP, SEP, SEP);
|
---|
968 |
|
---|
969 | #if defined(VBOX_WITH_NAT_SERVICE)
|
---|
970 | if (enmCommand == USAGE_NATNETWORK || enmCommand == USAGE_S_ALL)
|
---|
971 | {
|
---|
972 | RTStrmPrintf(pStrm,
|
---|
973 | "%s natnetwork %s add --netname <name>\n"
|
---|
974 | " --network <network>\n"
|
---|
975 | " [--enable|--disable]\n"
|
---|
976 | " [--dhcp on|off]\n"
|
---|
977 | " [--port-forward-4 <rule>]\n"
|
---|
978 | " [--loopback-4 <rule>]\n"
|
---|
979 | " [--ipv6 on|off]\n"
|
---|
980 | " [--port-forward-6 <rule>]\n"
|
---|
981 | " [--loopback-6 <rule>]\n\n"
|
---|
982 | "%s natnetwork %s remove --netname <name>\n\n"
|
---|
983 | "%s natnetwork %s modify --netname <name>\n"
|
---|
984 | " [--network <network>]\n"
|
---|
985 | " [--enable|--disable]\n"
|
---|
986 | " [--dhcp on|off]\n"
|
---|
987 | " [--port-forward-4 <rule>]\n"
|
---|
988 | " [--loopback-4 <rule>]\n"
|
---|
989 | " [--ipv6 on|off]\n"
|
---|
990 | " [--port-forward-6 <rule>]\n"
|
---|
991 | " [--loopback-6 <rule>]\n\n"
|
---|
992 | "%s natnetwork %s start --netname <name>\n\n"
|
---|
993 | "%s natnetwork %s stop --netname <name>\n\n"
|
---|
994 | "%s natnetwork %s list [<pattern>]\n"
|
---|
995 | "\n", SEP, SEP, SEP, SEP, SEP, SEP);
|
---|
996 |
|
---|
997 |
|
---|
998 | }
|
---|
999 | #endif
|
---|
1000 |
|
---|
1001 | #if defined(VBOX_WITH_NETFLT)
|
---|
1002 | if (enmCommand == USAGE_HOSTONLYIFS || enmCommand == USAGE_S_ALL)
|
---|
1003 | {
|
---|
1004 | RTStrmPrintf(pStrm,
|
---|
1005 | "%s hostonlyif %s ipconfig <name>\n"
|
---|
1006 | " [--dhcp |\n"
|
---|
1007 | " --ip <ipv4> [--netmask <ipv4> (def:255.255.255.0)]|\n"
|
---|
1008 | " --ipv6 <ipv6> [--netmasklengthv6 <N> (def:64)]]", SEP);
|
---|
1009 | # if !defined(RT_OS_SOLARIS) || defined(VBOX_ONLY_DOCS)
|
---|
1010 | RTStrmPrintf(pStrm,
|
---|
1011 | " |\n"
|
---|
1012 | " create |\n"
|
---|
1013 | " remove <name>\n");
|
---|
1014 | # else
|
---|
1015 | RTStrmPrintf(pStrm,
|
---|
1016 | "\n");
|
---|
1017 | # endif
|
---|
1018 | RTStrmPrintf(pStrm,
|
---|
1019 | "\n");
|
---|
1020 | }
|
---|
1021 | #endif
|
---|
1022 |
|
---|
1023 | if (enmCommand == USAGE_USBDEVSOURCE || enmCommand == USAGE_S_ALL)
|
---|
1024 | {
|
---|
1025 | RTStrmPrintf(pStrm,
|
---|
1026 | "%s usbdevsource %s add <source name>\n"
|
---|
1027 | " --backend <backend>\n"
|
---|
1028 | " --address <address>\n"
|
---|
1029 | "%s usbdevsource %s remove <source name>\n"
|
---|
1030 | "\n", SEP, SEP);
|
---|
1031 | }
|
---|
1032 |
|
---|
1033 | #ifndef VBOX_ONLY_DOCS /* Converted to man page, not needed. */
|
---|
1034 | if (enmCommand == USAGE_S_ALL)
|
---|
1035 | {
|
---|
1036 | uint32_t cPendingBlankLines = 0;
|
---|
1037 | #ifdef VBOX_WITH_VBOXMANAGE_NLS
|
---|
1038 | PHELP_LANG_ENTRY pHelpLangEntry = ASMAtomicReadPtrT(&g_pHelpLangEntry, PHELP_LANG_ENTRY);
|
---|
1039 | #else
|
---|
1040 | PHELP_LANG_ENTRY pHelpLangEntry = (PHELP_LANG_ENTRY)g_pHelpLangEntry;
|
---|
1041 | #endif
|
---|
1042 | for (uint32_t i = 0; i < pHelpLangEntry->cHelpEntries; i++)
|
---|
1043 | {
|
---|
1044 | PCRTMSGREFENTRY pHelp = pHelpLangEntry->papHelpEntries[i];
|
---|
1045 |
|
---|
1046 | while (cPendingBlankLines-- > 0)
|
---|
1047 | RTStrmPutCh(pStrm, '\n');
|
---|
1048 | char szFirstChar[16] = {0};
|
---|
1049 | const char *pszNext = firstCharUppercase(pHelp->pszBrief, szFirstChar);
|
---|
1050 | RTStrmPrintf(pStrm, " %s%s:\n", szFirstChar, pszNext);
|
---|
1051 | cPendingBlankLines = 0;
|
---|
1052 | RTMsgRefEntryPrintStringTable(pStrm, &pHelp->Synopsis, RTMSGREFENTRYSTR_SCOPE_GLOBAL,
|
---|
1053 | &cPendingBlankLines, NULL /*pcLinesWritten*/);
|
---|
1054 | cPendingBlankLines = RT_MAX(cPendingBlankLines, 1);
|
---|
1055 | }
|
---|
1056 | }
|
---|
1057 | #endif
|
---|
1058 | }
|
---|
1059 |
|
---|
1060 | /**
|
---|
1061 | * Print a usage synopsis and the syntax error message.
|
---|
1062 | * @returns RTEXITCODE_SYNTAX.
|
---|
1063 | */
|
---|
1064 | RTEXITCODE errorSyntax(USAGECATEGORY enmCommand, const char *pszFormat, ...)
|
---|
1065 | {
|
---|
1066 | va_list args;
|
---|
1067 | showLogo(g_pStdErr); // show logo even if suppressed
|
---|
1068 | #ifndef VBOX_ONLY_DOCS
|
---|
1069 | if (g_fInternalMode)
|
---|
1070 | printUsageInternal(enmCommand, g_pStdErr);
|
---|
1071 | else if (g_enmCurCommand == HELP_CMD_VBOXMANAGE_INVALID)
|
---|
1072 | printUsage(enmCommand, RTMSGREFENTRYSTR_SCOPE_GLOBAL, g_pStdErr);
|
---|
1073 | else
|
---|
1074 | printUsage(g_pStdErr);
|
---|
1075 | #else
|
---|
1076 | RT_NOREF_PV(enmCommand);
|
---|
1077 | #endif
|
---|
1078 | va_start(args, pszFormat);
|
---|
1079 | RTStrmPrintf(g_pStdErr, Help::tr("\nSyntax error: %N\n"), pszFormat, &args);
|
---|
1080 | va_end(args);
|
---|
1081 | return RTEXITCODE_SYNTAX;
|
---|
1082 | }
|
---|
1083 |
|
---|
1084 | /**
|
---|
1085 | * Print a usage synopsis and the syntax error message.
|
---|
1086 | * @returns RTEXITCODE_SYNTAX.
|
---|
1087 | */
|
---|
1088 | RTEXITCODE errorSyntaxEx(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, const char *pszFormat, ...)
|
---|
1089 | {
|
---|
1090 | va_list args;
|
---|
1091 | showLogo(g_pStdErr); // show logo even if suppressed
|
---|
1092 | #ifndef VBOX_ONLY_DOCS
|
---|
1093 | if (g_fInternalMode)
|
---|
1094 | printUsageInternal(enmCommand, g_pStdErr);
|
---|
1095 | else if (g_enmCurCommand == HELP_CMD_VBOXMANAGE_INVALID)
|
---|
1096 | printUsage(enmCommand, fSubcommandScope, g_pStdErr);
|
---|
1097 | else
|
---|
1098 | printUsage(g_pStdErr);
|
---|
1099 | #else
|
---|
1100 | RT_NOREF2(enmCommand, fSubcommandScope);
|
---|
1101 | #endif
|
---|
1102 | va_start(args, pszFormat);
|
---|
1103 | RTStrmPrintf(g_pStdErr, Help::tr("\nSyntax error: %N\n"), pszFormat, &args);
|
---|
1104 | va_end(args);
|
---|
1105 | return RTEXITCODE_SYNTAX;
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | /**
|
---|
1109 | * errorSyntax for RTGetOpt users.
|
---|
1110 | *
|
---|
1111 | * @returns RTEXITCODE_SYNTAX.
|
---|
1112 | *
|
---|
1113 | * @param enmCommand The command.
|
---|
1114 | * @param fSubcommandScope The subcommand scope, REFENTRYSTR_SCOPE_GLOBAL
|
---|
1115 | * for all.
|
---|
1116 | * @param rc The RTGetOpt return code.
|
---|
1117 | * @param pValueUnion The value union.
|
---|
1118 | */
|
---|
1119 | RTEXITCODE errorGetOptEx(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, int rc, union RTGETOPTUNION const *pValueUnion)
|
---|
1120 | {
|
---|
1121 | /*
|
---|
1122 | * Check if it is an unhandled standard option.
|
---|
1123 | */
|
---|
1124 | #ifndef VBOX_ONLY_DOCS
|
---|
1125 | if (rc == 'V')
|
---|
1126 | {
|
---|
1127 | RTPrintf("%sr%d\n", VBOX_VERSION_STRING, RTBldCfgRevision());
|
---|
1128 | return RTEXITCODE_SUCCESS;
|
---|
1129 | }
|
---|
1130 | #endif
|
---|
1131 |
|
---|
1132 | if (rc == 'h')
|
---|
1133 | {
|
---|
1134 | showLogo(g_pStdErr);
|
---|
1135 | #ifndef VBOX_ONLY_DOCS
|
---|
1136 | if (g_fInternalMode)
|
---|
1137 | printUsageInternal(enmCommand, g_pStdOut);
|
---|
1138 | else if (g_enmCurCommand == HELP_CMD_VBOXMANAGE_INVALID)
|
---|
1139 | printUsage(enmCommand, fSubcommandScope, g_pStdOut);
|
---|
1140 | else
|
---|
1141 | printUsage(g_pStdErr);
|
---|
1142 | #endif
|
---|
1143 | return RTEXITCODE_SUCCESS;
|
---|
1144 | }
|
---|
1145 |
|
---|
1146 | /*
|
---|
1147 | * General failure.
|
---|
1148 | */
|
---|
1149 | showLogo(g_pStdErr); // show logo even if suppressed
|
---|
1150 | #ifndef VBOX_ONLY_DOCS
|
---|
1151 | if (g_fInternalMode)
|
---|
1152 | printUsageInternal(enmCommand, g_pStdErr);
|
---|
1153 | else if (g_enmCurCommand == HELP_CMD_VBOXMANAGE_INVALID)
|
---|
1154 | printUsage(enmCommand, fSubcommandScope, g_pStdErr);
|
---|
1155 | else
|
---|
1156 | printUsage(g_pStdErr);
|
---|
1157 | #else
|
---|
1158 | RT_NOREF2(enmCommand, fSubcommandScope);
|
---|
1159 | #endif
|
---|
1160 |
|
---|
1161 | if (rc == VINF_GETOPT_NOT_OPTION)
|
---|
1162 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, Help::tr("Invalid parameter '%s'"), pValueUnion->psz);
|
---|
1163 | if (rc > 0)
|
---|
1164 | {
|
---|
1165 | if (RT_C_IS_PRINT(rc))
|
---|
1166 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, Help::tr("Invalid option -%c"), rc);
|
---|
1167 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, Help::tr("Invalid option case %i"), rc);
|
---|
1168 | }
|
---|
1169 | if (rc == VERR_GETOPT_UNKNOWN_OPTION)
|
---|
1170 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, Help::tr("Unknown option: %s"), pValueUnion->psz);
|
---|
1171 | if (rc == VERR_GETOPT_INVALID_ARGUMENT_FORMAT)
|
---|
1172 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, Help::tr("Invalid argument format: %s"), pValueUnion->psz);
|
---|
1173 | if (pValueUnion->pDef)
|
---|
1174 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "%s: %Rrs", pValueUnion->pDef->pszLong, rc);
|
---|
1175 | return RTMsgErrorExit(RTEXITCODE_SYNTAX, "%Rrs", rc);
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 |
|
---|
1179 | /**
|
---|
1180 | * errorSyntax for RTGetOpt users.
|
---|
1181 | *
|
---|
1182 | * @returns RTEXITCODE_SYNTAX.
|
---|
1183 | *
|
---|
1184 | * @param enmCommand The command.
|
---|
1185 | * @param rc The RTGetOpt return code.
|
---|
1186 | * @param pValueUnion The value union.
|
---|
1187 | */
|
---|
1188 | RTEXITCODE errorGetOpt(USAGECATEGORY enmCommand, int rc, union RTGETOPTUNION const *pValueUnion)
|
---|
1189 | {
|
---|
1190 | return errorGetOptEx(enmCommand, RTMSGREFENTRYSTR_SCOPE_GLOBAL, rc, pValueUnion);
|
---|
1191 | }
|
---|
1192 |
|
---|