VirtualBox

Changeset 65827 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 21, 2017 8:49:45 AM (8 years ago)
Author:
vboxsync
Message:

VBoxManage: added --machinereadable option to 'VBoxManage hostonlyif create' (thanks Sara Golemon)

File:
1 edited

Legend:

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

    r63300 r65827  
    4444using namespace com;
    4545
     46static const RTGETOPTDEF g_aHostOnlyCreateOptions[] =
     47{
     48    { "--machinereadable",  'M', RTGETOPT_REQ_NOTHING },
     49};
     50
    4651#if defined(VBOX_WITH_NETFLT) && !defined(RT_OS_SOLARIS)
    4752static RTEXITCODE handleCreate(HandlerArg *a)
     
    5055     * Parse input.
    5156     */
     57    bool fMachineReadable = false;
    5258    RTGETOPTUNION ValueUnion;
    5359    RTGETOPTSTATE GetState;
    54     RTGetOptInit(&GetState, a->argc, a->argv, NULL, 0, 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
    55     int ch = RTGetOpt(&GetState, &ValueUnion);
    56     if (ch != 0)
    57         return errorGetOpt(USAGE_HOSTONLYIFS, ch, &ValueUnion);
     60    RTGetOptInit(&GetState, a->argc, a->argv, g_aHostOnlyCreateOptions,
     61                 RT_ELEMENTS(g_aHostOnlyCreateOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
     62    int c;
     63    while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0)
     64    {
     65        switch (c)
     66        {
     67            case 'M':   // --machinereadable
     68                fMachineReadable = true;
     69                break;
     70
     71            default:
     72                return errorGetOpt(USAGE_HOSTONLYIFS, c, &ValueUnion);
     73        }
     74    }
    5875
    5976    /*
     
    6885    CHECK_ERROR2I_RET(host, CreateHostOnlyNetworkInterface(hif.asOutParam(), progress.asOutParam()), RTEXITCODE_FAILURE);
    6986
    70     /*HRESULT hrc =*/ showProgress(progress);
    71     CHECK_PROGRESS_ERROR_RET(progress, ("Failed to create the host-only adapter"), RTEXITCODE_FAILURE);
     87    if (fMachineReadable)
     88    {
     89        CHECK_PROGRESS_ERROR_RET(progress, (""), RTEXITCODE_FAILURE);
     90    }
     91    else
     92    {
     93        /*HRESULT hrc =*/ showProgress(progress);
     94        CHECK_PROGRESS_ERROR_RET(progress, ("Failed to create the host-only adapter"), RTEXITCODE_FAILURE);
     95    }
    7296
    7397    Bstr bstrName;
    7498    CHECK_ERROR2I(hif, COMGETTER(Name)(bstrName.asOutParam()));
    7599
    76     RTPrintf("Interface '%ls' was successfully created\n", bstrName.raw());
    77 
     100    if (fMachineReadable)
     101        RTPrintf("%ls", bstrName.raw());
     102    else
     103        RTPrintf("Interface '%ls' was successfully created\n", bstrName.raw());
    78104    return RTEXITCODE_SUCCESS;
    79105}
Note: See TracChangeset for help on using the changeset viewer.

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