Index: trunk/src/VBox/Frontends/VBoxManage/VBoxManageCloudMachine.cpp
===================================================================
--- trunk/src/VBox/Frontends/VBoxManage/VBoxManageCloudMachine.cpp	(revision 91337)
+++ trunk/src/VBox/Frontends/VBoxManage/VBoxManageCloudMachine.cpp	(revision 91338)
@@ -28,4 +28,18 @@
 
 
+struct CMachineHandlerArg
+  : public HandlerArg
+{
+    ComPtr<ICloudClient> pClient;
+
+    const char *pcszSpec;   /* RTGETOPTUNION::psz, points inside argv */
+    enum { GUESS, ID, NAME } enmSpecKind;
+    ComPtr<ICloudMachine> pMachine;
+
+    explicit CMachineHandlerArg(const HandlerArg &a)
+      : HandlerArg(a), pcszSpec(NULL), enmSpecKind(GUESS) {}
+};
+
+
 static int selectCloudProvider(ComPtr<ICloudProvider> &pProvider,
                                const ComPtr<IVirtualBox> &pVirtualBox,
@@ -34,6 +48,5 @@
                               const ComPtr<ICloudProvider> &pProvider,
                               const char *pszProviderName);
-static int getCloudClient(ComPtr<ICloudClient> &aClient,
-                          HandlerArg *a,
+static int getCloudClient(CMachineHandlerArg &a,
                           const char *pcszProviderName,
                           const char *pcszProfileName);
@@ -42,50 +55,25 @@
                               const ComPtr<ICloudClient> &pClient);
 
-static HRESULT getMachineById(ComPtr<ICloudMachine> &pMachineOut,
-                              const ComPtr<ICloudClient> &pClient,
-                              const char *pcszId);
-static HRESULT getMachineByName(ComPtr<ICloudMachine> &pMachineOut,
-                                const ComPtr<ICloudClient> &pClient,
-                                const char *pcszName);
-static HRESULT getMachineByGuess(ComPtr<ICloudMachine> &pMachineOut,
-                                 const ComPtr<ICloudClient> &pClient,
-                                 const char *pcszWhatever);
-
-struct MachineSpec {
-    const char *pcszSpec;
-    enum { GUESS, ID, NAME } enmKind;
-
-    MachineSpec()
-      : pcszSpec(NULL), enmKind(GUESS) {}
-};
-
-static int checkMachineSpecArgument(MachineSpec &aMachineSpec,
+static HRESULT getMachineBySpec(CMachineHandlerArg *a);
+static HRESULT getMachineById(CMachineHandlerArg *a);
+static HRESULT getMachineByName(CMachineHandlerArg *a);
+static HRESULT getMachineByGuess(CMachineHandlerArg *a);
+
+static int checkMachineSpecArgument(CMachineHandlerArg *a,
                                     int ch, const RTGETOPTUNION &Val);
-static HRESULT getMachineBySpec(ComPtr<ICloudMachine> &pMachineOut,
-                                const ComPtr<ICloudClient> &pClient,
-                                const MachineSpec &aMachineSpec);
-
-
-static RTEXITCODE handleCloudMachineImpl(HandlerArg *a, int iFirst,
-                                         const ComPtr<ICloudClient> &pClient);
-
-static RTEXITCODE handleCloudMachineStart(HandlerArg *a, int iFirst,
-                                          const ComPtr<ICloudClient> &pClient);
-static RTEXITCODE handleCloudMachineReboot(HandlerArg *a, int iFirst,
-                                           const ComPtr<ICloudClient> &pClient);
-static RTEXITCODE handleCloudMachineShutdown(HandlerArg *a, int iFirst,
-                                             const ComPtr<ICloudClient> &pClient);
-static RTEXITCODE handleCloudMachinePowerdown(HandlerArg *a, int iFirst,
-                                              const ComPtr<ICloudClient> &pClient);
-static RTEXITCODE handleCloudMachineTerminate(HandlerArg *a, int iFirst,
-                                              const ComPtr<ICloudClient> &pClient);
-
-static RTEXITCODE handleCloudMachineConsoleHistory(HandlerArg *a, int iFirst,
-                                                   const ComPtr<ICloudClient> &pClient);
-
-static RTEXITCODE listCloudMachinesImpl(HandlerArg *a, int iFirst,
-                                        const ComPtr<ICloudClient> &pClient);
-static RTEXITCODE handleCloudMachineInfo(HandlerArg *a, int iFirst,
-                                          const ComPtr<ICloudClient> &pClient);
+
+
+static RTEXITCODE handleCloudMachineImpl(CMachineHandlerArg *a, int iFirst);
+
+static RTEXITCODE handleCloudMachineStart(CMachineHandlerArg *a, int iFirst);
+static RTEXITCODE handleCloudMachineReboot(CMachineHandlerArg *a, int iFirst);
+static RTEXITCODE handleCloudMachineShutdown(CMachineHandlerArg *a, int iFirst);
+static RTEXITCODE handleCloudMachinePowerdown(CMachineHandlerArg *a, int iFirst);
+static RTEXITCODE handleCloudMachineTerminate(CMachineHandlerArg *a, int iFirst);
+
+static RTEXITCODE handleCloudMachineConsoleHistory(CMachineHandlerArg *a, int iFirst);
+
+static RTEXITCODE listCloudMachinesImpl(CMachineHandlerArg *a, int iFirst);
+static RTEXITCODE handleCloudMachineInfo(CMachineHandlerArg *a, int iFirst);
 
 static HRESULT printMachineInfo(const ComPtr<ICloudMachine> &pMachine);
@@ -119,10 +107,10 @@
                    const char *pcszProfileName)
 {
-    ComPtr<ICloudClient> pClient;
-    int rc = getCloudClient(pClient, a, pcszProviderName, pcszProfileName);
+    CMachineHandlerArg handlerArg(*a);
+    int rc = getCloudClient(handlerArg, pcszProviderName, pcszProfileName);
     if (RT_FAILURE(rc))
         return RTEXITCODE_FAILURE;
 
-    return handleCloudMachineImpl(a, iFirst, pClient);
+    return handleCloudMachineImpl(&handlerArg, iFirst);
 }
 
