VirtualBox

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

Last change on this file since 18131 was 18108, checked in by vboxsync, 16 years ago

VBoxManage: clean up various places which use RTGetOpt, fix error handling to deal with changed RTGetOpt semantics, make the double-dash options the recommended ones, updated help

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.1 KB
Line 
1/* $Id: VBoxManageHelp.cpp 18108 2009-03-20 11:04:44Z vboxsync $ */
2/** @file
3 * VBoxManage - help and other message output.
4 */
5
6/*
7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#include <iprt/stream.h>
23#include <iprt/getopt.h>
24
25#include "VBoxManage.h"
26
27void printUsage(USAGECATEGORY u64Cmd)
28{
29#ifdef RT_OS_LINUX
30 bool fLinux = true;
31#else
32 bool fLinux = false;
33#endif
34#ifdef RT_OS_WINDOWS
35 bool fWin = true;
36#else
37 bool fWin = false;
38#endif
39#ifdef RT_OS_SOLARIS
40 bool fSolaris = true;
41#else
42 bool fSolaris = false;
43#endif
44#ifdef RT_OS_DARWIN
45 bool fDarwin = true;
46#else
47 bool fDarwin = false;
48#endif
49#ifdef VBOX_WITH_VRDP
50 bool fVRDP = true;
51#else
52 bool fVRDP = false;
53#endif
54
55 if (u64Cmd == USAGE_DUMPOPTS)
56 {
57 fLinux = true;
58 fWin = true;
59 fSolaris = true;
60 fDarwin = true;
61 fVRDP = true;
62 u64Cmd = USAGE_ALL;
63 }
64
65 RTPrintf("Usage:\n"
66 "\n");
67
68 if (u64Cmd == USAGE_ALL)
69 {
70 RTPrintf("VBoxManage [-v|-version] print version number and exit\n"
71 "VBoxManage -nologo ... suppress the logo\n"
72 "\n");
73 }
74
75 if (u64Cmd & USAGE_LIST)
76 {
77 RTPrintf("VBoxManage list [--long|-l] vms|runningvms|ostypes|hostdvds|hostfloppies|\n"
78#if defined(VBOX_WITH_NETFLT)
79 " bridgedifs|hostonlyifs|dhcpservers|hostinfo|\n"
80#else
81 " bridgedifs|hostinfo|dhcpservers|\n"
82#endif
83 " hddbackends|hdds|dvds|floppies|\n"
84 " usbhost|usbfilters|systemproperties\n"
85 "\n");
86 }
87
88 if (u64Cmd & USAGE_SHOWVMINFO)
89 {
90 RTPrintf("VBoxManage showvminfo <uuid>|<name> [-details] [-statistics]\n"
91 " [-machinereadable]\n"
92 "\n");
93 }
94
95 if (u64Cmd & USAGE_REGISTERVM)
96 {
97 RTPrintf("VBoxManage registervm <filename>\n"
98 "\n");
99 }
100
101 if (u64Cmd & USAGE_UNREGISTERVM)
102 {
103 RTPrintf("VBoxManage unregistervm <uuid>|<name> [-delete]\n"
104 "\n");
105 }
106
107 if (u64Cmd & USAGE_CREATEVM)
108 {
109 RTPrintf("VBoxManage createvm -name <name>\n"
110 " [-ostype <ostype>]\n"
111 " [-register]\n"
112 " [-basefolder <path> | -settingsfile <path>]\n"
113 " [-uuid <uuid>]\n"
114 "\n");
115 }
116
117 if (u64Cmd & USAGE_MODIFYVM)
118 {
119 RTPrintf("VBoxManage modifyvm <uuid|name>\n"
120 " [-name <name>]\n"
121 " [-ostype <ostype>]\n"
122 " [-memory <memorysize in MB>]\n"
123 " [-vram <vramsize in MB>]\n"
124 " [-acpi on|off]\n"
125 " [-ioapic on|off]\n"
126 " [-pae on|off]\n"
127 " [-hwvirtex on|off|default]\n"
128 " [-nestedpaging on|off]\n"
129 " [-vtxvpid on|off]\n"
130 " [-monitorcount <number>]\n"
131 " [-accelerate3d <on|off>]\n"
132 " [-bioslogofadein on|off]\n"
133 " [-bioslogofadeout on|off]\n"
134 " [-bioslogodisplaytime <msec>]\n"
135 " [-bioslogoimagepath <imagepath>]\n"
136 " [-biosbootmenu disabled|menuonly|messageandmenu]\n"
137 " [-biossystemtimeoffset <msec>]\n"
138 " [-biospxedebug on|off]\n"
139 " [-boot<1-4> none|floppy|dvd|disk|net>]\n"
140 " [-hd<a|b|d> none|<uuid>|<filename>]\n"
141 " [-idecontroller PIIX3|PIIX4]\n"
142#ifdef VBOX_WITH_AHCI
143 " [-sata on|off]\n"
144 " [-sataportcount <1-30>]\n"
145 " [-sataport<1-30> none|<uuid>|<filename>]\n"
146 " [-sataideemulation<1-4> <1-30>]\n"
147#endif
148#ifdef VBOX_WITH_SCSI
149 " [-scsi on|off]\n"
150 " [-scsiport<1-16> none|<uuid>|<filename>]\n"
151 " [-scsitype LsiLogic|BusLogic]\n"
152#endif
153 " [-dvd none|<uuid>|<filename>|host:<drive>]\n"
154 " [-dvdpassthrough on|off]\n"
155 " [-floppy disabled|empty|<uuid>|\n"
156 " <filename>|host:<drive>]\n"
157#if defined(VBOX_WITH_NETFLT)
158 " [-nic<1-N> none|null|nat|bridged|intnet|hostonly]\n"
159#else /* !RT_OS_LINUX && !RT_OS_DARWIN */
160 " [-nic<1-N> none|null|nat|bridged|intnet]\n"
161#endif /* !RT_OS_LINUX && !RT_OS_DARWIN */
162 " [-nictype<1-N> Am79C970A|Am79C973"
163#ifdef VBOX_WITH_E1000
164 "|82540EM|82543GC"
165#endif
166 "]\n"
167 " [-cableconnected<1-N> on|off]\n"
168 " [-nictrace<1-N> on|off]\n"
169 " [-nictracefile<1-N> <filename>]\n"
170 " [-nicspeed<1-N> <kbps>]\n"
171 " [-bridgeadapter<1-N> none|<devicename>]\n"
172#if defined(VBOX_WITH_NETFLT)
173 " [-hostonlyadapter<1-N> none|<devicename>]\n"
174#endif
175 " [-intnet<1-N> <network name>]\n"
176 " [-natnet<1-N> <network>|default]\n"
177 " [-macaddress<1-N> auto|<mac>]\n"
178 " [-uart<1-N> off|<I/O base> <IRQ>]\n"
179 " [-uartmode<1-N> disconnected|\n"
180 " server <pipe>|\n"
181 " client <pipe>|\n"
182 " <devicename>]\n"
183#ifdef VBOX_WITH_MEM_BALLOONING
184 " [-guestmemoryballoon <balloonsize in MB>]\n"
185#endif
186 " [-gueststatisticsinterval <seconds>]\n"
187 );
188 RTPrintf(" [-audio none|null");
189 if (fWin)
190 {
191#ifdef VBOX_WITH_WINMM
192 RTPrintf( "|winmm|dsound");
193#else
194 RTPrintf( "|dsound");
195#endif
196 }
197 if (fSolaris)
198 {
199 RTPrintf( "|solaudio");
200 }
201 if (fLinux)
202 {
203 RTPrintf( "|oss"
204#ifdef VBOX_WITH_ALSA
205 "|alsa"
206#endif
207#ifdef VBOX_WITH_PULSE
208 "|pulse"
209#endif
210 );
211 }
212 if (fDarwin)
213 {
214 RTPrintf( "|coreaudio");
215 }
216 RTPrintf( "]\n");
217 RTPrintf(" [-audiocontroller ac97|sb16]\n"
218 " [-clipboard disabled|hosttoguest|guesttohost|\n"
219 " bidirectional]\n");
220 if (fVRDP)
221 {
222 RTPrintf(" [-vrdp on|off]\n"
223 " [-vrdpport default|<port>]\n"
224 " [-vrdpaddress <host>]\n"
225 " [-vrdpauthtype null|external|guest]\n"
226 " [-vrdpmulticon on|off]\n"
227 " [-vrdpreusecon on|off]\n");
228 }
229 RTPrintf(" [-usb on|off]\n"
230 " [-usbehci on|off]\n"
231 " [-snapshotfolder default|<path>]\n");
232 RTPrintf("\n");
233 }
234
235 if (u64Cmd & USAGE_IMPORTAPPLIANCE)
236 {
237 RTPrintf("VBoxManage import <ovf> [--dry-run|-n] [more options]\n"
238 " (run with -n to have options displayed for a particular OVF)\n\n");
239 }
240
241 if (u64Cmd & USAGE_EXPORTAPPLIANCE)
242 {
243 RTPrintf("VBoxManage export <machines> --output|-o <ovf>\n"
244 "\n");
245 }
246
247 if (u64Cmd & USAGE_STARTVM)
248 {
249 RTPrintf("VBoxManage startvm <uuid>|<name>\n");
250 if (fVRDP)
251 RTPrintf(" [-type gui|vrdp]\n");
252 RTPrintf("\n");
253 }
254
255 if (u64Cmd & USAGE_CONTROLVM)
256 {
257 RTPrintf("VBoxManage controlvm <uuid>|<name>\n"
258 " pause|resume|reset|poweroff|savestate|\n"
259 " acpipowerbutton|acpisleepbutton|\n"
260 " keyboardputscancode <hex> [<hex> ...]|\n"
261 " injectnmi|\n"
262 " setlinkstate<1-4> on|off |\n"
263 " usbattach <uuid>|<address> |\n"
264 " usbdetach <uuid>|<address> |\n"
265 " dvdattach none|<uuid>|<filename>|host:<drive> |\n"
266 " floppyattach none|<uuid>|<filename>|host:<drive> |\n");
267 if (fVRDP)
268 {
269 RTPrintf(" vrdp on|off] |\n");
270 }
271 RTPrintf(" setvideomodehint <xres> <yres> <bpp> [display]|\n"
272 " setcredentials <username> <password> <domain>\n"
273 " [-allowlocallogon <yes|no>]\n"
274 "\n");
275 }
276
277 if (u64Cmd & USAGE_DISCARDSTATE)
278 {
279 RTPrintf("VBoxManage discardstate <uuid>|<name>\n"
280 "\n");
281 }
282
283 if (u64Cmd & USAGE_ADOPTSTATE)
284 {
285 RTPrintf("VBoxManage adoptstate <uuid>|<name> <state_file>\n"
286 "\n");
287 }
288
289 if (u64Cmd & USAGE_SNAPSHOT)
290 {
291 RTPrintf("VBoxManage snapshot <uuid>|<name>\n"
292 " take <name> [-desc <desc>] |\n"
293 " discard <uuid>|<name> |\n"
294 " discardcurrent -state|-all |\n"
295 " edit <uuid>|<name>|-current\n"
296 " [-newname <name>]\n"
297 " [-newdesc <desc>] |\n"
298 " showvminfo <uuid>|<name>\n"
299 "\n");
300 }
301
302 if (u64Cmd & USAGE_REGISTERIMAGE)
303 {
304 RTPrintf("VBoxManage openmedium disk|dvd|floppy <filename>\n"
305 " [-type normal|immutable|writethrough] (disk only)\n"
306 "\n");
307 }
308
309 if (u64Cmd & USAGE_UNREGISTERIMAGE)
310 {
311 RTPrintf("VBoxManage closemedium disk|dvd|floppy <uuid>|<filename>\n"
312 "\n");
313 }
314
315 if (u64Cmd & USAGE_SHOWHDINFO)
316 {
317 RTPrintf("VBoxManage showhdinfo <uuid>|<filename>\n"
318 "\n");
319 }
320
321 if (u64Cmd & USAGE_CREATEHD)
322 {
323 RTPrintf("VBoxManage createhd --filename <filename>\n"
324 " --size <megabytes>\n"
325 " [--format VDI|VMDK|VHD] (default: VDI)\n"
326 " [--variant Standard,Fixed,Diff,Split2G,Stream]\n"
327 " [--type normal|writethrough] (default: normal)\n"
328 " [--comment <comment>]\n"
329 " [--remember]\n"
330 "\n");
331 }
332
333 if (u64Cmd & USAGE_MODIFYHD)
334 {
335 RTPrintf("VBoxManage modifyhd <uuid>|<filename>\n"
336 " settype normal|writethrough|immutable |\n"
337 " autoreset on|off |\n"
338 " compact\n"
339 "\n");
340 }
341
342 if (u64Cmd & USAGE_CLONEHD)
343 {
344 RTPrintf("VBoxManage clonehd <uuid>|<filename> <outputfile>\n"
345 " [--format VDI|VMDK|VHD|RAW|<other>]\n"
346 " [--variant Standard,Fixed,Diff,Split2G,Stream]\n"
347 " [--type normal|writethrough|immutable]\n"
348 " [--remember]\n"
349 "\n");
350 }
351
352 if (u64Cmd & USAGE_CONVERTFROMRAW)
353 {
354 RTPrintf("VBoxManage convertfromraw <filename> <outputfile>\n"
355 " [--format VDI|VMDK|VHD]\n"
356 " [--variant Standard,Fixed,Diff,Split2G,Stream]\n"
357 "VBoxManage convertfromraw stdin <outputfile> <bytes>\n"
358 " [--format VDI|VMDK|VHD]\n"
359 " [--variant Standard,Fixed,Diff,Split2G,Stream]\n"
360 "\n");
361 }
362
363 if (u64Cmd & USAGE_ADDISCSIDISK)
364 {
365 RTPrintf("VBoxManage addiscsidisk -server <name>|<ip>\n"
366 " -target <target>\n"
367 " [-port <port>]\n"
368 " [-lun <lun>]\n"
369 " [-encodedlun <lun>]\n"
370 " [-username <username>]\n"
371 " [-password <password>]\n"
372 " [-comment <comment>]\n"
373 " [-intnet]\n"
374 "\n");
375 }
376
377 if (u64Cmd & USAGE_GETEXTRADATA)
378 {
379 RTPrintf("VBoxManage getextradata global|<uuid>|<name>\n"
380 " <key>|enumerate\n"
381 "\n");
382 }
383
384 if (u64Cmd & USAGE_SETEXTRADATA)
385 {
386 RTPrintf("VBoxManage setextradata global|<uuid>|<name>\n"
387 " <key>\n"
388 " [<value>] (no value deletes key)\n"
389 "\n");
390 }
391
392 if (u64Cmd & USAGE_SETPROPERTY)
393 {
394 RTPrintf("VBoxManage setproperty hdfolder default|<folder> |\n"
395 " machinefolder default|<folder> |\n"
396 " vrdpauthlibrary default|<library> |\n"
397 " websrvauthlibrary default|null|<library> |\n"
398 " hwvirtexenabled yes|no\n"
399 " loghistorycount <value>\n"
400 "\n");
401 }
402
403 if (u64Cmd & USAGE_USBFILTER_ADD)
404 {
405 RTPrintf("VBoxManage usbfilter add <index,0-N>\n"
406 " -target <uuid>|<name>|global\n"
407 " -name <string>\n"
408 " -action ignore|hold (global filters only)\n"
409 " [-active yes|no] (yes)\n"
410 " [-vendorid <XXXX>] (null)\n"
411 " [-productid <XXXX>] (null)\n"
412 " [-revision <IIFF>] (null)\n"
413 " [-manufacturer <string>] (null)\n"
414 " [-product <string>] (null)\n"
415 " [-remote yes|no] (null, VM filters only)\n"
416 " [-serialnumber <string>] (null)\n"
417 " [-maskedinterfaces <XXXXXXXX>]\n"
418 "\n");
419 }
420
421 if (u64Cmd & USAGE_USBFILTER_MODIFY)
422 {
423 RTPrintf("VBoxManage usbfilter modify <index,0-N>\n"
424 " -target <uuid>|<name>|global\n"
425 " [-name <string>]\n"
426 " [-action ignore|hold] (global filters only)\n"
427 " [-active yes|no]\n"
428 " [-vendorid <XXXX>|\"\"]\n"
429 " [-productid <XXXX>|\"\"]\n"
430 " [-revision <IIFF>|\"\"]\n"
431 " [-manufacturer <string>|\"\"]\n"
432 " [-product <string>|\"\"]\n"
433 " [-remote yes|no] (null, VM filters only)\n"
434 " [-serialnumber <string>|\"\"]\n"
435 " [-maskedinterfaces <XXXXXXXX>]\n"
436 "\n");
437 }
438
439 if (u64Cmd & USAGE_USBFILTER_REMOVE)
440 {
441 RTPrintf("VBoxManage usbfilter remove <index,0-N>\n"
442 " -target <uuid>|<name>|global\n"
443 "\n");
444 }
445
446 if (u64Cmd & USAGE_SHAREDFOLDER_ADD)
447 {
448 RTPrintf("VBoxManage sharedfolder add <vmname>|<uuid>\n"
449 " -name <name> -hostpath <hostpath>\n"
450 " [-transient] [-readonly]\n"
451 "\n");
452 }
453
454 if (u64Cmd & USAGE_SHAREDFOLDER_REMOVE)
455 {
456 RTPrintf("VBoxManage sharedfolder remove <vmname>|<uuid>\n"
457 " -name <name> [-transient]\n"
458 "\n");
459 }
460
461 if (u64Cmd & USAGE_VM_STATISTICS)
462 {
463 RTPrintf("VBoxManage vmstatistics <vmname>|<uuid> [-reset]\n"
464 " [-pattern <pattern>] [-descriptions]\n"
465 "\n");
466 }
467
468#ifdef VBOX_WITH_GUEST_PROPS
469 if (u64Cmd & USAGE_GUESTPROPERTY)
470 usageGuestProperty();
471#endif /* VBOX_WITH_GUEST_PROPS defined */
472
473 if (u64Cmd & USAGE_METRICS)
474 {
475 RTPrintf("VBoxManage metrics list [*|host|<vmname> [<metric_list>]]\n"
476 " (comma-separated)\n\n"
477 "VBoxManage metrics setup\n"
478 " [-period <seconds>]\n"
479 " [-samples <count>]\n"
480 " [-list]\n"
481 " [*|host|<vmname> [<metric_list>]]\n\n"
482 "VBoxManage metrics query [*|host|<vmname> [<metric_list>]]\n\n"
483 "VBoxManage metrics collect\n"
484 " [-period <seconds>]\n"
485 " [-samples <count>]\n"
486 " [-list]\n"
487 " [-detach]\n"
488 " [*|host|<vmname> [<metric_list>]]\n"
489 "\n");
490 }
491#if defined(VBOX_WITH_NETFLT)
492 if (u64Cmd & USAGE_HOSTONLYIFS)
493 {
494 RTPrintf("VBoxManage hostonlyif ipconfig <name>\n"
495 " [--dhcp |\n"
496 " --ip<ipv4> [--netmask<ipv4> (def: 255.255.255.0)] |\n"
497 " --ipv6<ipv6> [--netmasklengthv6<length> (def: 64)]]\n"
498# if defined(RT_OS_WINDOWS)
499 " create |\n"
500 " remove <name>\n"
501# endif
502 "\n");
503 }
504#endif
505
506 if (u64Cmd & USAGE_DHCPSERVER)
507 {
508 RTPrintf("VBoxManage dhcpserver add|modify --netname <network_name> |\n"
509#if defined(VBOX_WITH_NETFLT)
510 " --ifname <hostonly_if_name>\n"
511#endif
512 " [--ip <ip_address>\n"
513 " --netmask <network_mask>\n"
514 " --lowerip <lower_ip>\n"
515 " --upperip <upper_ip>]\n"
516 " [--enable | --disable]\n"
517 "VBoxManage dhcpserver remove --netname <network_name> |\n"
518#if defined(VBOX_WITH_NETFLT)
519 " --ifname <hostonly_if_name>\n"
520#endif
521 "\n");
522 }
523}
524
525/**
526 * Print a usage synopsis and the syntax error message.
527 */
528int errorSyntax(USAGECATEGORY u64Cmd, const char *pszFormat, ...)
529{
530 va_list args;
531 showLogo(); // show logo even if suppressed
532#ifndef VBOX_ONLY_DOCS
533 if (g_fInternalMode)
534 printUsageInternal(u64Cmd);
535 else
536 printUsage(u64Cmd);
537#endif /* !VBOX_ONLY_DOCS */
538 va_start(args, pszFormat);
539 RTPrintf("\n"
540 "Syntax error: %N\n", pszFormat, &args);
541 va_end(args);
542 return 1;
543}
544
545/**
546 * Print an error message without the syntax stuff.
547 */
548int errorArgument(const char *pszFormat, ...)
549{
550 va_list args;
551 va_start(args, pszFormat);
552 RTPrintf("error: %N\n", pszFormat, &args);
553 va_end(args);
554 return 1;
555}
556
557#ifndef VBOX_ONLY_DOCS
558/**
559 * Print out progress on the console
560 */
561void showProgress(ComPtr<IProgress> progress)
562{
563 BOOL fCompleted;
564 LONG currentPercent;
565 LONG lastPercent = 0;
566
567 RTPrintf("0%%...");
568 RTStrmFlush(g_pStdOut);
569 while (SUCCEEDED(progress->COMGETTER(Completed(&fCompleted))))
570 {
571 progress->COMGETTER(Percent(&currentPercent));
572
573 /* did we cross a 10% mark? */
574 if (((currentPercent / 10) > (lastPercent / 10)))
575 {
576 /* make sure to also print out missed steps */
577 for (LONG curVal = (lastPercent / 10) * 10 + 10; curVal <= (currentPercent / 10) * 10; curVal += 10)
578 {
579 if (curVal < 100)
580 {
581 RTPrintf("%ld%%...", curVal);
582 RTStrmFlush(g_pStdOut);
583 }
584 }
585 lastPercent = (currentPercent / 10) * 10;
586 }
587 if (fCompleted)
588 break;
589
590 /* make sure the loop is not too tight */
591 progress->WaitForCompletion(100);
592 }
593
594 /* complete the line. */
595 HRESULT rc;
596 if (SUCCEEDED(progress->COMGETTER(ResultCode)(&rc)))
597 {
598 if (SUCCEEDED(rc))
599 RTPrintf("100%%\n");
600 else
601 RTPrintf("FAILED\n");
602 }
603 else
604 RTPrintf("\n");
605 RTStrmFlush(g_pStdOut);
606}
607
608#endif /* !VBOX_ONLY_DOCS */
Note: See TracBrowser for help on using the repository browser.

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