VirtualBox

Ignore:
Timestamp:
Feb 24, 2009 8:18:52 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
43329
Message:

VBoxManage: new export command line parsing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageImport.cpp

    r17074 r17098  
    4141
    4242#include <iprt/stream.h>
     43#include <iprt/getopt.h>
    4344
    4445#include <VBox/log.h>
     
    493494}
    494495
     496static const RTGETOPTDEF g_aExportOptions[]
     497    = {
     498        { "--output",             'o', RTGETOPT_REQ_STRING },
     499      };
     500
    495501int handleExportAppliance(HandlerArg *a)
    496502{
     
    502508    do
    503509    {
    504         for (int i = 0;
    505             i < a->argc;
    506             ++i)
    507         {
    508             Utf8Str strThisArg(a->argv[i]);
    509 
    510             if (    strThisArg == "--output"
    511                 || strThisArg == "-output"
    512                 || strThisArg == "-o"
    513             )
     510        int c;
     511
     512        RTGETOPTUNION ValueUnion;
     513        RTGETOPTSTATE GetState;
     514        RTGetOptInit(&GetState,
     515                     a->argc,
     516                     a->argv,
     517                     g_aExportOptions,
     518                     RT_ELEMENTS(g_aExportOptions),
     519                     0, // start at 0 even though arg 1 was "list" because main() has hacked both the argc and argv given to us
     520                     0 /* fFlags */);
     521        while ((c = RTGetOpt(&GetState, &ValueUnion)))
     522        {
     523            switch (c)
    514524            {
    515                 if (++i < a->argc)
    516                 {
     525                case 'o':   // --output
    517526                    if (strOutputFile.length())
    518527                        return errorSyntax(USAGE_EXPORTAPPLIANCE, "You can only specify --output once.");
    519528                    else
    520                         strOutputFile = strThisArg;
     529                        strOutputFile = ValueUnion.psz;
     530                break;
     531
     532                case VINF_GETOPT_NOT_OPTION:
     533                {
     534                    Utf8Str strMachine(ValueUnion.psz);
     535                    // must be machine: try UUID or name
     536                    ComPtr<IMachine> machine;
     537                    /* assume it's a UUID */
     538                    rc = a->virtualBox->GetMachine(Guid(strMachine), machine.asOutParam());
     539                    if (FAILED(rc) || !machine)
     540                    {
     541                        /* must be a name */
     542                        CHECK_ERROR_BREAK(a->virtualBox, FindMachine(Bstr(strMachine), machine.asOutParam()));
     543                    }
     544
     545                    if (machine)
     546                        llMachines.push_back(machine);
    521547                }
    522                 else
    523                     return errorSyntax(USAGE_EXPORTAPPLIANCE, "Missing argument to --output option.");
    524             }
    525             else
    526             {
    527                 // must be machine: try UUID or name
    528                 ComPtr<IMachine> machine;
    529                 /* assume it's a UUID */
    530                 rc = a->virtualBox->GetMachine(Guid(strThisArg), machine.asOutParam());
    531                 if (FAILED(rc) || !machine)
    532                 {
    533                     /* must be a name */
    534                     CHECK_ERROR_BREAK(a->virtualBox, FindMachine(Bstr(strThisArg), machine.asOutParam()));
    535                 }
    536 
    537                 if (machine)
    538                     llMachines.push_back(machine);
     548                break;
     549
     550                default:
     551                    if (c > 0)
     552                        return errorSyntax(USAGE_LIST, "missing case: %c\n", c);
     553                    else if (ValueUnion.pDef)
     554                        return errorSyntax(USAGE_LIST, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
     555                    else
     556                        return errorSyntax(USAGE_LIST, "%Rrs", c);
    539557            }
    540558        }
     
    544562
    545563        if (llMachines.size() == 0)
    546             return errorSyntax(USAGE_EXPORTAPPLIANCE, "Missing arguments to export command.");
     564            return errorSyntax(USAGE_EXPORTAPPLIANCE, "At least one machine must be specified with the export command.");
     565        if (!strOutputFile.length())
     566            return errorSyntax(USAGE_EXPORTAPPLIANCE, "Missing --output argument with export command.");
    547567
    548568        ComPtr<IAppliance> pAppliance;
Note: See TracChangeset for help on using the changeset viewer.

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