@@ -257,6 +245,5 @@
 
 static int
-getCloudClient(ComPtr<ICloudClient> &aCloudClient,
-                HandlerArg *a,
+getCloudClient(CMachineHandlerArg &a,
                 const char *pcszProviderName,
                 const char *pcszProfileName)
@@ -266,5 +253,5 @@
 
     ComPtr<ICloudProvider> pProvider;
-    rc = selectCloudProvider(pProvider, a->virtualBox, pcszProviderName);
+    rc = selectCloudProvider(pProvider, a.virtualBox, pcszProviderName);
     if (RT_FAILURE(rc))
         return rc;
@@ -280,5 +267,5 @@
             VERR_GENERAL_FAILURE);
 
-    aCloudClient = pCloudClient;
+    a.pClient = pCloudClient;
     return VINF_SUCCESS;
 }
@@ -309,13 +296,11 @@
 
 static HRESULT
-getMachineById(ComPtr<ICloudMachine> &pMachineOut,
-               const ComPtr<ICloudClient> &pClient,
-               const char *pcszId)
+getMachineById(CMachineHandlerArg *a)
 {
     HRESULT hrc;
 
     ComPtr<ICloudMachine> pMachine;
-    CHECK_ERROR2_RET(hrc, pClient,
-        GetCloudMachine(com::Bstr(pcszId).raw(),
+    CHECK_ERROR2_RET(hrc, a->pClient,
+        GetCloudMachine(com::Bstr(a->pcszSpec).raw(),
                         pMachine.asOutParam()), hrc);
 
@@ -328,5 +313,5 @@
         return hrc;
 
-    pMachineOut = pMachine;
+    a->pMachine = pMachine;
     return S_OK;
 }
@@ -334,12 +319,10 @@
 
 static HRESULT
-getMachineByName(ComPtr<ICloudMachine> &pMachineOut,
-                 const ComPtr<ICloudClient> &pClient,
-                 const char *pcszName)
+getMachineByName(CMachineHandlerArg *a)
 {
     HRESULT hrc;
 
     com::SafeIfaceArray<ICloudMachine> aMachines;
-    hrc = getMachineList(aMachines, pClient);
+    hrc = getMachineList(aMachines, a->pClient);
     if (FAILED(hrc))
         return hrc;
@@ -359,5 +342,5 @@
                 hrc);
 
-        if (!bstrName.equals(pcszName))
+        if (!bstrName.equals(a->pcszSpec))
             continue;
 
@@ -384,5 +367,5 @@
         return VBOX_E_OBJECT_NOT_FOUND;
 
-    pMachineOut = pMachineFound;
+    a->pMachine = pMachineFound;
     return S_OK;
 }
@@ -398,23 +381,18 @@
  */
 static HRESULT
-getMachineByGuess(ComPtr<ICloudMachine> &pMachineOut,
-                  const ComPtr<ICloudClient> &pClient,
-                  const char *pcszWhatever)
-{
-    ComPtr<ICloudMachine> pMachine;
-
+getMachineByGuess(CMachineHandlerArg *a)
+{
     HRESULT hrc;
 
     RTUUID Uuid;
-    int rc = RTUuidFromStr(&Uuid, pcszWhatever);
+    int rc = RTUuidFromStr(&Uuid, a->pcszSpec);
     if (RT_SUCCESS(rc))
-        hrc = getMachineById(pMachine, pClient, pcszWhatever);
+        hrc = getMachineById(a);
     else
-        hrc = getMachineByName(pMachine, pClient, pcszWhatever);
+        hrc = getMachineByName(a);
 
     if (FAILED(hrc))
         return hrc;
 
-    pMachineOut = pMachine;
     return S_OK;
 }
@@ -456,5 +434,5 @@
  */
 static int
-checkMachineSpecArgument(MachineSpec &aMachineSpec,
+checkMachineSpecArgument(CMachineHandlerArg *a,
                          int ch, const RTGETOPTUNION &Val)
 {
@@ -475,5 +453,5 @@
             const char *pcszId = Val.psz;
 
-            if (aMachineSpec.pcszSpec != NULL)
+            if (a->pcszSpec != NULL)
             {
                 errThereCanBeOnlyOne();
@@ -489,6 +467,6 @@
             }
 
-            aMachineSpec.pcszSpec = pcszId;
-            aMachineSpec.enmKind = MachineSpec::ID;
+            a->pcszSpec = pcszId;
+            a->enmSpecKind = CMachineHandlerArg::ID;
             return VINF_SUCCESS;
         }
@@ -498,5 +476,5 @@
             const char *pcszName = Val.psz;
 
-            if (aMachineSpec.pcszSpec != NULL)
+            if (a->pcszSpec != NULL)
             {
                 errThereCanBeOnlyOne();
@@ -504,6 +482,6 @@
             }
 
-            aMachineSpec.pcszSpec = pcszName;
-            aMachineSpec.enmKind = MachineSpec::NAME;
+            a->pcszSpec = pcszName;
+            a->enmSpecKind = CMachineHandlerArg::NAME;
             return VINF_SUCCESS;
         }
@@ -517,5 +495,5 @@
             const char *pcszNameOrId = Val.psz;
 
-            if (aMachineSpec.pcszSpec != NULL)
+            if (a->pcszSpec != NULL)
             {
                 errThereCanBeOnlyOne();
@@ -523,6 +501,6 @@
             }
 
-            aMachineSpec.pcszSpec = pcszNameOrId;
-            aMachineSpec.enmKind = MachineSpec::GUESS;
+            a->pcszSpec = pcszNameOrId;
+            a->enmSpecKind = CMachineHandlerArg::GUESS;
             return VINF_SUCCESS;
         }
@@ -542,11 +520,9 @@
 
 static HRESULT
-getMachineBySpec(ComPtr<ICloudMachine> &pMachineOut,
-                 const ComPtr<ICloudClient> &pClient,
-                 const MachineSpec &aMachineSpec)
+getMachineBySpec(CMachineHandlerArg *a)
 {
     HRESULT hrc = E_FAIL;
 
-    if (aMachineSpec.pcszSpec == NULL)
+    if (a->pcszSpec == NULL)
     {
         RTMsgErrorExit(RTEXITCODE_SYNTAX, "machine not specified");
@@ -554,5 +530,5 @@
     }
 
-    if (aMachineSpec.pcszSpec[0] == '\0')
+    if (a->pcszSpec[0] == '\0')
     {
         RTMsgError("machine name is empty");
@@ -560,32 +536,32 @@
     }
 
-    switch (aMachineSpec.enmKind)
-    {
-        case MachineSpec::ID:
-            hrc = getMachineById(pMachineOut, pClient, aMachineSpec.pcszSpec);
+    switch (a->enmSpecKind)
+    {
+        case CMachineHandlerArg::ID:
+            hrc = getMachineById(a);
             if (FAILED(hrc))
             {
                 if (hrc == VBOX_E_OBJECT_NOT_FOUND)
-                    RTMsgError("unable to find machine with id %s", aMachineSpec.pcszSpec);
+                    RTMsgError("unable to find machine with id %s", a->pcszSpec);
                 return hrc;
             }
             break;
 
-        case MachineSpec::NAME:
-            hrc = getMachineByName(pMachineOut, pClient, aMachineSpec.pcszSpec);
+        case CMachineHandlerArg::NAME:
+            hrc = getMachineByName(a);
             if (FAILED(hrc))
             {
                 if (hrc == VBOX_E_OBJECT_NOT_FOUND)
-                    RTMsgError("unable to find machine with name %s", aMachineSpec.pcszSpec);
+                    RTMsgError("unable to find machine with name %s", a->pcszSpec);
                 return hrc;
             }
             break;
 
-        case MachineSpec::GUESS:
-            hrc = getMachineByGuess(pMachineOut, pClient, aMachineSpec.pcszSpec);
+        case CMachineHandlerArg::GUESS:
+            hrc = getMachineByGuess(a);
             if (FAILED(hrc))
             {
                 if (hrc == VBOX_E_OBJECT_NOT_FOUND)
-                    RTMsgError("unable to find machine %s", aMachineSpec.pcszSpec);
+                    RTMsgError("unable to find machine %s", a->pcszSpec);
                 return hrc;
             }
@@ -602,12 +578,24 @@
 
 /*
- * cloud machine ...
+ * cloud machine [--id id | --name name] command ...
  *
- * The "cloud" prefix handling is in VBoxManageCloud.cpp, so this
- * function is not static.
+ * We allow machine to be specified after "machine" but only with an
+ * explicit option for the obvious reason.  We will also check for
+ * these options and machine spec as a plain words argument after the
+ * command word, so user can use either of:
+ *
+ *   cloud machine --name foo start
+ *   cloud machine start --name foo
+ *   cloud machine start foo
+ *
+ * This will accept e.g.  cloud machine --name foo list ... b/c we
+ * don't yet know that it's "list" that is coming, so commands that
+ * don't take machine argument check that separately when called.  One
+ * side effect of this is that specifying several machines or using a
+ * syntactically invalid id will be reported as such, not as an
+ * unknown option, but that's a relatively minor nit.
  */
 static RTEXITCODE
-handleCloudMachineImpl(HandlerArg *a, int iFirst,
-                       const ComPtr<ICloudClient> &pClient)
+handleCloudMachineImpl(CMachineHandlerArg *a, int iFirst)
 {
     int rc;
@@ -638,4 +626,5 @@
         { "start",              kMachine_Start,             RTGETOPT_REQ_NOTHING },
         { "terminate",          kMachine_Terminate,         RTGETOPT_REQ_NOTHING },
+        CLOUD_MACHINE_RTGETOPTDEF_MACHINE,
         CLOUD_MACHINE_RTGETOPTDEF_HELP
     };
@@ -652,42 +641,60 @@
     while ((ch = RTGetOpt(&OptState, &Val)) != 0)
     {
+        if (RT_FAILURE(ch))
+            return RTGetOptPrintError(ch, &Val);
+
+        /*
+         * Check for an unknown word first: checkMachineSpecArgument()
+         * would try to interpret that as a machine id/name.
+         */
+        if (ch == VINF_GETOPT_NOT_OPTION)
+            return RTMsgErrorExit(RTEXITCODE_SYNTAX,
+                       "Invalid sub-command: %s", Val.psz);
+
+        /*
+         * Allow --id/--name after "machine", before the command.
+         * Also handles --help.
+         */
+        rc = checkMachineSpecArgument(a, ch, Val);
+        if (rc == VINF_SUCCESS)
+            continue;
+        else if (rc == VINF_CALLBACK_RETURN)
+            return RTEXITCODE_SUCCESS;
+        else if (rc == VERR_PARSE_ERROR)
+            return RTEXITCODE_SYNTAX;
+
+        /*
+         * Dispatch to command implementation ([ab]use getopt to do
+         * string comparisons for us).
+         */
         switch (ch)
         {
             case kMachine_ConsoleHistory:
-                return handleCloudMachineConsoleHistory(a, OptState.iNext, pClient);
+                return handleCloudMachineConsoleHistory(a, OptState.iNext);
 
             case kMachine_Info:
-                return handleCloudMachineInfo(a, OptState.iNext, pClient);
+                return handleCloudMachineInfo(a, OptState.iNext);
 
             case kMachine_List:
-                return listCloudMachinesImpl(a, OptState.iNext, pClient);
+                return listCloudMachinesImpl(a, OptState.iNext);
 
             case kMachine_Powerdown:
-                return handleCloudMachinePowerdown(a, OptState.iNext, pClient);
+                return handleCloudMachinePowerdown(a, OptState.iNext);
 
             case kMachine_Reboot:
-                return handleCloudMachineReboot(a, OptState.iNext, pClient);
+                return handleCloudMachineReboot(a, OptState.iNext);
 
             case kMachine_Shutdown:
-                return handleCloudMachineShutdown(a, OptState.iNext, pClient);
+                return handleCloudMachineShutdown(a, OptState.iNext);
 
             case kMachine_Start:
-                return handleCloudMachineStart(a, OptState.iNext, pClient);
+                return handleCloudMachineStart(a, OptState.iNext);
 
             case kMachine_Terminate:
-                return handleCloudMachineTerminate(a, OptState.iNext, pClient);
-
-
-            case 'h':           /* --help */
-                printHelp(g_pStdOut);
-                return RTEXITCODE_SUCCESS;
-
-
-            case VINF_GETOPT_NOT_OPTION:
-                return RTMsgErrorExit(RTEXITCODE_SYNTAX,
-                           "Invalid sub-command: %s", Val.psz);
-
-            default:
-                return RTGetOptPrintError(ch, &Val);
+                return handleCloudMachineTerminate(a, OptState.iNext);
+
+            default:            /* should never happen */
+                return RTMsgErrorExit(RTEXITCODE_INIT,
+                           "cloud machine: internal error: %d", ch);
         }
     }
@@ -711,12 +718,10 @@
                   const char *pcszProfileName)
 {
-    int rc;
-
-    ComPtr<ICloudClient> pClient;
-    rc = getCloudClient(pClient, a, pcszProviderName, pcszProfileName);
+    CMachineHandlerArg handlerArg(*a);
+    int rc = getCloudClient(handlerArg, pcszProviderName, pcszProfileName);
     if (RT_FAILURE(rc))
         return RTEXITCODE_FAILURE;
 
-    return listCloudMachinesImpl(a, iFirst, pClient);
+    return listCloudMachinesImpl(&handlerArg, iFirst);
 }
 
@@ -727,6 +732,5 @@
  */
 static RTEXITCODE
-listCloudMachinesImpl(HandlerArg *a, int iFirst,
-                      const ComPtr<ICloudClient> &pClient)
+listCloudMachinesImpl(CMachineHandlerArg *a, int iFirst)
 {
     HRESULT hrc;
@@ -746,4 +750,9 @@
     enum kSortOrderEnum { kSortOrder_None, kSortOrder_Name, kSortOrder_Id };
     kSortOrderEnum enmSortOrder = kSortOrder_None;
+
+    if (a->pcszSpec != NULL)
+        return RTMsgErrorExit(RTEXITCODE_SYNTAX,
+                   "cloud machine list: unexpected machine argument");
+
 
     RTGETOPTSTATE OptState;
@@ -784,5 +793,5 @@
 
     com::SafeIfaceArray<ICloudMachine> aMachines;
-    hrc = getMachineList(aMachines, pClient);
+    hrc = getMachineList(aMachines, a->pClient);
     if (FAILED(hrc))
         return RTEXITCODE_FAILURE;
@@ -875,12 +884,10 @@
                       const char *pcszProfileName)
 {
-    int rc;
-
-    ComPtr<ICloudClient> pClient;
-    rc = getCloudClient(pClient, a, pcszProviderName, pcszProfileName);
+    CMachineHandlerArg handlerArg(*a);
+    int rc = getCloudClient(handlerArg, pcszProviderName, pcszProfileName);
     if (RT_FAILURE(rc))
         return RTEXITCODE_FAILURE;
 
-    return handleCloudMachineInfo(a, iFirst, pClient);
+    return handleCloudMachineInfo(&handlerArg, iFirst);
 }
 
@@ -890,9 +897,6 @@
  */
 static RTEXITCODE
-handleCloudMachineInfo(HandlerArg *a, int iFirst,
-                       const ComPtr<ICloudClient> &pClient)
-{
-    MachineSpec machineSpec;
-    ComPtr<ICloudMachine> pMachine;
+handleCloudMachineInfo(CMachineHandlerArg *a, int iFirst)
+{
     HRESULT hrc;
     int rc;
@@ -923,5 +927,5 @@
     while ((ch = RTGetOpt(&OptState, &Val)) != 0)
     {
-        rc = checkMachineSpecArgument(machineSpec, ch, Val);
+        rc = checkMachineSpecArgument(a, ch, Val);
         if (rc == VINF_SUCCESS)
             continue;
@@ -942,5 +946,5 @@
     }
 
-    hrc = getMachineBySpec(pMachine, pClient, machineSpec);
+    hrc = getMachineBySpec(a);
     if (FAILED(hrc))
         return RTEXITCODE_FAILURE;
@@ -949,5 +953,5 @@
 
 
-    hrc = printMachineInfo(pMachine);
+    hrc = printMachineInfo(a->pMachine);
     if (FAILED(hrc))
         return RTEXITCODE_FAILURE;
@@ -1193,15 +1197,9 @@
  */
 static RTEXITCODE
-getMachineFromArgs(ComPtr<ICloudMachine> &pMachine,
-                   uint64_t fCurSubcommandScope,
-                   HandlerArg *a, int iFirst,
-                   const ComPtr<ICloudClient> &pClient)
-{
-    MachineSpec machineSpec;
+getMachineFromArgs(CMachineHandlerArg *a, int iFirst)
+{
     HRESULT hrc;
     int rc;
 
-    RT_NOREF(fCurSubcommandScope); /// @todo scopes not in the manual yet
-    // setCurrentSubcommand(fCurSubcommandScope);
     static const RTGETOPTDEF s_aOptions[] =
     {
@@ -1222,5 +1220,5 @@
     while ((ch = RTGetOpt(&OptState, &Val)) != 0)
     {
-        rc = checkMachineSpecArgument(machineSpec, ch, Val);
+        rc = checkMachineSpecArgument(a, ch, Val);
         if (rc == VINF_SUCCESS)
             continue;
@@ -1238,5 +1236,5 @@
     }
 
-    hrc = getMachineBySpec(pMachine, pClient, machineSpec);
+    hrc = getMachineBySpec(a);
     if (FAILED(hrc))
         return RTEXITCODE_FAILURE;
@@ -1250,14 +1248,10 @@
  */
 static RTEXITCODE
-handleCloudMachineStart(HandlerArg *a, int iFirst,
-                        const ComPtr<ICloudClient> &pClient)
-{
-    ComPtr<ICloudMachine> pMachine;
-    HRESULT hrc;
-
-    RTEXITCODE status
-        = getMachineFromArgs(pMachine,
-              /* HELP_SCOPE_CLOUD_MACHINE_START */ 0,
-              a, iFirst, pClient);
+handleCloudMachineStart(CMachineHandlerArg *a, int iFirst)
+{
+    HRESULT hrc;
+
+    // setCurrentSubcommand(HELP_SCOPE_CLOUD_MACHINE_START);
+    RTEXITCODE status = getMachineFromArgs(a, iFirst);
     if (status != RTEXITCODE_SUCCESS)
         return status;
@@ -1265,5 +1259,5 @@
 
     ComPtr<IProgress> pProgress;
-    CHECK_ERROR2_RET(hrc, pMachine,
+    CHECK_ERROR2_RET(hrc, a->pMachine,
         PowerUp(pProgress.asOutParam()),
             RTEXITCODE_FAILURE);
@@ -1279,14 +1273,10 @@
  */
 static RTEXITCODE
-handleCloudMachineReboot(HandlerArg *a, int iFirst,
-                         const ComPtr<ICloudClient> &pClient)
-{
-    ComPtr<ICloudMachine> pMachine;
-    HRESULT hrc;
-
-    RTEXITCODE status
-        = getMachineFromArgs(pMachine,
-              /* HELP_SCOPE_CLOUD_MACHINE_REBOOT */ 0,
-              a, iFirst, pClient);
+handleCloudMachineReboot(CMachineHandlerArg *a, int iFirst)
+{
+    HRESULT hrc;
+
+    // setCurrentSubcommand(HELP_SCOPE_CLOUD_MACHINE_REBOOT);
+    RTEXITCODE status = getMachineFromArgs(a, iFirst);
     if (status != RTEXITCODE_SUCCESS)
         return status;
@@ -1294,5 +1284,5 @@
 
     ComPtr<IProgress> pProgress;
-    CHECK_ERROR2_RET(hrc, pMachine,
+    CHECK_ERROR2_RET(hrc, a->pMachine,
         Reboot(pProgress.asOutParam()),
             RTEXITCODE_FAILURE);
@@ -1308,14 +1298,10 @@
  */
 static RTEXITCODE
-handleCloudMachineShutdown(HandlerArg *a, int iFirst,
-                           const ComPtr<ICloudClient> &pClient)
-{
-    ComPtr<ICloudMachine> pMachine;
-    HRESULT hrc;
-
-    RTEXITCODE status
-        = getMachineFromArgs(pMachine,
-              /* HELP_SCOPE_CLOUD_MACHINE_SHUTDOWN */ 0,
-              a, iFirst, pClient);
+handleCloudMachineShutdown(CMachineHandlerArg *a, int iFirst)
+{
+    HRESULT hrc;
+
+    // setCurrentSubcommand(HELP_SCOPE_CLOUD_MACHINE_SHUTDOWN);
+    RTEXITCODE status = getMachineFromArgs(a, iFirst);
     if (status != RTEXITCODE_SUCCESS)
         return status;
@@ -1323,5 +1309,5 @@
 
     ComPtr<IProgress> pProgress;
-    CHECK_ERROR2_RET(hrc, pMachine,
+    CHECK_ERROR2_RET(hrc, a->pMachine,
         Shutdown(pProgress.asOutParam()),
             RTEXITCODE_FAILURE);
@@ -1337,14 +1323,10 @@
  */
 static RTEXITCODE
-handleCloudMachinePowerdown(HandlerArg *a, int iFirst,
-                            const ComPtr<ICloudClient> &pClient)
-{
-    ComPtr<ICloudMachine> pMachine;
-    HRESULT hrc;
-
-    RTEXITCODE status
-        = getMachineFromArgs(pMachine,
-              /* HELP_SCOPE_CLOUD_MACHINE_POWERDOWN */ 0,
-              a, iFirst, pClient);
+handleCloudMachinePowerdown(CMachineHandlerArg *a, int iFirst)
+{
+    HRESULT hrc;
+
+    // setCurrentSubcommand(HELP_SCOPE_CLOUD_MACHINE_POWERDOWN);
+    RTEXITCODE status = getMachineFromArgs(a, iFirst);
     if (status != RTEXITCODE_SUCCESS)
         return status;
@@ -1352,5 +1334,5 @@
 
     ComPtr<IProgress> pProgress;
-    CHECK_ERROR2_RET(hrc, pMachine,
+    CHECK_ERROR2_RET(hrc, a->pMachine,
         PowerDown(pProgress.asOutParam()),
             RTEXITCODE_FAILURE);
@@ -1366,14 +1348,10 @@
  */
 static RTEXITCODE
-handleCloudMachineTerminate(HandlerArg *a, int iFirst,
-                            const ComPtr<ICloudClient> &pClient)
-{
-    ComPtr<ICloudMachine> pMachine;
-    HRESULT hrc;
-
-    RTEXITCODE status
-        = getMachineFromArgs(pMachine,
-              /* HELP_SCOPE_CLOUD_MACHINE_TERMINATE */ 0,
-              a, iFirst, pClient);
+handleCloudMachineTerminate(CMachineHandlerArg *a, int iFirst)
+{
+    HRESULT hrc;
+
+    // setCurrentSubcommand(HELP_SCOPE_CLOUD_MACHINE_TERMINATE);
+    RTEXITCODE status = getMachineFromArgs(a, iFirst);
     if (status != RTEXITCODE_SUCCESS)
         return status;
@@ -1381,5 +1359,5 @@
 
     ComPtr<IProgress> pProgress;
-    CHECK_ERROR2_RET(hrc, pMachine,
+    CHECK_ERROR2_RET(hrc, a->pMachine,
         Terminate(pProgress.asOutParam()),
             RTEXITCODE_FAILURE);
@@ -1394,14 +1372,10 @@
  */
 static RTEXITCODE
-handleCloudMachineConsoleHistory(HandlerArg *a, int iFirst,
-                                 const ComPtr<ICloudClient> &pClient)
-{
-    ComPtr<ICloudMachine> pMachine;
-    HRESULT hrc;
-
-    RTEXITCODE status
-        = getMachineFromArgs(pMachine,
-              /* HELP_SCOPE_CLOUD_MACHINE_CONSOLEHISTORY */ 0,
-              a, iFirst, pClient);
+handleCloudMachineConsoleHistory(CMachineHandlerArg *a, int iFirst)
+{
+    HRESULT hrc;
+
+    // setCurrentSubcommand(HELP_SCOPE_CLOUD_MACHINE_CONSOLEHISTORY);
+    RTEXITCODE status = getMachineFromArgs(a, iFirst);
     if (status != RTEXITCODE_SUCCESS)
         return status;
@@ -1410,5 +1384,5 @@
     ComPtr<IDataStream> pHistoryStream;
     ComPtr<IProgress> pHistoryProgress;
-    CHECK_ERROR2_RET(hrc, pMachine,
+    CHECK_ERROR2_RET(hrc, a->pMachine,
         GetConsoleHistory(pHistoryStream.asOutParam(),
                           pHistoryProgress.asOutParam()),
