VirtualBox

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

Last change on this file since 94018 was 93708, checked in by vboxsync, 3 years ago

include/iprt/message.h: Max out the available bits for the scope, we need a lot for the VBoxManage controlvm docs.

docs, VBoxManage: Integrate refman (and fix some content) for VBoxManage startvm and VBoxManage controlvm. Needs about 60 scopes (do RT_BIT_64 is a must have), and for protection against exceeding the limit there are now checks (as AssertCompile).

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

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