Changeset 65517 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Jan 30, 2017 12:50:05 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r65263 r65517 623 623 if (fCategory & USAGE_LIST) 624 624 RTStrmPrintf(pStrm, 625 "%s list [--long|-l] %s vms|runningvms|ostypes|hostdvds|hostfloppies|\n"625 "%s list [--long|-l] [--sorted|-s]%s vms|runningvms|ostypes|hostdvds|hostfloppies|\n" 626 626 #if defined(VBOX_WITH_NETFLT) 627 627 " intnets|bridgedifs|hostonlyifs|natnets|dhcpservers|\n" -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp
r64910 r65517 37 37 #include <iprt/getopt.h> 38 38 #include <iprt/ctype.h> 39 40 #include <vector> 41 #include <algorithm> 39 42 40 43 #include "VBoxManage.h" … … 925 928 * @param pVirtualBox Reference to the IVirtualBox smart pointer. 926 929 */ 927 static HRESULT produceList(enum enmListType enmCommand, bool fOptLong, const ComPtr<IVirtualBox> &pVirtualBox)930 static HRESULT produceList(enum enmListType enmCommand, bool fOptLong, bool fOptSorted, const ComPtr<IVirtualBox> &pVirtualBox) 928 931 { 929 932 HRESULT rc = S_OK; … … 944 947 { 945 948 /* 946 * Iterate through the collection949 * Display it. 947 950 */ 948 for (size_t i = 0; i < machines.size(); ++i)951 if (!fOptSorted) 949 952 { 950 if (machines[i]) 951 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT); 953 for (size_t i = 0; i < machines.size(); ++i) 954 if (machines[i]) 955 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT); 956 } 957 else 958 { 959 /* 960 * Sort the list by name before displaying it. 961 */ 962 std::vector<std::pair<com::Bstr, IMachine *>> sortedMachines; 963 for (size_t i = 0; i < machines.size(); ++i) 964 { 965 IMachine *pMachine = machines[i]; 966 if (pMachine) /* no idea why we need to do this... */ 967 { 968 Bstr bstrName; 969 pMachine->COMGETTER(Name)(bstrName.asOutParam()); 970 sortedMachines.push_back(std::pair<com::Bstr, IMachine *>(bstrName, pMachine)); 971 } 972 } 973 974 std::sort(sortedMachines.begin(), sortedMachines.end()); 975 976 for (size_t i = 0; i < sortedMachines.size(); ++i) 977 rc = showVMInfo(pVirtualBox, sortedMachines[i].second, NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT); 952 978 } 953 979 } … … 1273 1299 bool fOptLong = false; 1274 1300 bool fOptMultiple = false; 1301 bool fOptSorted = false; 1275 1302 enum enmListType enmOptCommand = kListNotSpecified; 1276 1303 … … 1279 1306 { "--long", 'l', RTGETOPT_REQ_NOTHING }, 1280 1307 { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */ 1308 { "--sorted", 's', RTGETOPT_REQ_NOTHING }, 1281 1309 { "vms", kListVMs, RTGETOPT_REQ_NOTHING }, 1282 1310 { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING }, … … 1321 1349 break; 1322 1350 1351 case 's': 1352 fOptSorted = true; 1353 break; 1354 1323 1355 case 'm': 1324 1356 fOptMultiple = true; … … 1356 1388 if (fOptMultiple) 1357 1389 { 1358 HRESULT hrc = produceList((enum enmListType)ch, fOptLong, a->virtualBox);1390 HRESULT hrc = produceList((enum enmListType)ch, fOptLong, fOptSorted, a->virtualBox); 1359 1391 if (FAILED(hrc)) 1360 1392 return RTEXITCODE_FAILURE; … … 1377 1409 if (!fOptMultiple) 1378 1410 { 1379 HRESULT hrc = produceList(enmOptCommand, fOptLong, a->virtualBox);1411 HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox); 1380 1412 if (FAILED(hrc)) 1381 1413 return RTEXITCODE_FAILURE;
Note:
See TracChangeset
for help on using the changeset viewer.