VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp@ 68838

最後變更 在這個檔案從68838是 68838,由 vboxsync 提交於 8 年 前

VBoxManageHelp.cpp: Use RTStrmQueryTerminalWidth to get the screen width when formatting help text. Fixed bug causing it to not make progress if a word is too long compared to the screen width.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 69.5 KB
 
1/* $Id: VBoxManageHelp.cpp 68838 2017-09-22 16:55:24Z vboxsync $ */
2/** @file
3 * VBoxManage - help and other message output.
4 */
5
6/*
7 * Copyright (C) 2006-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.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/buildconfig.h>
25#include <iprt/ctype.h>
26#include <iprt/env.h>
27#include <iprt/err.h>
28#include <iprt/getopt.h>
29#include <iprt/stream.h>
30
31#include "VBoxManage.h"
32
33
34/*********************************************************************************************************************************
35* Defined Constants And Macros *
36*********************************************************************************************************************************/
37/** If the usage is the given number of length long or longer, the error is
38 * repeated so the user can actually see it. */
39#define ERROR_REPEAT_AFTER_USAGE_LENGTH 16
40
41
42/*********************************************************************************************************************************
43* Global Variables *
44*********************************************************************************************************************************/
45#ifndef VBOX_ONLY_DOCS
46enum HELP_CMD_VBOXMANAGE g_enmCurCommand = HELP_CMD_VBOXMANAGE_INVALID;
47/** The scope maskt for the current subcommand. */
48uint64_t g_fCurSubcommandScope = REFENTRYSTR_SCOPE_GLOBAL;
49/** String of spaces that can be used for indentation. */
50static const char g_szSpaces[] = " ";
51
52/**
53 * Sets the current command.
54 *
55 * This affects future calls to error and help functions.
56 *
57 * @param enmCommand The command.
58 */
59void setCurrentCommand(enum HELP_CMD_VBOXMANAGE enmCommand)
60{
61 Assert(g_enmCurCommand == HELP_CMD_VBOXMANAGE_INVALID);
62 g_enmCurCommand = enmCommand;
63 g_fCurSubcommandScope = REFENTRYSTR_SCOPE_GLOBAL;
64}
65
66
67/**
68 * Sets the current subcommand.
69 *
70 * This affects future calls to error and help functions.
71 *
72 * @param fSubcommandScope The subcommand scope.
73 */
74void setCurrentSubcommand(uint64_t fSubcommandScope)
75{
76 g_fCurSubcommandScope = fSubcommandScope;
77}
78
79
80
81/**
82 * Retruns the width for the given handle.
83 *
84 * @returns Screen width.
85 * @param pStrm The stream, g_pStdErr or g_pStdOut.
86 */
87static uint32_t getScreenWidth(PRTSTREAM pStrm)
88{
89 static uint32_t s_acch[2] = { 0, 0 };
90 uint32_t iWhich = pStrm == g_pStdErr ? 1 : 0;
91 uint32_t cch = s_acch[iWhich];
92 if (cch)
93 return cch;
94
95 const char *psz = RTEnvGet("VBOXMANAGE_SCREEN_WIDTH");
96 if ( !psz
97 || RTStrToUInt32Full(psz, 0, &cch) != VINF_SUCCESS
98 || cch == 0)
99 {
100 int rc = RTStrmQueryTerminalWidth(pStrm, &cch);
101 if (rc == VERR_INVALID_FUNCTION)
102 {
103 /* It's not a console, but in case we're being piped to less/more/list
104 we look for a console handle on the other standard output handle
105 and standard input. (Latter doesn't work on windows.) */
106 rc = RTStrmQueryTerminalWidth(pStrm == g_pStdErr ? g_pStdOut : g_pStdErr, &cch);
107 if (rc == VERR_INVALID_FUNCTION || rc == VERR_INVALID_HANDLE)
108 rc = RTStrmQueryTerminalWidth(g_pStdIn, &cch);
109 if (RT_FAILURE(rc))
110 cch = 80;
111 }
112 }
113
114 s_acch[iWhich] = cch;
115 return cch;
116}
117
118
119/**
120 * Prints a string table string (paragraph), performing non-breaking-space
121 * replacement and wrapping.
122 *
123 * @returns Number of lines written.
124 * @param pStrm The output stream.
125 * @param psz The string table string to print.
126 * @param cchMaxWidth The maximum output width.
127 * @param fFlags String flags that may affect formatting.
128 */
129static uint32_t printString(PRTSTREAM pStrm, const char *psz, uint32_t cchMaxWidth, uint64_t fFlags)
130{
131 uint32_t cLinesWritten;
132 size_t cch = strlen(psz);
133 const char *pszNbsp = strchr(psz, REFENTRY_NBSP);
134
135 /*
136 * No-wrap case is simpler, so handle that separately.
137 */
138 if (cch <= cchMaxWidth)
139 {
140 if (!pszNbsp)
141 RTStrmWrite(pStrm, psz, cch);
142 else
143 {
144 do
145 {
146 RTStrmWrite(pStrm, psz, pszNbsp - psz);
147 RTStrmPutCh(pStrm, ' ');
148 psz = pszNbsp + 1;
149 pszNbsp = strchr(psz, REFENTRY_NBSP);
150 } while (pszNbsp);
151 RTStrmWrite(pStrm, psz, strlen(psz));
152 }
153 RTStrmPutCh(pStrm, '\n');
154 cLinesWritten = 1;
155 }
156 /*
157 * We need to wrap stuff, too bad.
158 */
159 else
160 {
161 /* Figure the paragraph indent level first. */
162 uint32_t cchIndent = 0;
163 while (*psz == ' ')
164 cchIndent++, psz++;
165 Assert(cchIndent + 4 + 1 <= RT_ELEMENTS(g_szSpaces));
166
167 if (cchIndent + 8 >= cchMaxWidth)
168 cchMaxWidth += cchIndent + 8;
169
170 /* Work our way thru the string, line by line. */
171 uint32_t cchHangingIndent = 0;
172 cLinesWritten = 0;
173 do
174 {
175 RTStrmWrite(pStrm, g_szSpaces, cchIndent + cchHangingIndent);
176 size_t offLine = cchIndent + cchHangingIndent;
177 bool fPendingSpace = false;
178 do
179 {
180 const char *pszSpace = strchr(psz, ' ');
181 size_t cchWord = pszSpace ? pszSpace - psz : strlen(psz);
182 if ( offLine + cchWord + fPendingSpace > cchMaxWidth
183 && offLine != cchIndent
184 && fPendingSpace /* don't stop before first word */)
185 break;
186
187 pszNbsp = (const char *)memchr(psz, REFENTRY_NBSP, cchWord);
188 while (pszNbsp)
189 {
190 size_t cchSubWord = pszNbsp - psz;
191 if (fPendingSpace)
192 RTStrmPutCh(pStrm, ' ');
193 RTStrmWrite(pStrm, psz, cchSubWord);
194 offLine += cchSubWord + fPendingSpace;
195 psz += cchSubWord + 1;
196 cchWord -= cchSubWord + 1;
197 pszNbsp = (const char *)memchr(psz, REFENTRY_NBSP, cchWord);
198 fPendingSpace = true;
199 }
200
201 if (fPendingSpace)
202 RTStrmPutCh(pStrm, ' ');
203 RTStrmWrite(pStrm, psz, cchWord);
204 offLine += cchWord + fPendingSpace;
205 psz = pszSpace ? pszSpace + 1 : strchr(psz, '\0');
206 fPendingSpace = true;
207 } while (offLine < cchMaxWidth && *psz != '\0');
208 RTStrmPutCh(pStrm, '\n');
209 cLinesWritten++;
210
211 /* Set up hanging indent if relevant. */
212 if (fFlags & REFENTRYSTR_FLAGS_SYNOPSIS)
213 cchHangingIndent = 4;
214 } while (*psz != '\0');
215 }
216 return cLinesWritten;
217}
218
219
220/**
221 * Checks if the given string is empty (only spaces).
222 * @returns true if empty, false if not.
223 * @param psz The string to examine.
224 */
225DECLINLINE(bool) isEmptyString(const char *psz)
226{
227 char ch;
228 while ((ch = *psz) == ' ')
229 psz++;
230 return ch == '\0';
231}
232
233
234/**
235 * Prints a string table.
236 *
237 * @returns Current number of pending blank lines.
238 * @param pStrm The output stream.
239 * @param pStrTab The string table.
240 * @param fScope The selection scope.
241 * @param cPendingBlankLines Pending blank lines from previous string table.
242 * @param pcLinesWritten Pointer to variable that should be incremented
243 * by the number of lines written. Optional.
244 */
245static uint32_t printStringTable(PRTSTREAM pStrm, PCREFENTRYSTRTAB pStrTab, uint64_t fScope, uint32_t cPendingBlankLines,
246 uint32_t *pcLinesWritten = NULL)
247{
248 uint32_t cLinesWritten = 0;
249 uint32_t cchWidth = getScreenWidth(pStrm);
250 uint64_t fPrevScope = fScope;
251 for (uint32_t i = 0; i < pStrTab->cStrings; i++)
252 {
253 uint64_t fCurScope = pStrTab->paStrings[i].fScope;
254 if ((fCurScope & REFENTRYSTR_SCOPE_MASK) == REFENTRYSTR_SCOPE_SAME)
255 {
256 fCurScope &= ~REFENTRYSTR_SCOPE_MASK;
257 fCurScope |= (fPrevScope & REFENTRYSTR_SCOPE_MASK);
258 }
259 if (fCurScope & REFENTRYSTR_SCOPE_MASK & fScope)
260 {
261 const char *psz = pStrTab->paStrings[i].psz;
262 if (psz && !isEmptyString(psz))
263 {
264 while (cPendingBlankLines > 0)
265 {
266 cPendingBlankLines--;
267 RTStrmPutCh(pStrm, '\n');
268 cLinesWritten++;
269 }
270 cLinesWritten += printString(pStrm, psz, cchWidth, fCurScope & REFENTRYSTR_FLAGS_MASK);
271 }
272 else
273 cPendingBlankLines++;
274 }
275 fPrevScope = fCurScope;
276 }
277
278 if (pcLinesWritten)
279 *pcLinesWritten += cLinesWritten;
280 return cPendingBlankLines;
281}
282
283
284/**
285 * Prints brief help for a command or subcommand.
286 *
287 * @returns Number of lines written.
288 * @param enmCommand The command.
289 * @param fSubcommandScope The subcommand scope, REFENTRYSTR_SCOPE_GLOBAL
290 * for all.
291 * @param pStrm The output stream.
292 */
293static uint32_t printBriefCommandOrSubcommandHelp(enum HELP_CMD_VBOXMANAGE enmCommand, uint64_t fSubcommandScope, PRTSTREAM pStrm)
294{
295 uint32_t cLinesWritten = 0;
296 uint32_t cPendingBlankLines = 0;
297 uint32_t cFound = 0;
298 for (uint32_t i = 0; i < g_cHelpEntries; i++)
299 {
300 PCREFENTRY pHelp = g_apHelpEntries[i];
301 if (pHelp->idInternal == (int64_t)enmCommand)
302 {
303 cFound++;
304 if (cFound == 1)
305 {
306 if (fSubcommandScope == REFENTRYSTR_SCOPE_GLOBAL)
307 RTStrmPrintf(pStrm, "Usage - %c%s:\n", RT_C_TO_UPPER(pHelp->pszBrief[0]), pHelp->pszBrief + 1);
308 else
309 RTStrmPrintf(pStrm, "Usage:\n");
310 }
311 cPendingBlankLines = printStringTable(pStrm, &pHelp->Synopsis, fSubcommandScope, cPendingBlankLines, &cLinesWritten);
312 if (!cPendingBlankLines)
313 cPendingBlankLines = 1;
314 }
315 }
316 Assert(cFound > 0);
317 return cLinesWritten;
318}
319
320
321/**
322 * Prints the brief usage information for the current (sub)command.
323 *
324 * @param pStrm The output stream.
325 */
326void printUsage(PRTSTREAM pStrm)
327{
328 printBriefCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, pStrm);
329}
330
331
332/**
333 * Prints full help for a command or subcommand.
334 *
335 * @param enmCommand The command.
336 * @param fSubcommandScope The subcommand scope, REFENTRYSTR_SCOPE_GLOBAL
337 * for all.
338 * @param pStrm The output stream.
339 */
340static void printFullCommandOrSubcommandHelp(enum HELP_CMD_VBOXMANAGE enmCommand, uint64_t fSubcommandScope, PRTSTREAM pStrm)
341{
342 uint32_t cPendingBlankLines = 0;
343 uint32_t cFound = 0;
344 for (uint32_t i = 0; i < g_cHelpEntries; i++)
345 {
346 PCREFENTRY pHelp = g_apHelpEntries[i];
347 if ( pHelp->idInternal == (int64_t)enmCommand
348 || enmCommand == HELP_CMD_VBOXMANAGE_INVALID)
349 {
350 cFound++;
351 cPendingBlankLines = printStringTable(pStrm, &pHelp->Help, fSubcommandScope, cPendingBlankLines);
352 if (cPendingBlankLines < 2)
353 cPendingBlankLines = 2;
354 }
355 }
356 Assert(cFound > 0);
357}
358
359
360/**
361 * Prints the full help for the current (sub)command.
362 *
363 * @param pStrm The output stream.
364 */
365void printHelp(PRTSTREAM pStrm)
366{
367 printFullCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, pStrm);
368}
369
370
371/**
372 * Display no subcommand error message and current command usage.
373 *
374 * @returns RTEXITCODE_SYNTAX.
375 */
376RTEXITCODE errorNoSubcommand(void)
377{
378 Assert(g_enmCurCommand != HELP_CMD_VBOXMANAGE_INVALID);
379 Assert(g_fCurSubcommandScope == REFENTRYSTR_SCOPE_GLOBAL);
380
381 return errorSyntax("No subcommand specified");
382}
383
384
385/**
386 * Display unknown subcommand error message and current command usage.
387 *
388 * May show full command help instead if the subcommand is a common help option.
389 *
390 * @returns RTEXITCODE_SYNTAX, or RTEXITCODE_SUCCESS if common help option.
391 * @param pszSubcommand The name of the alleged subcommand.
392 */
393RTEXITCODE errorUnknownSubcommand(const char *pszSubcommand)
394{
395 Assert(g_enmCurCommand != HELP_CMD_VBOXMANAGE_INVALID);
396 Assert(g_fCurSubcommandScope == REFENTRYSTR_SCOPE_GLOBAL);
397
398 /* check if help was requested. */
399 if ( strcmp(pszSubcommand, "--help") == 0
400 || strcmp(pszSubcommand, "-h") == 0
401 || strcmp(pszSubcommand, "-?") == 0)
402 {
403 printFullCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, g_pStdOut);
404 return RTEXITCODE_SUCCESS;
405 }
406
407 return errorSyntax("Unknown subcommand: %s", pszSubcommand);
408}
409
410
411/**
412 * Display too many parameters error message and current command usage.
413 *
414 * May show full command help instead if the subcommand is a common help option.
415 *
416 * @returns RTEXITCODE_SYNTAX, or RTEXITCODE_SUCCESS if common help option.
417 * @param papszArgs The first unwanted parameter. Terminated by
418 * NULL entry.
419 */
420RTEXITCODE errorTooManyParameters(char **papszArgs)
421{
422 Assert(g_enmCurCommand != HELP_CMD_VBOXMANAGE_INVALID);
423 Assert(g_fCurSubcommandScope != REFENTRYSTR_SCOPE_GLOBAL);
424
425 /* check if help was requested. */
426 if (papszArgs)
427 {
428 for (uint32_t i = 0; papszArgs[i]; i++)
429 if ( strcmp(papszArgs[i], "--help") == 0
430 || strcmp(papszArgs[i], "-h") == 0
431 || strcmp(papszArgs[i], "-?") == 0)
432 {
433 printFullCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, g_pStdOut);
434 return RTEXITCODE_SUCCESS;
435 }
436 else if (!strcmp(papszArgs[i], "--"))
437 break;
438 }
439
440 return errorSyntax("Too many parameters");
441}
442
443
444/**
445 * Display current (sub)command usage and the custom error message.
446 *
447 * @returns RTEXITCODE_SYNTAX.
448 * @param pszFormat Custom error message format string.
449 * @param ... Format arguments.
450 */
451RTEXITCODE errorSyntax(const char *pszFormat, ...)
452{
453 Assert(g_enmCurCommand != HELP_CMD_VBOXMANAGE_INVALID);
454
455 showLogo(g_pStdErr);
456
457 va_list va;
458 va_start(va, pszFormat);
459 RTMsgErrorV(pszFormat, va);
460 va_end(va);
461
462 RTStrmPutCh(g_pStdErr, '\n');
463 if ( printBriefCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, g_pStdErr)
464 >= ERROR_REPEAT_AFTER_USAGE_LENGTH)
465 {
466 /* Usage was very long, repeat the error message. */
467 RTStrmPutCh(g_pStdErr, '\n');
468 va_start(va, pszFormat);
469 RTMsgErrorV(pszFormat, va);
470 va_end(va);
471 }
472 return RTEXITCODE_SYNTAX;
473}
474
475
476/**
477 * Worker for errorGetOpt.
478 *
479 * @param rcGetOpt The RTGetOpt return value.
480 * @param pValueUnion The value union returned by RTGetOpt.
481 */
482static void errorGetOptWorker(int rcGetOpt, union RTGETOPTUNION const *pValueUnion)
483{
484 if (rcGetOpt == VINF_GETOPT_NOT_OPTION)
485 RTMsgError("Invalid parameter '%s'", pValueUnion->psz);
486 else if (rcGetOpt > 0)
487 {
488 if (RT_C_IS_PRINT(rcGetOpt))
489 RTMsgError("Invalid option -%c", rcGetOpt);
490 else
491 RTMsgError("Invalid option case %i", rcGetOpt);
492 }
493 else if (rcGetOpt == VERR_GETOPT_UNKNOWN_OPTION)
494 RTMsgError("Unknown option: %s", pValueUnion->psz);
495 else if (rcGetOpt == VERR_GETOPT_INVALID_ARGUMENT_FORMAT)
496 RTMsgError("Invalid argument format: %s", pValueUnion->psz);
497 else if (pValueUnion->pDef)
498 RTMsgError("%s: %Rrs", pValueUnion->pDef->pszLong, rcGetOpt);
499 else
500 RTMsgError("%Rrs", rcGetOpt);
501}
502
503
504/**
505 * Handled an RTGetOpt error or common option.
506 *
507 * This implements the 'V' and 'h' cases. It reports appropriate syntax errors
508 * for other @a rcGetOpt values.
509 *
510 * @retval RTEXITCODE_SUCCESS if help or version request.
511 * @retval RTEXITCODE_SYNTAX if not help or version request.
512 * @param rcGetOpt The RTGetOpt return value.
513 * @param pValueUnion The value union returned by RTGetOpt.
514 */
515RTEXITCODE errorGetOpt(int rcGetOpt, union RTGETOPTUNION const *pValueUnion)
516{
517 Assert(g_enmCurCommand != HELP_CMD_VBOXMANAGE_INVALID);
518
519 /*
520 * Check if it is an unhandled standard option.
521 */
522 if (rcGetOpt == 'V')
523 {
524 RTPrintf("%sr%d\n", VBOX_VERSION_STRING, RTBldCfgRevision());
525 return RTEXITCODE_SUCCESS;
526 }
527
528 if (rcGetOpt == 'h')
529 {
530 printFullCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, g_pStdOut);
531 return RTEXITCODE_SUCCESS;
532 }
533
534 /*
535 * We failed.
536 */
537 showLogo(g_pStdErr);
538 errorGetOptWorker(rcGetOpt, pValueUnion);
539 if ( printBriefCommandOrSubcommandHelp(g_enmCurCommand, g_fCurSubcommandScope, g_pStdErr)
540 >= ERROR_REPEAT_AFTER_USAGE_LENGTH)
541 {
542 /* Usage was very long, repeat the error message. */
543 RTStrmPutCh(g_pStdErr, '\n');
544 errorGetOptWorker(rcGetOpt, pValueUnion);
545 }
546 return RTEXITCODE_SYNTAX;
547}
548
549#endif /* !VBOX_ONLY_DOCS */
550
551
552
553void showLogo(PRTSTREAM pStrm)
554{
555 static bool s_fShown; /* show only once */
556
557 if (!s_fShown)
558 {
559 RTStrmPrintf(pStrm, VBOX_PRODUCT " Command Line Management Interface Version "
560 VBOX_VERSION_STRING "\n"
561 "(C) 2005-" VBOX_C_YEAR " " VBOX_VENDOR "\n"
562 "All rights reserved.\n"
563 "\n");
564 s_fShown = true;
565 }
566}
567
568
569
570
571void printUsage(USAGECATEGORY fCategory, uint32_t fSubCategory, PRTSTREAM pStrm)
572{
573 bool fDumpOpts = false;
574#ifdef RT_OS_LINUX
575 bool fLinux = true;
576#else
577 bool fLinux = false;
578#endif
579#ifdef RT_OS_WINDOWS
580 bool fWin = true;
581#else
582 bool fWin = false;
583#endif
584#ifdef RT_OS_SOLARIS
585 bool fSolaris = true;
586#else
587 bool fSolaris = false;
588#endif
589#ifdef RT_OS_FREEBSD
590 bool fFreeBSD = true;
591#else
592 bool fFreeBSD = false;
593#endif
594#ifdef RT_OS_DARWIN
595 bool fDarwin = true;
596#else
597 bool fDarwin = false;
598#endif
599#ifdef VBOX_WITH_VBOXSDL
600 bool fVBoxSDL = true;
601#else
602 bool fVBoxSDL = false;
603#endif
604
605 if (fCategory == USAGE_DUMPOPTS)
606 {
607 fDumpOpts = true;
608 fLinux = true;
609 fWin = true;
610 fSolaris = true;
611 fFreeBSD = true;
612 fDarwin = true;
613 fVBoxSDL = true;
614 fCategory = USAGE_ALL;
615 }
616
617 RTStrmPrintf(pStrm,
618 "Usage:\n"
619 "\n");
620
621 if (fCategory == USAGE_ALL)
622 RTStrmPrintf(pStrm,
623 " VBoxManage [<general option>] <command>\n"
624 " \n \n"
625 "General Options:\n \n"
626 " [-v|--version] print version number and exit\n"
627 " [-q|--nologo] suppress the logo\n"
628 " [--settingspw <pw>] provide the settings password\n"
629 " [--settingspwfile <file>] provide a file containing the settings password\n"
630 " [@<response-file>] load arguments from the given response file (bourne style)\n"
631 " \n \n"
632 "Commands:\n \n");
633
634 const char *pcszSep1 = " ";
635 const char *pcszSep2 = " ";
636 if (fCategory != USAGE_ALL)
637 {
638 pcszSep1 = "VBoxManage";
639 pcszSep2 = "";
640 }
641
642#define SEP pcszSep1, pcszSep2
643
644 if (fCategory & USAGE_LIST)
645 RTStrmPrintf(pStrm,
646 "%s list [--long|-l] [--sorted|-s]%s vms|runningvms|ostypes|hostdvds|hostfloppies|\n"
647#if defined(VBOX_WITH_NETFLT)
648 " intnets|bridgedifs|hostonlyifs|natnets|dhcpservers|\n"
649#else
650 " intnets|bridgedifs|natnets|dhcpservers|hostinfo|\n"
651#endif
652 " hostinfo|hostcpuids|hddbackends|hdds|dvds|floppies|\n"
653 " usbhost|usbfilters|systemproperties|extpacks|\n"
654 " groups|webcams|screenshotformats\n"
655 "\n", SEP);
656
657 if (fCategory & USAGE_SHOWVMINFO)
658 RTStrmPrintf(pStrm,
659 "%s showvminfo %s <uuid|vmname> [--details]\n"
660 " [--machinereadable]\n"
661 "%s showvminfo %s <uuid|vmname> --log <idx>\n"
662 "\n", SEP, SEP);
663
664 if (fCategory & USAGE_REGISTERVM)
665 RTStrmPrintf(pStrm,
666 "%s registervm %s <filename>\n"
667 "\n", SEP);
668
669 if (fCategory & USAGE_UNREGISTERVM)
670 RTStrmPrintf(pStrm,
671 "%s unregistervm %s <uuid|vmname> [--delete]\n"
672 "\n", SEP);
673
674 if (fCategory & USAGE_CREATEVM)
675 RTStrmPrintf(pStrm,
676 "%s createvm %s --name <name>\n"
677 " [--groups <group>, ...]\n"
678 " [--ostype <ostype>]\n"
679 " [--register]\n"
680 " [--basefolder <path>]\n"
681 " [--uuid <uuid>]\n"
682 "\n", SEP);
683
684 if (fCategory & USAGE_MODIFYVM)
685 {
686 RTStrmPrintf(pStrm,
687 "%s modifyvm %s <uuid|vmname>\n"
688 " [--name <name>]\n"
689 " [--groups <group>, ...]\n"
690 " [--description <desc>]\n"
691 " [--ostype <ostype>]\n"
692 " [--iconfile <filename>]\n"
693 " [--memory <memorysize in MB>]\n"
694 " [--pagefusion on|off]\n"
695 " [--vram <vramsize in MB>]\n"
696 " [--acpi on|off]\n"
697#ifdef VBOX_WITH_PCI_PASSTHROUGH
698 " [--pciattach 03:04.0]\n"
699 " [--pciattach 03:04.0@02:01.0]\n"
700 " [--pcidetach 03:04.0]\n"
701#endif
702 " [--ioapic on|off]\n"
703 " [--hpet on|off]\n"
704 " [--triplefaultreset on|off]\n"
705 " [--apic on|off]\n"
706 " [--x2apic on|off]\n"
707 " [--paravirtprovider none|default|legacy|minimal|\n"
708 " hyperv|kvm]\n"
709 " [--paravirtdebug <key=value> [,<key=value> ...]]\n"
710 " [--hwvirtex on|off]\n"
711 " [--nestedpaging on|off]\n"
712 " [--largepages on|off]\n"
713 " [--vtxvpid on|off]\n"
714 " [--vtxux on|off]\n"
715 " [--pae on|off]\n"
716 " [--longmode on|off]\n"
717 " [--cpu-profile \"host|Intel 80[86|286|386]\"]\n"
718 " [--cpuid-portability-level <0..3>\n"
719 " [--cpuidset <leaf> <eax> <ebx> <ecx> <edx>]\n"
720 " [--cpuidremove <leaf>]\n"
721 " [--cpuidremoveall]\n"
722 " [--hardwareuuid <uuid>]\n"
723 " [--cpus <number>]\n"
724 " [--cpuhotplug on|off]\n"
725 " [--plugcpu <id>]\n"
726 " [--unplugcpu <id>]\n"
727 " [--cpuexecutioncap <1-100>]\n"
728 " [--rtcuseutc on|off]\n"
729#ifdef VBOX_WITH_VMSVGA
730 " [--graphicscontroller none|vboxvga|vmsvga]\n"
731#else
732 " [--graphicscontroller none|vboxvga]\n"
733#endif
734 " [--monitorcount <number>]\n"
735 " [--accelerate3d on|off]\n"
736#ifdef VBOX_WITH_VIDEOHWACCEL
737 " [--accelerate2dvideo on|off]\n"
738#endif
739 " [--firmware bios|efi|efi32|efi64]\n"
740 " [--chipset ich9|piix3]\n"
741 " [--bioslogofadein on|off]\n"
742 " [--bioslogofadeout on|off]\n"
743 " [--bioslogodisplaytime <msec>]\n"
744 " [--bioslogoimagepath <imagepath>]\n"
745 " [--biosbootmenu disabled|menuonly|messageandmenu]\n"
746 " [--biosapic disabled|apic|x2apic]\n"
747 " [--biossystemtimeoffset <msec>]\n"
748 " [--biospxedebug on|off]\n"
749 " [--boot<1-4> none|floppy|dvd|disk|net>]\n"
750 " [--nic<1-N> none|null|nat|bridged|intnet"
751#if defined(VBOX_WITH_NETFLT)
752 "|hostonly"
753#endif
754 "|\n"
755 " generic|natnetwork"
756 "]\n"
757 " [--nictype<1-N> Am79C970A|Am79C973"
758#ifdef VBOX_WITH_E1000
759 "|\n 82540EM|82543GC|82545EM"
760#endif
761#ifdef VBOX_WITH_VIRTIO
762 "|\n virtio"
763#endif /* VBOX_WITH_VIRTIO */
764 "]\n"
765 " [--cableconnected<1-N> on|off]\n"
766 " [--nictrace<1-N> on|off]\n"
767 " [--nictracefile<1-N> <filename>]\n"
768 " [--nicproperty<1-N> name=[value]]\n"
769 " [--nicspeed<1-N> <kbps>]\n"
770 " [--nicbootprio<1-N> <priority>]\n"
771 " [--nicpromisc<1-N> deny|allow-vms|allow-all]\n"
772 " [--nicbandwidthgroup<1-N> none|<name>]\n"
773 " [--bridgeadapter<1-N> none|<devicename>]\n"
774#if defined(VBOX_WITH_NETFLT)
775 " [--hostonlyadapter<1-N> none|<devicename>]\n"
776#endif
777 " [--intnet<1-N> <network name>]\n"
778 " [--nat-network<1-N> <network name>]\n"
779 " [--nicgenericdrv<1-N> <driver>\n"
780 " [--natnet<1-N> <network>|default]\n"
781 " [--natsettings<1-N> [<mtu>],[<socksnd>],\n"
782 " [<sockrcv>],[<tcpsnd>],\n"
783 " [<tcprcv>]]\n"
784 " [--natpf<1-N> [<rulename>],tcp|udp,[<hostip>],\n"
785 " <hostport>,[<guestip>],<guestport>]\n"
786 " [--natpf<1-N> delete <rulename>]\n"
787 " [--nattftpprefix<1-N> <prefix>]\n"
788 " [--nattftpfile<1-N> <file>]\n"
789 " [--nattftpserver<1-N> <ip>]\n"
790 " [--natbindip<1-N> <ip>\n"
791 " [--natdnspassdomain<1-N> on|off]\n"
792 " [--natdnsproxy<1-N> on|off]\n"
793 " [--natdnshostresolver<1-N> on|off]\n"
794 " [--nataliasmode<1-N> default|[log],[proxyonly],\n"
795 " [sameports]]\n"
796 " [--macaddress<1-N> auto|<mac>]\n"
797 " [--mouse ps2|usb|usbtablet|usbmultitouch]\n"
798 " [--keyboard ps2|usb\n"
799 " [--uart<1-N> off|<I/O base> <IRQ>]\n"
800 " [--uartmode<1-N> disconnected|\n"
801 " server <pipe>|\n"
802 " client <pipe>|\n"
803 " tcpserver <port>|\n"
804 " tcpclient <hostname:port>|\n"
805 " file <file>|\n"
806 " <devicename>]\n"
807#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
808 " [--lpt<1-N> off|<I/O base> <IRQ>]\n"
809 " [--lptmode<1-N> <devicename>]\n"
810#endif
811 " [--guestmemoryballoon <balloonsize in MB>]\n"
812 " [--audio none|null", SEP);
813 if (fWin)
814 {
815#ifdef VBOX_WITH_WINMM
816 RTStrmPrintf(pStrm, "|winmm|dsound");
817#else
818 RTStrmPrintf(pStrm, "|dsound");
819#endif
820 }
821 if (fLinux || fSolaris)
822 {
823 RTStrmPrintf(pStrm, ""
824#ifdef VBOX_WITH_AUDIO_OSS
825 "|oss"
826#endif
827#ifdef VBOX_WITH_AUDIO_ALSA
828 "|alsa"
829#endif
830#ifdef VBOX_WITH_AUDIO_PULSE
831 "|pulse"
832#endif
833 );
834 }
835 if (fFreeBSD)
836 {
837#ifdef VBOX_WITH_AUDIO_OSS
838 /* Get the line break sorted when dumping all option variants. */
839 if (fDumpOpts)
840 {
841 RTStrmPrintf(pStrm, "|\n"
842 " oss");
843 }
844 else
845 RTStrmPrintf(pStrm, "|oss");
846#endif
847#ifdef VBOX_WITH_AUDIO_PULSE
848 RTStrmPrintf(pStrm, "|pulse");
849#endif
850 }
851 if (fDarwin)
852 {
853 RTStrmPrintf(pStrm, "|coreaudio");
854 }
855 RTStrmPrintf(pStrm, "]\n");
856 RTStrmPrintf(pStrm,
857 " [--audioin on|off]\n"
858 " [--audioout on|off]\n"
859 " [--audiocontroller ac97|hda|sb16]\n"
860 " [--audiocodec stac9700|ad1980|stac9221|sb16]\n"
861 " [--clipboard disabled|hosttoguest|guesttohost|\n"
862 " bidirectional]\n"
863 " [--draganddrop disabled|hosttoguest]\n");
864 RTStrmPrintf(pStrm,
865 " [--vrde on|off]\n"
866 " [--vrdeextpack default|<name>\n"
867 " [--vrdeproperty <name=[value]>]\n"
868 " [--vrdeport <hostport>]\n"
869 " [--vrdeaddress <hostip>]\n"
870 " [--vrdeauthtype null|external|guest]\n"
871 " [--vrdeauthlibrary default|<name>\n"
872 " [--vrdemulticon on|off]\n"
873 " [--vrdereusecon on|off]\n"
874 " [--vrdevideochannel on|off]\n"
875 " [--vrdevideochannelquality <percent>]\n");
876 RTStrmPrintf(pStrm,
877 " [--usb on|off]\n"
878 " [--usbehci on|off]\n"
879 " [--usbxhci on|off]\n"
880 " [--usbrename <oldname> <newname>]\n"
881 " [--snapshotfolder default|<path>]\n"
882 " [--teleporter on|off]\n"
883 " [--teleporterport <port>]\n"
884 " [--teleporteraddress <address|empty>\n"
885 " [--teleporterpassword <password>]\n"
886 " [--teleporterpasswordfile <file>|stdin]\n"
887 " [--tracing-enabled on|off]\n"
888 " [--tracing-config <config-string>]\n"
889 " [--tracing-allow-vm-access on|off]\n"
890#if 0
891 " [--iocache on|off]\n"
892 " [--iocachesize <I/O cache size in MB>]\n"
893#endif
894#if 0
895 " [--faulttolerance master|standby]\n"
896 " [--faulttoleranceaddress <name>]\n"
897 " [--faulttoleranceport <port>]\n"
898 " [--faulttolerancesyncinterval <msec>]\n"
899 " [--faulttolerancepassword <password>]\n"
900#endif
901#ifdef VBOX_WITH_USB_CARDREADER
902 " [--usbcardreader on|off]\n"
903#endif
904 " [--autostart-enabled on|off]\n"
905 " [--autostart-delay <seconds>]\n"
906#if 0
907 " [--autostop-type disabled|savestate|poweroff|\n"
908 " acpishutdown]\n"
909#endif
910#ifdef VBOX_WITH_VIDEOREC
911 " [--videocap on|off]\n"
912 " [--videocapscreens all|<screen ID> [<screen ID> ...]]\n"
913 " [--videocapfile <filename>]\n"
914 " [--videocapres <width> <height>]\n"
915 " [--videocaprate <rate>]\n"
916 " [--videocapfps <fps>]\n"
917 " [--videocapmaxtime <ms>]\n"
918 " [--videocapmaxsize <MB>]\n"
919 " [--videocapopts <key=value> [,<key=value> ...]]\n"
920#endif
921 " [--defaultfrontend default|<name>]\n"
922 "\n");
923 }
924
925 if (fCategory & USAGE_CLONEVM)
926 RTStrmPrintf(pStrm,
927 "%s clonevm %s <uuid|vmname>\n"
928 " [--snapshot <uuid>|<name>]\n"
929 " [--mode machine|machineandchildren|all]\n"
930 " [--options link|keepallmacs|keepnatmacs|\n"
931 " keepdisknames]\n"
932 " [--name <name>]\n"
933 " [--groups <group>, ...]\n"
934 " [--basefolder <basefolder>]\n"
935 " [--uuid <uuid>]\n"
936 " [--register]\n"
937 "\n", SEP);
938
939 if (fCategory & USAGE_IMPORTAPPLIANCE)
940 RTStrmPrintf(pStrm,
941 "%s import %s <ovfname/ovaname>\n"
942 " [--dry-run|-n]\n"
943 " [--options keepallmacs|keepnatmacs|importtovdi]\n"
944 " [more options]\n"
945 " (run with -n to have options displayed\n"
946 " for a particular OVF)\n\n", SEP);
947
948 if (fCategory & USAGE_EXPORTAPPLIANCE)
949 RTStrmPrintf(pStrm,
950 "%s export %s <machines> --output|-o <name>.<ovf/ova/tar.gz>\n"
951 " [--legacy09|--ovf09|--ovf10|--ovf20|--opc10]\n"
952 " [--manifest]\n"
953 " [--iso]\n"
954 " [--options manifest|iso|nomacs|nomacsbutnat]\n"
955 " [--vsys <number of virtual system>]\n"
956 " [--product <product name>]\n"
957 " [--producturl <product url>]\n"
958 " [--vendor <vendor name>]\n"
959 " [--vendorurl <vendor url>]\n"
960 " [--version <version info>]\n"
961 " [--description <description info>]\n"
962 " [--eula <license text>]\n"
963 " [--eulafile <filename>]\n"
964 "\n", SEP);
965
966 if (fCategory & USAGE_STARTVM)
967 {
968 RTStrmPrintf(pStrm,
969 "%s startvm %s <uuid|vmname>...\n"
970 " [--type gui", SEP);
971 if (fVBoxSDL)
972 RTStrmPrintf(pStrm, "|sdl");
973 RTStrmPrintf(pStrm, "|headless|separate]\n");
974 RTStrmPrintf(pStrm,
975 " [-E|--putenv <NAME>[=<VALUE>]]\n"
976 "\n");
977 }
978
979 if (fCategory & USAGE_CONTROLVM)
980 {
981 RTStrmPrintf(pStrm,
982 "%s controlvm %s <uuid|vmname>\n"
983 " pause|resume|reset|poweroff|savestate|\n"
984 " acpipowerbutton|acpisleepbutton|\n"
985 " keyboardputscancode <hex> [<hex> ...]|\n"
986 " keyboardputstring <string1> [<string2> ...]|\n"
987 " keyboardputfile <filename>|\n"
988 " setlinkstate<1-N> on|off |\n"
989#if defined(VBOX_WITH_NETFLT)
990 " nic<1-N> null|nat|bridged|intnet|hostonly|generic|\n"
991 " natnetwork [<devicename>] |\n"
992#else /* !VBOX_WITH_NETFLT */
993 " nic<1-N> null|nat|bridged|intnet|generic|natnetwork\n"
994 " [<devicename>] |\n"
995#endif /* !VBOX_WITH_NETFLT */
996 " nictrace<1-N> on|off |\n"
997 " nictracefile<1-N> <filename> |\n"
998 " nicproperty<1-N> name=[value] |\n"
999 " nicpromisc<1-N> deny|allow-vms|allow-all |\n"
1000 " natpf<1-N> [<rulename>],tcp|udp,[<hostip>],\n"
1001 " <hostport>,[<guestip>],<guestport> |\n"
1002 " natpf<1-N> delete <rulename> |\n"
1003 " guestmemoryballoon <balloonsize in MB> |\n"
1004 " usbattach <uuid>|<address>\n"
1005 " [--capturefile <filename>] |\n"
1006 " usbdetach <uuid>|<address> |\n"
1007 " audioin on|off |\n"
1008 " audioout on|off |\n"
1009 " clipboard disabled|hosttoguest|guesttohost|\n"
1010 " bidirectional |\n"
1011 " draganddrop disabled|hosttoguest |\n"
1012 " vrde on|off |\n"
1013 " vrdeport <port> |\n"
1014 " vrdeproperty <name=[value]> |\n"
1015 " vrdevideochannelquality <percent> |\n"
1016 " setvideomodehint <xres> <yres> <bpp>\n"
1017 " [[<display>] [<enabled:yes|no> |\n"
1018 " [<xorigin> <yorigin>]]] |\n"
1019 " screenshotpng <file> [display] |\n"
1020 " videocap on|off |\n"
1021 " videocapscreens all|none|<screen>,[<screen>...] |\n"
1022 " videocapfile <file>\n"
1023 " videocapres <width>x<height>\n"
1024 " videocaprate <rate>\n"
1025 " videocapfps <fps>\n"
1026 " videocapmaxtime <ms>\n"
1027 " videocapmaxsize <MB>\n"
1028 " setcredentials <username>\n"
1029 " --passwordfile <file> | <password>\n"
1030 " <domain>\n"
1031 " [--allowlocallogon <yes|no>] |\n"
1032 " teleport --host <name> --port <port>\n"
1033 " [--maxdowntime <msec>]\n"
1034 " [--passwordfile <file> |\n"
1035 " --password <password>] |\n"
1036 " plugcpu <id> |\n"
1037 " unplugcpu <id> |\n"
1038 " cpuexecutioncap <1-100>\n"
1039 " webcam <attach [path [settings]]> | <detach [path]> | <list>\n"
1040 " addencpassword <id>\n"
1041 " <password file>|-\n"
1042 " [--removeonsuspend <yes|no>]\n"
1043 " removeencpassword <id>\n"
1044 " removeallencpasswords\n"
1045 "\n", SEP);
1046 }
1047
1048 if (fCategory & USAGE_DISCARDSTATE)
1049 RTStrmPrintf(pStrm,
1050 "%s discardstate %s <uuid|vmname>\n"
1051 "\n", SEP);
1052
1053 if (fCategory & USAGE_ADOPTSTATE)
1054 RTStrmPrintf(pStrm,
1055 "%s adoptstate %s <uuid|vmname> <state_file>\n"
1056 "\n", SEP);
1057
1058 if (fCategory & USAGE_SNAPSHOT)
1059 RTStrmPrintf(pStrm,
1060 "%s snapshot %s <uuid|vmname>\n"
1061 " take <name> [--description <desc>] [--live]\n"
1062 " [--uniquename Number,Timestamp,Space,Force] |\n"
1063 " delete <uuid|snapname> |\n"
1064 " restore <uuid|snapname> |\n"
1065 " restorecurrent |\n"
1066 " edit <uuid|snapname>|--current\n"
1067 " [--name <name>]\n"
1068 " [--description <desc>] |\n"
1069 " list [--details|--machinereadable]\n"
1070 " showvminfo <uuid|snapname>\n"
1071 "\n", SEP);
1072
1073 if (fCategory & USAGE_CLOSEMEDIUM)
1074 RTStrmPrintf(pStrm,
1075 "%s closemedium %s [disk|dvd|floppy] <uuid|filename>\n"
1076 " [--delete]\n"
1077 "\n", SEP);
1078
1079 if (fCategory & USAGE_STORAGEATTACH)
1080 RTStrmPrintf(pStrm,
1081 "%s storageattach %s <uuid|vmname>\n"
1082 " --storagectl <name>\n"
1083 " [--port <number>]\n"
1084 " [--device <number>]\n"
1085 " [--type dvddrive|hdd|fdd]\n"
1086 " [--medium none|emptydrive|additions|\n"
1087 " <uuid|filename>|host:<drive>|iscsi]\n"
1088 " [--mtype normal|writethrough|immutable|shareable|\n"
1089 " readonly|multiattach]\n"
1090 " [--comment <text>]\n"
1091 " [--setuuid <uuid>]\n"
1092 " [--setparentuuid <uuid>]\n"
1093 " [--passthrough on|off]\n"
1094 " [--tempeject on|off]\n"
1095 " [--nonrotational on|off]\n"
1096 " [--discard on|off]\n"
1097 " [--hotpluggable on|off]\n"
1098 " [--bandwidthgroup <name>]\n"
1099 " [--forceunmount]\n"
1100 " [--server <name>|<ip>]\n"
1101 " [--target <target>]\n"
1102 " [--tport <port>]\n"
1103 " [--lun <lun>]\n"
1104 " [--encodedlun <lun>]\n"
1105 " [--username <username>]\n"
1106 " [--password <password>]\n"
1107 " [--initiator <initiator>]\n"
1108 " [--intnet]\n"
1109 "\n", SEP);
1110
1111 if (fCategory & USAGE_STORAGECONTROLLER)
1112 RTStrmPrintf(pStrm,
1113 "%s storagectl %s <uuid|vmname>\n"
1114 " --name <name>\n"
1115 " [--add ide|sata|scsi|floppy|sas|usb|pcie]\n"
1116 " [--controller LSILogic|LSILogicSAS|BusLogic|\n"
1117 " IntelAHCI|PIIX3|PIIX4|ICH6|I82078|\n"
1118 " [ USB|NVMe]\n"
1119 " [--portcount <1-n>]\n"
1120 " [--hostiocache on|off]\n"
1121 " [--bootable on|off]\n"
1122 " [--rename <name>]\n"
1123 " [--remove]\n"
1124 "\n", SEP);
1125
1126 if (fCategory & USAGE_BANDWIDTHCONTROL)
1127 RTStrmPrintf(pStrm,
1128 "%s bandwidthctl %s <uuid|vmname>\n"
1129 " add <name> --type disk|network\n"
1130 " --limit <megabytes per second>[k|m|g|K|M|G] |\n"
1131 " set <name>\n"
1132 " --limit <megabytes per second>[k|m|g|K|M|G] |\n"
1133 " remove <name> |\n"
1134 " list [--machinereadable]\n"
1135 " (limit units: k=kilobit, m=megabit, g=gigabit,\n"
1136 " K=kilobyte, M=megabyte, G=gigabyte)\n"
1137 "\n", SEP);
1138
1139 if (fCategory & USAGE_SHOWMEDIUMINFO)
1140 RTStrmPrintf(pStrm,
1141 "%s showmediuminfo %s [disk|dvd|floppy] <uuid|filename>\n"
1142 "\n", SEP);
1143
1144 if (fCategory & USAGE_CREATEMEDIUM)
1145 RTStrmPrintf(pStrm,
1146 "%s createmedium %s [disk|dvd|floppy] --filename <filename>\n"
1147 " [--size <megabytes>|--sizebyte <bytes>]\n"
1148 " [--diffparent <uuid>|<filename>\n"
1149 " [--format VDI|VMDK|VHD] (default: VDI)\n"
1150 " [--variant Standard,Fixed,Split2G,Stream,ESX]\n"
1151 "\n", SEP);
1152
1153 if (fCategory & USAGE_MODIFYMEDIUM)
1154 RTStrmPrintf(pStrm,
1155 "%s modifymedium %s [disk|dvd|floppy] <uuid|filename>\n"
1156 " [--type normal|writethrough|immutable|shareable|\n"
1157 " readonly|multiattach]\n"
1158 " [--autoreset on|off]\n"
1159 " [--property <name=[value]>]\n"
1160 " [--compact]\n"
1161 " [--resize <megabytes>|--resizebyte <bytes>]\n"
1162 " [--move <path]\n"
1163 " [--description <description string>]"
1164 "\n", SEP);
1165
1166 if (fCategory & USAGE_CLONEMEDIUM)
1167 RTStrmPrintf(pStrm,
1168 "%s clonemedium %s [disk|dvd|floppy] <uuid|inputfile> <uuid|outputfile>\n"
1169 " [--format VDI|VMDK|VHD|RAW|<other>]\n"
1170 " [--variant Standard,Fixed,Split2G,Stream,ESX]\n"
1171 " [--existing]\n"
1172 "\n", SEP);
1173
1174 if (fCategory & USAGE_MEDIUMPROPERTY)
1175 RTStrmPrintf(pStrm,
1176 "%s mediumproperty %s [disk|dvd|floppy] set <uuid|filename>\n"
1177 " <property> <value>\n"
1178 "\n"
1179 " [disk|dvd|floppy] get <uuid|filename>\n"
1180 " <property>\n"
1181 "\n"
1182 " [disk|dvd|floppy] delete <uuid|filename>\n"
1183 " <property>\n"
1184 "\n", SEP);
1185
1186 if (fCategory & USAGE_ENCRYPTMEDIUM)
1187 RTStrmPrintf(pStrm,
1188 "%s encryptmedium %s <uuid|filename>\n"
1189 " [--newpassword <file>|-]\n"
1190 " [--oldpassword <file>|-]\n"
1191 " [--cipher <cipher identifier>]\n"
1192 " [--newpasswordid <password identifier>]\n"
1193 "\n", SEP);
1194
1195 if (fCategory & USAGE_MEDIUMENCCHKPWD)
1196 RTStrmPrintf(pStrm,
1197 "%s checkmediumpwd %s <uuid|filename>\n"
1198 " <pwd file>|-\n"
1199 "\n", SEP);
1200
1201 if (fCategory & USAGE_CONVERTFROMRAW)
1202 RTStrmPrintf(pStrm,
1203 "%s convertfromraw %s <filename> <outputfile>\n"
1204 " [--format VDI|VMDK|VHD]\n"
1205 " [--variant Standard,Fixed,Split2G,Stream,ESX]\n"
1206 " [--uuid <uuid>]\n"
1207 "%s convertfromraw %s stdin <outputfile> <bytes>\n"
1208 " [--format VDI|VMDK|VHD]\n"
1209 " [--variant Standard,Fixed,Split2G,Stream,ESX]\n"
1210 " [--uuid <uuid>]\n"
1211 "\n", SEP, SEP);
1212
1213 if (fCategory & USAGE_GETEXTRADATA)
1214 RTStrmPrintf(pStrm,
1215 "%s getextradata %s global|<uuid|vmname>\n"
1216 " <key>|enumerate\n"
1217 "\n", SEP);
1218
1219 if (fCategory & USAGE_SETEXTRADATA)
1220 RTStrmPrintf(pStrm,
1221 "%s setextradata %s global|<uuid|vmname>\n"
1222 " <key>\n"
1223 " [<value>] (no value deletes key)\n"
1224 "\n", SEP);
1225
1226 if (fCategory & USAGE_SETPROPERTY)
1227 RTStrmPrintf(pStrm,
1228 "%s setproperty %s machinefolder default|<folder> |\n"
1229 " hwvirtexclusive on|off |\n"
1230 " vrdeauthlibrary default|<library> |\n"
1231 " websrvauthlibrary default|null|<library> |\n"
1232 " vrdeextpack null|<library> |\n"
1233 " autostartdbpath null|<folder> |\n"
1234 " loghistorycount <value>\n"
1235 " defaultfrontend default|<name>\n"
1236 " logginglevel <log setting>\n"
1237 "\n", SEP);
1238
1239 if (fCategory & USAGE_USBFILTER_ADD)
1240 RTStrmPrintf(pStrm,
1241 "%s usbfilter %s add <index,0-N>\n"
1242 " --target <uuid|vmname>|global\n"
1243 " --name <string>\n"
1244 " --action ignore|hold (global filters only)\n"
1245 " [--active yes|no] (yes)\n"
1246 " [--vendorid <XXXX>] (null)\n"
1247 " [--productid <XXXX>] (null)\n"
1248 " [--revision <IIFF>] (null)\n"
1249 " [--manufacturer <string>] (null)\n"
1250 " [--product <string>] (null)\n"
1251 " [--remote yes|no] (null, VM filters only)\n"
1252 " [--serialnumber <string>] (null)\n"
1253 " [--maskedinterfaces <XXXXXXXX>]\n"
1254 "\n", SEP);
1255
1256 if (fCategory & USAGE_USBFILTER_MODIFY)
1257 RTStrmPrintf(pStrm,
1258 "%s usbfilter %s modify <index,0-N>\n"
1259 " --target <uuid|vmname>|global\n"
1260 " [--name <string>]\n"
1261 " [--action ignore|hold] (global filters only)\n"
1262 " [--active yes|no]\n"
1263 " [--vendorid <XXXX>|\"\"]\n"
1264 " [--productid <XXXX>|\"\"]\n"
1265 " [--revision <IIFF>|\"\"]\n"
1266 " [--manufacturer <string>|\"\"]\n"
1267 " [--product <string>|\"\"]\n"
1268 " [--remote yes|no] (null, VM filters only)\n"
1269 " [--serialnumber <string>|\"\"]\n"
1270 " [--maskedinterfaces <XXXXXXXX>]\n"
1271 "\n", SEP);
1272
1273 if (fCategory & USAGE_USBFILTER_REMOVE)
1274 RTStrmPrintf(pStrm,
1275 "%s usbfilter %s remove <index,0-N>\n"
1276 " --target <uuid|vmname>|global\n"
1277 "\n", SEP);
1278
1279 if (fCategory & USAGE_SHAREDFOLDER_ADD)
1280 RTStrmPrintf(pStrm,
1281 "%s sharedfolder %s add <uuid|vmname>\n"
1282 " --name <name> --hostpath <hostpath>\n"
1283 " [--transient] [--readonly] [--automount]\n"
1284 "\n", SEP);
1285
1286 if (fCategory & USAGE_SHAREDFOLDER_REMOVE)
1287 RTStrmPrintf(pStrm,
1288 "%s sharedfolder %s remove <uuid|vmname>\n"
1289 " --name <name> [--transient]\n"
1290 "\n", SEP);
1291
1292#ifdef VBOX_WITH_GUEST_PROPS
1293 if (fCategory & USAGE_GUESTPROPERTY)
1294 usageGuestProperty(pStrm, SEP);
1295#endif /* VBOX_WITH_GUEST_PROPS defined */
1296
1297#ifdef VBOX_WITH_GUEST_CONTROL
1298 if (fCategory & USAGE_GUESTCONTROL)
1299 usageGuestControl(pStrm, SEP, fSubCategory);
1300#endif /* VBOX_WITH_GUEST_CONTROL defined */
1301
1302 if (fCategory & USAGE_METRICS)
1303 RTStrmPrintf(pStrm,
1304 "%s metrics %s list [*|host|<vmname> [<metric_list>]]\n"
1305 " (comma-separated)\n\n"
1306 "%s metrics %s setup\n"
1307 " [--period <seconds>] (default: 1)\n"
1308 " [--samples <count>] (default: 1)\n"
1309 " [--list]\n"
1310 " [*|host|<vmname> [<metric_list>]]\n\n"
1311 "%s metrics %s query [*|host|<vmname> [<metric_list>]]\n\n"
1312 "%s metrics %s enable\n"
1313 " [--list]\n"
1314 " [*|host|<vmname> [<metric_list>]]\n\n"
1315 "%s metrics %s disable\n"
1316 " [--list]\n"
1317 " [*|host|<vmname> [<metric_list>]]\n\n"
1318 "%s metrics %s collect\n"
1319 " [--period <seconds>] (default: 1)\n"
1320 " [--samples <count>] (default: 1)\n"
1321 " [--list]\n"
1322 " [--detach]\n"
1323 " [*|host|<vmname> [<metric_list>]]\n"
1324 "\n", SEP, SEP, SEP, SEP, SEP, SEP);
1325
1326#if defined(VBOX_WITH_NAT_SERVICE)
1327 if (fCategory & USAGE_NATNETWORK)
1328 {
1329 RTStrmPrintf(pStrm,
1330 "%s natnetwork %s add --netname <name>\n"
1331 " --network <network>\n"
1332 " [--enable|--disable]\n"
1333 " [--dhcp on|off]\n"
1334 " [--port-forward-4 <rule>]\n"
1335 " [--loopback-4 <rule>]\n"
1336 " [--ipv6 on|off]\n"
1337 " [--port-forward-6 <rule>]\n"
1338 " [--loopback-6 <rule>]\n\n"
1339 "%s natnetwork %s remove --netname <name>\n\n"
1340 "%s natnetwork %s modify --netname <name>\n"
1341 " [--network <network>]\n"
1342 " [--enable|--disable]\n"
1343 " [--dhcp on|off]\n"
1344 " [--port-forward-4 <rule>]\n"
1345 " [--loopback-4 <rule>]\n"
1346 " [--ipv6 on|off]\n"
1347 " [--port-forward-6 <rule>]\n"
1348 " [--loopback-6 <rule>]\n\n"
1349 "%s natnetwork %s start --netname <name>\n\n"
1350 "%s natnetwork %s stop --netname <name>\n\n"
1351 "%s natnetwork %s list [<pattern>]\n"
1352 "\n", SEP, SEP, SEP, SEP, SEP, SEP);
1353
1354
1355 }
1356#endif
1357
1358#if defined(VBOX_WITH_NETFLT)
1359 if (fCategory & USAGE_HOSTONLYIFS)
1360 {
1361 RTStrmPrintf(pStrm,
1362 "%s hostonlyif %s ipconfig <name>\n"
1363 " [--dhcp |\n"
1364 " --ip<ipv4> [--netmask<ipv4> (def: 255.255.255.0)] |\n"
1365 " --ipv6<ipv6> [--netmasklengthv6<length> (def: 64)]]\n"
1366# if !defined(RT_OS_SOLARIS) || defined(VBOX_ONLY_DOCS)
1367 " create |\n"
1368 " remove <name>\n"
1369# endif
1370 "\n", SEP);
1371 }
1372#endif
1373
1374 if (fCategory & USAGE_DHCPSERVER)
1375 {
1376 RTStrmPrintf(pStrm,
1377 "%s dhcpserver %s add|modify --netname <network_name> |\n"
1378#if defined(VBOX_WITH_NETFLT)
1379 " --ifname <hostonly_if_name>\n"
1380#endif
1381 " [--ip <ip_address>\n"
1382 " --netmask <network_mask>\n"
1383 " --lowerip <lower_ip>\n"
1384 " --upperip <upper_ip>]\n"
1385 " [--enable | --disable]\n\n"
1386 "%s dhcpserver %s remove --netname <network_name> |\n"
1387#if defined(VBOX_WITH_NETFLT)
1388 " --ifname <hostonly_if_name>\n"
1389#endif
1390 "\n", SEP, SEP);
1391 }
1392
1393 if (fCategory & USAGE_USBDEVSOURCE)
1394 {
1395 RTStrmPrintf(pStrm,
1396 "%s usbdevsource %s add <source name>\n"
1397 " --backend <backend>\n"
1398 " --address <address>\n"
1399 "%s usbdevsource %s remove <source name>\n"
1400 "\n", SEP, SEP);
1401 }
1402
1403#ifndef VBOX_ONLY_DOCS /* Converted to man page, not needed. */
1404 if (fCategory == USAGE_ALL)
1405 {
1406 uint32_t cPendingBlankLines = 0;
1407 for (uint32_t i = 0; i < g_cHelpEntries; i++)
1408 {
1409 PCREFENTRY pHelp = g_apHelpEntries[i];
1410 while (cPendingBlankLines-- > 0)
1411 RTStrmPutCh(pStrm, '\n');
1412 RTStrmPrintf(pStrm, " %c%s:\n", RT_C_TO_UPPER(pHelp->pszBrief[0]), pHelp->pszBrief + 1);
1413 cPendingBlankLines = printStringTable(pStrm, &pHelp->Synopsis, REFENTRYSTR_SCOPE_GLOBAL, 0);
1414 cPendingBlankLines = RT_MAX(cPendingBlankLines, 1);
1415 }
1416 }
1417#endif
1418}
1419
1420/**
1421 * Print a usage synopsis and the syntax error message.
1422 * @returns RTEXITCODE_SYNTAX.
1423 */
1424RTEXITCODE errorSyntax(USAGECATEGORY fCategory, const char *pszFormat, ...)
1425{
1426 va_list args;
1427 showLogo(g_pStdErr); // show logo even if suppressed
1428#ifndef VBOX_ONLY_DOCS
1429 if (g_fInternalMode)
1430 printUsageInternal(fCategory, g_pStdErr);
1431 else
1432 printUsage(fCategory, ~0U, g_pStdErr);
1433#else
1434 RT_NOREF_PV(fCategory);
1435#endif
1436 va_start(args, pszFormat);
1437 RTStrmPrintf(g_pStdErr, "\nSyntax error: %N\n", pszFormat, &args);
1438 va_end(args);
1439 return RTEXITCODE_SYNTAX;
1440}
1441
1442/**
1443 * Print a usage synopsis and the syntax error message.
1444 * @returns RTEXITCODE_SYNTAX.
1445 */
1446RTEXITCODE errorSyntaxEx(USAGECATEGORY fCategory, uint32_t fSubCategory, const char *pszFormat, ...)
1447{
1448 va_list args;
1449 showLogo(g_pStdErr); // show logo even if suppressed
1450#ifndef VBOX_ONLY_DOCS
1451 if (g_fInternalMode)
1452 printUsageInternal(fCategory, g_pStdErr);
1453 else
1454 printUsage(fCategory, fSubCategory, g_pStdErr);
1455#else
1456 RT_NOREF2(fCategory, fSubCategory);
1457#endif
1458 va_start(args, pszFormat);
1459 RTStrmPrintf(g_pStdErr, "\nSyntax error: %N\n", pszFormat, &args);
1460 va_end(args);
1461 return RTEXITCODE_SYNTAX;
1462}
1463
1464/**
1465 * errorSyntax for RTGetOpt users.
1466 *
1467 * @returns RTEXITCODE_SYNTAX.
1468 *
1469 * @param fCategory The usage category of the command.
1470 * @param fSubCategory The usage sub-category of the command.
1471 * @param rc The RTGetOpt return code.
1472 * @param pValueUnion The value union.
1473 */
1474RTEXITCODE errorGetOptEx(USAGECATEGORY fCategory, uint32_t fSubCategory, int rc, union RTGETOPTUNION const *pValueUnion)
1475{
1476 /*
1477 * Check if it is an unhandled standard option.
1478 */
1479#ifndef VBOX_ONLY_DOCS
1480 if (rc == 'V')
1481 {
1482 RTPrintf("%sr%d\n", VBOX_VERSION_STRING, RTBldCfgRevision());
1483 return RTEXITCODE_SUCCESS;
1484 }
1485#endif
1486
1487 if (rc == 'h')
1488 {
1489 showLogo(g_pStdErr);
1490#ifndef VBOX_ONLY_DOCS
1491 if (g_fInternalMode)
1492 printUsageInternal(fCategory, g_pStdOut);
1493 else
1494 printUsage(fCategory, fSubCategory, g_pStdOut);
1495#endif
1496 return RTEXITCODE_SUCCESS;
1497 }
1498
1499 /*
1500 * General failure.
1501 */
1502 showLogo(g_pStdErr); // show logo even if suppressed
1503#ifndef VBOX_ONLY_DOCS
1504 if (g_fInternalMode)
1505 printUsageInternal(fCategory, g_pStdErr);
1506 else
1507 printUsage(fCategory, fSubCategory, g_pStdErr);
1508#else
1509 RT_NOREF2(fCategory, fSubCategory);
1510#endif
1511
1512 if (rc == VINF_GETOPT_NOT_OPTION)
1513 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid parameter '%s'", pValueUnion->psz);
1514 if (rc > 0)
1515 {
1516 if (RT_C_IS_PRINT(rc))
1517 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid option -%c", rc);
1518 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid option case %i", rc);
1519 }
1520 if (rc == VERR_GETOPT_UNKNOWN_OPTION)
1521 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Unknown option: %s", pValueUnion->psz);
1522 if (rc == VERR_GETOPT_INVALID_ARGUMENT_FORMAT)
1523 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "Invalid argument format: %s", pValueUnion->psz);
1524 if (pValueUnion->pDef)
1525 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "%s: %Rrs", pValueUnion->pDef->pszLong, rc);
1526 return RTMsgErrorExit(RTEXITCODE_SYNTAX, "%Rrs", rc);
1527}
1528
1529/**
1530 * errorSyntax for RTGetOpt users.
1531 *
1532 * @returns RTEXITCODE_SYNTAX.
1533 *
1534 * @param fUsageCategory The usage category of the command.
1535 * @param rc The RTGetOpt return code.
1536 * @param pValueUnion The value union.
1537 */
1538RTEXITCODE errorGetOpt(USAGECATEGORY fCategory, int rc, union RTGETOPTUNION const *pValueUnion)
1539{
1540 return errorGetOptEx(fCategory, ~0U, rc, pValueUnion);
1541}
1542
1543/**
1544 * Print an error message without the syntax stuff.
1545 *
1546 * @returns RTEXITCODE_SYNTAX.
1547 */
1548RTEXITCODE errorArgument(const char *pszFormat, ...)
1549{
1550 va_list args;
1551 va_start(args, pszFormat);
1552 RTMsgErrorV(pszFormat, args);
1553 va_end(args);
1554 return RTEXITCODE_SYNTAX;
1555}
1556
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette