VirtualBox

Changeset 90219 in vbox


Ignore:
Timestamp:
Jul 15, 2021 8:41:15 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
145756
Message:

VBoxManage: "cloud machine" work out the getopt boilerplate. bugref:10065.

File:
1 edited

Legend:

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

    r90214 r90219  
    2525
    2626
     27RTEXITCODE listCloudMachines(HandlerArg *a, int iFirst, const ComPtr<ICloudProfile> &pCloudProfile);
     28
     29
     30/*
     31 * RTGETOPTINIT_FLAGS_NO_STD_OPTS recognizes both --help and --version
     32 * and we don't want the latter.  It's easier to add one line of this
     33 * macro to the s_aOptions initializers than to filter out --version.
     34 */
     35#define CLOUD_MACHINE_RTGETOPTDEF_HELP                                      \
     36        { "--help",         'h',                    RTGETOPT_REQ_NOTHING }, \
     37        { "-help",          'h',                    RTGETOPT_REQ_NOTHING }, \
     38        { "help",           'h',                    RTGETOPT_REQ_NOTHING }, \
     39        { "-?",             'h',                    RTGETOPT_REQ_NOTHING }
     40
     41
    2742/*
    2843 * VBoxManage cloud machine ...
     
    3449                              const ComPtr<ICloudProfile> &pCloudProfile)
    3550{
    36     RT_NOREF(a, iFirst, pCloudProfile);
     51    enum
     52    {
     53        kMachineIota = 1000,
     54        kMachine_Info,
     55        kMachine_List,
     56    };
    3757
    38     return RTMsgErrorExit(RTEXITCODE_FAILURE,
    39                "cloud machine - not yet implemented");
     58    static const RTGETOPTDEF s_aOptions[] =
     59    {
     60        { "info",           kMachine_Info,          RTGETOPT_REQ_NOTHING },
     61        { "list",           kMachine_List,          RTGETOPT_REQ_NOTHING },
     62          CLOUD_MACHINE_RTGETOPTDEF_HELP
     63    };
     64
     65    int rc;
     66
     67    RTGETOPTSTATE OptState;
     68    rc = RTGetOptInit(&OptState, a->argc, a->argv,
     69                      s_aOptions, RT_ELEMENTS(s_aOptions),
     70                      iFirst, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
     71    AssertRCStmt(rc,
     72        return RTMsgErrorExit(RTEXITCODE_INIT, /* internal error */
     73                   "cloud machine: RTGetOptInit: %Rra", rc));
     74
     75    int ch;
     76    RTGETOPTUNION Val;
     77    while ((ch = RTGetOpt(&OptState, &Val)) != 0)
     78    {
     79        switch (ch)
     80        {
     81            case kMachine_Info:
     82                return RTMsgErrorExit(RTEXITCODE_FAILURE,
     83                                      "cloud machine info: not yet implemented");
     84
     85            case kMachine_List:
     86                return listCloudMachines(a, OptState.iNext, pCloudProfile);
     87
     88
     89            case 'h':           /* --help */
     90                printHelp(g_pStdOut);
     91                return RTEXITCODE_SUCCESS;
     92
     93
     94            case VINF_GETOPT_NOT_OPTION:
     95                return RTMsgErrorExit(RTEXITCODE_SYNTAX,
     96                           "Invalid sub-command: %s", Val.psz);
     97
     98            default:
     99                return RTGetOptPrintError(ch, &Val);
     100        }
     101    }
     102
     103    return RTMsgErrorExit(RTEXITCODE_SYNTAX,
     104               "cloud machine: command required\n"
     105               "Try '--help' for more information.");
    40106}
    41107
     
    43109/*
    44110 * VBoxManage cloud list machines
    45  * VBoxManage cloud machine list
     111 * VBoxManage cloud machine list # convenience alias
    46112 *
    47113 * The "cloud list" prefix handling is in VBoxManageCloud.cpp, so this
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