[libvirt] [PATCH 2/4] virsh: Extend virsh commands definition with completer

Michal Privoznik mprivozn at redhat.com
Mon Jul 4 08:41:26 UTC 2011


This commit introduces command-based completer. Any command can now have
a completer, which will generate additional command arguments. Completer
is called repeatedly until it returns NULL. On the first call, @state is
non-zero.
---
 tools/virsh.c |  364 ++++++++++++++++++++++++++++++---------------------------
 1 files changed, 193 insertions(+), 171 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index eeacec3..3dabb10 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -202,6 +202,7 @@ typedef struct {
     const vshCmdOptDef *opts;   /* definition of command options */
     const vshCmdInfo *info;     /* details about command */
     int flags;                  /* bitwise OR of VSH_CMD_FLAG */
+    char * (*completer) (const char *, int);    /* command completer */
 } vshCmdDef;
 
 /*
@@ -11614,272 +11615,285 @@ cleanup:
 
 static const vshCmdDef domManagementCmds[] = {
     {"attach-device", cmdAttachDevice, opts_attach_device,
-     info_attach_device, 0},
+     info_attach_device, 0, NULL},
     {"attach-disk", cmdAttachDisk, opts_attach_disk,
-     info_attach_disk, 0},
+     info_attach_disk, 0, NULL},
     {"attach-interface", cmdAttachInterface, opts_attach_interface,
-     info_attach_interface, 0},
-    {"autostart", cmdAutostart, opts_autostart, info_autostart, 0},
-    {"blkiotune", cmdBlkiotune, opts_blkiotune, info_blkiotune, 0},
+     info_attach_interface, 0, NULL},
+    {"autostart", cmdAutostart, opts_autostart, info_autostart, 0, NULL},
+    {"blkiotune", cmdBlkiotune, opts_blkiotune, info_blkiotune, 0, NULL},
 #ifndef WIN32
-    {"console", cmdConsole, opts_console, info_console, 0},
+    {"console", cmdConsole, opts_console, info_console, 0, NULL},
 #endif
-    {"cpu-baseline", cmdCPUBaseline, opts_cpu_baseline, info_cpu_baseline, 0},
-    {"cpu-compare", cmdCPUCompare, opts_cpu_compare, info_cpu_compare, 0},
-    {"create", cmdCreate, opts_create, info_create, 0},
-    {"define", cmdDefine, opts_define, info_define, 0},
-    {"destroy", cmdDestroy, opts_destroy, info_destroy, 0},
+    {"cpu-baseline", cmdCPUBaseline, opts_cpu_baseline,
+     info_cpu_baseline, 0, NULL},
+    {"cpu-compare", cmdCPUCompare, opts_cpu_compare, info_cpu_compare, 0, NULL},
+    {"create", cmdCreate, opts_create, info_create, 0, NULL},
+    {"define", cmdDefine, opts_define, info_define, 0, NULL},
+    {"destroy", cmdDestroy, opts_destroy, info_destroy, 0, NULL},
     {"detach-device", cmdDetachDevice, opts_detach_device,
-     info_detach_device, 0},
-    {"detach-disk", cmdDetachDisk, opts_detach_disk, info_detach_disk, 0},
+     info_detach_device, 0, NULL},
+    {"detach-disk", cmdDetachDisk, opts_detach_disk, info_detach_disk, 0, NULL},
     {"detach-interface", cmdDetachInterface, opts_detach_interface,
-     info_detach_interface, 0},
-    {"domid", cmdDomid, opts_domid, info_domid, 0},
-    {"domjobabort", cmdDomjobabort, opts_domjobabort, info_domjobabort, 0},
-    {"domjobinfo", cmdDomjobinfo, opts_domjobinfo, info_domjobinfo, 0},
-    {"domname", cmdDomname, opts_domname, info_domname, 0},
-    {"domuuid", cmdDomuuid, opts_domuuid, info_domuuid, 0},
+     info_detach_interface, 0, NULL},
+    {"domid", cmdDomid, opts_domid, info_domid, 0, NULL},
+    {"domjobabort", cmdDomjobabort, opts_domjobabort,
+     info_domjobabort, 0, NULL},
+    {"domjobinfo", cmdDomjobinfo, opts_domjobinfo, info_domjobinfo, 0, NULL},
+    {"domname", cmdDomname, opts_domname, info_domname, 0, NULL},
+    {"domuuid", cmdDomuuid, opts_domuuid, info_domuuid, 0, NULL},
     {"domxml-from-native", cmdDomXMLFromNative, opts_domxmlfromnative,
-     info_domxmlfromnative, 0},
+     info_domxmlfromnative, 0, NULL},
     {"domxml-to-native", cmdDomXMLToNative, opts_domxmltonative,
-     info_domxmltonative, 0},
-    {"dump", cmdDump, opts_dump, info_dump, 0},
-    {"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml, 0},
-    {"edit", cmdEdit, opts_edit, info_edit, 0},
-    {"inject-nmi", cmdInjectNMI, opts_inject_nmi, info_inject_nmi, 0},
-    {"managedsave", cmdManagedSave, opts_managedsave, info_managedsave, 0},
+     info_domxmltonative, 0, NULL},
+    {"dump", cmdDump, opts_dump, info_dump, 0, NULL},
+    {"dumpxml", cmdDumpXML, opts_dumpxml, info_dumpxml, 0, NULL},
+    {"edit", cmdEdit, opts_edit, info_edit, 0, NULL},
+    {"inject-nmi", cmdInjectNMI, opts_inject_nmi, info_inject_nmi, 0, NULL},
+    {"managedsave", cmdManagedSave, opts_managedsave,
+     info_managedsave, 0, NULL},
     {"managedsave-remove", cmdManagedSaveRemove, opts_managedsaveremove,
-     info_managedsaveremove, 0},
-    {"maxvcpus", cmdMaxvcpus, opts_maxvcpus, info_maxvcpus, 0},
-    {"memtune", cmdMemtune, opts_memtune, info_memtune, 0},
-    {"migrate", cmdMigrate, opts_migrate, info_migrate, 0},
+     info_managedsaveremove, 0, NULL},
+    {"maxvcpus", cmdMaxvcpus, opts_maxvcpus, info_maxvcpus, 0, NULL},
+    {"memtune", cmdMemtune, opts_memtune, info_memtune, 0, NULL},
+    {"migrate", cmdMigrate, opts_migrate, info_migrate, 0, NULL},
     {"migrate-setmaxdowntime", cmdMigrateSetMaxDowntime,
-     opts_migrate_setmaxdowntime, info_migrate_setmaxdowntime, 0},
+     opts_migrate_setmaxdowntime, info_migrate_setmaxdowntime, 0, NULL},
     {"migrate-setspeed", cmdMigrateSetMaxSpeed,
-     opts_migrate_setspeed, info_migrate_setspeed, 0},
-    {"reboot", cmdReboot, opts_reboot, info_reboot, 0},
-    {"restore", cmdRestore, opts_restore, info_restore, 0},
-    {"resume", cmdResume, opts_resume, info_resume, 0},
-    {"save", cmdSave, opts_save, info_save, 0},
-    {"schedinfo", cmdSchedinfo, opts_schedinfo, info_schedinfo, 0},
-    {"screenshot", cmdScreenshot, opts_screenshot, info_screenshot, 0},
-    {"setmaxmem", cmdSetmaxmem, opts_setmaxmem, info_setmaxmem, 0},
-    {"setmem", cmdSetmem, opts_setmem, info_setmem, 0},
-    {"setvcpus", cmdSetvcpus, opts_setvcpus, info_setvcpus, 0},
-    {"shutdown", cmdShutdown, opts_shutdown, info_shutdown, 0},
-    {"start", cmdStart, opts_start, info_start, 0},
-    {"suspend", cmdSuspend, opts_suspend, info_suspend, 0},
-    {"ttyconsole", cmdTTYConsole, opts_ttyconsole, info_ttyconsole, 0},
-    {"undefine", cmdUndefine, opts_undefine, info_undefine, 0},
+     opts_migrate_setspeed, info_migrate_setspeed, 0, NULL},
+    {"reboot", cmdReboot, opts_reboot, info_reboot, 0, NULL},
+    {"restore", cmdRestore, opts_restore, info_restore, 0, NULL},
+    {"resume", cmdResume, opts_resume, info_resume, 0, NULL},
+    {"save", cmdSave, opts_save, info_save, 0, NULL},
+    {"schedinfo", cmdSchedinfo, opts_schedinfo, info_schedinfo, 0, NULL},
+    {"screenshot", cmdScreenshot, opts_screenshot, info_screenshot, 0, NULL},
+    {"setmaxmem", cmdSetmaxmem, opts_setmaxmem, info_setmaxmem, 0, NULL},
+    {"setmem", cmdSetmem, opts_setmem, info_setmem, 0, NULL},
+    {"setvcpus", cmdSetvcpus, opts_setvcpus, info_setvcpus, 0, NULL},
+    {"shutdown", cmdShutdown, opts_shutdown, info_shutdown, 0, NULL},
+    {"start", cmdStart, opts_start, info_start, 0, NULL},
+    {"suspend", cmdSuspend, opts_suspend, info_suspend, 0, NULL},
+    {"ttyconsole", cmdTTYConsole, opts_ttyconsole, info_ttyconsole, 0, NULL},
+    {"undefine", cmdUndefine, opts_undefine, info_undefine, 0, NULL},
     {"update-device", cmdUpdateDevice, opts_update_device,
-     info_update_device, 0},
-    {"vcpucount", cmdVcpucount, opts_vcpucount, info_vcpucount, 0},
-    {"vcpuinfo", cmdVcpuinfo, opts_vcpuinfo, info_vcpuinfo, 0},
-    {"vcpupin", cmdVcpuPin, opts_vcpupin, info_vcpupin, 0},
-    {"version", cmdVersion, opts_version, info_version, 0},
-    {"vncdisplay", cmdVNCDisplay, opts_vncdisplay, info_vncdisplay, 0},
-    {NULL, NULL, NULL, NULL, 0}
+     info_update_device, 0, NULL},
+    {"vcpucount", cmdVcpucount, opts_vcpucount, info_vcpucount, 0, NULL},
+    {"vcpuinfo", cmdVcpuinfo, opts_vcpuinfo, info_vcpuinfo, 0, NULL},
+    {"vcpupin", cmdVcpuPin, opts_vcpupin, info_vcpupin, 0, NULL},
+    {"version", cmdVersion, opts_version, info_version, 0, NULL},
+    {"vncdisplay", cmdVNCDisplay, opts_vncdisplay, info_vncdisplay, 0, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdDef domMonitoringCmds[] = {
-    {"domblkinfo", cmdDomblkinfo, opts_domblkinfo, info_domblkinfo, 0},
-    {"domblkstat", cmdDomblkstat, opts_domblkstat, info_domblkstat, 0},
-    {"domcontrol", cmdDomControl, opts_domcontrol, info_domcontrol, 0},
-    {"domifstat", cmdDomIfstat, opts_domifstat, info_domifstat, 0},
-    {"dominfo", cmdDominfo, opts_dominfo, info_dominfo, 0},
-    {"dommemstat", cmdDomMemStat, opts_dommemstat, info_dommemstat, 0},
-    {"domstate", cmdDomstate, opts_domstate, info_domstate, 0},
-    {"list", cmdList, opts_list, info_list, 0},
-    {NULL, NULL, NULL, NULL, 0}
+    {"domblkinfo", cmdDomblkinfo, opts_domblkinfo, info_domblkinfo, 0, NULL},
+    {"domblkstat", cmdDomblkstat, opts_domblkstat, info_domblkstat, 0, NULL},
+    {"domcontrol", cmdDomControl, opts_domcontrol, info_domcontrol, 0, NULL},
+    {"domifstat", cmdDomIfstat, opts_domifstat, info_domifstat, 0, NULL},
+    {"dominfo", cmdDominfo, opts_dominfo, info_dominfo, 0, NULL},
+    {"dommemstat", cmdDomMemStat, opts_dommemstat, info_dommemstat, 0, NULL},
+    {"domstate", cmdDomstate, opts_domstate, info_domstate, 0, NULL},
+    {"list", cmdList, opts_list, info_list, 0, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdDef storagePoolCmds[] = {
     {"find-storage-pool-sources-as", cmdPoolDiscoverSourcesAs,
-     opts_find_storage_pool_sources_as, info_find_storage_pool_sources_as, 0},
+     opts_find_storage_pool_sources_as,
+     info_find_storage_pool_sources_as, 0, NULL},
     {"find-storage-pool-sources", cmdPoolDiscoverSources,
-     opts_find_storage_pool_sources, info_find_storage_pool_sources, 0},
+     opts_find_storage_pool_sources, info_find_storage_pool_sources, 0, NULL},
     {"pool-autostart", cmdPoolAutostart, opts_pool_autostart,
-     info_pool_autostart, 0},
-    {"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build, 0},
-    {"pool-create-as", cmdPoolCreateAs, opts_pool_X_as, info_pool_create_as, 0},
-    {"pool-create", cmdPoolCreate, opts_pool_create, info_pool_create, 0},
-    {"pool-define-as", cmdPoolDefineAs, opts_pool_X_as, info_pool_define_as, 0},
-    {"pool-define", cmdPoolDefine, opts_pool_define, info_pool_define, 0},
-    {"pool-delete", cmdPoolDelete, opts_pool_delete, info_pool_delete, 0},
-    {"pool-destroy", cmdPoolDestroy, opts_pool_destroy, info_pool_destroy, 0},
-    {"pool-dumpxml", cmdPoolDumpXML, opts_pool_dumpxml, info_pool_dumpxml, 0},
-    {"pool-edit", cmdPoolEdit, opts_pool_edit, info_pool_edit, 0},
-    {"pool-info", cmdPoolInfo, opts_pool_info, info_pool_info, 0},
-    {"pool-list", cmdPoolList, opts_pool_list, info_pool_list, 0},
-    {"pool-name", cmdPoolName, opts_pool_name, info_pool_name, 0},
-    {"pool-refresh", cmdPoolRefresh, opts_pool_refresh, info_pool_refresh, 0},
-    {"pool-start", cmdPoolStart, opts_pool_start, info_pool_start, 0},
+     info_pool_autostart, 0, NULL},
+    {"pool-build", cmdPoolBuild, opts_pool_build, info_pool_build, 0, NULL},
+    {"pool-create-as", cmdPoolCreateAs, opts_pool_X_as,
+     info_pool_create_as, 0, NULL},
+    {"pool-create", cmdPoolCreate, opts_pool_create, info_pool_create, 0, NULL},
+    {"pool-define-as", cmdPoolDefineAs, opts_pool_X_as,
+     info_pool_define_as, 0, NULL},
+    {"pool-define", cmdPoolDefine, opts_pool_define, info_pool_define, 0, NULL},
+    {"pool-delete", cmdPoolDelete, opts_pool_delete, info_pool_delete, 0, NULL},
+    {"pool-destroy", cmdPoolDestroy, opts_pool_destroy,
+     info_pool_destroy, 0, NULL},
+    {"pool-dumpxml", cmdPoolDumpXML, opts_pool_dumpxml,
+     info_pool_dumpxml, 0, NULL},
+    {"pool-edit", cmdPoolEdit, opts_pool_edit, info_pool_edit, 0, NULL},
+    {"pool-info", cmdPoolInfo, opts_pool_info, info_pool_info, 0, NULL},
+    {"pool-list", cmdPoolList, opts_pool_list, info_pool_list, 0, NULL},
+    {"pool-name", cmdPoolName, opts_pool_name, info_pool_name, 0, NULL},
+    {"pool-refresh", cmdPoolRefresh, opts_pool_refresh,
+     info_pool_refresh, 0, NULL},
+    {"pool-start", cmdPoolStart, opts_pool_start, info_pool_start, 0, NULL},
     {"pool-undefine", cmdPoolUndefine, opts_pool_undefine,
-     info_pool_undefine, 0},
-    {"pool-uuid", cmdPoolUuid, opts_pool_uuid, info_pool_uuid, 0},
-    {NULL, NULL, NULL, NULL, 0}
+     info_pool_undefine, 0, NULL},
+    {"pool-uuid", cmdPoolUuid, opts_pool_uuid, info_pool_uuid, 0, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdDef storageVolCmds[] = {
-    {"vol-clone", cmdVolClone, opts_vol_clone, info_vol_clone, 0},
+    {"vol-clone", cmdVolClone, opts_vol_clone, info_vol_clone, 0, NULL},
     {"vol-create-as", cmdVolCreateAs, opts_vol_create_as,
-     info_vol_create_as, 0},
-    {"vol-create", cmdVolCreate, opts_vol_create, info_vol_create, 0},
+     info_vol_create_as, 0, NULL},
+    {"vol-create", cmdVolCreate, opts_vol_create, info_vol_create, 0, NULL},
     {"vol-create-from", cmdVolCreateFrom, opts_vol_create_from,
-     info_vol_create_from, 0},
-    {"vol-delete", cmdVolDelete, opts_vol_delete, info_vol_delete, 0},
-    {"vol-download", cmdVolDownload, opts_vol_download, info_vol_download, 0},
-    {"vol-dumpxml", cmdVolDumpXML, opts_vol_dumpxml, info_vol_dumpxml, 0},
-    {"vol-info", cmdVolInfo, opts_vol_info, info_vol_info, 0},
-    {"vol-key", cmdVolKey, opts_vol_key, info_vol_key, 0},
-    {"vol-list", cmdVolList, opts_vol_list, info_vol_list, 0},
-    {"vol-name", cmdVolName, opts_vol_name, info_vol_name, 0},
-    {"vol-path", cmdVolPath, opts_vol_path, info_vol_path, 0},
-    {"vol-pool", cmdVolPool, opts_vol_pool, info_vol_pool, 0},
-    {"vol-upload", cmdVolUpload, opts_vol_upload, info_vol_upload, 0},
-    {"vol-wipe", cmdVolWipe, opts_vol_wipe, info_vol_wipe, 0},
-    {NULL, NULL, NULL, NULL, 0}
+     info_vol_create_from, 0, NULL},
+    {"vol-delete", cmdVolDelete, opts_vol_delete, info_vol_delete, 0, NULL},
+    {"vol-download", cmdVolDownload, opts_vol_download,
+     info_vol_download, 0, NULL},
+    {"vol-dumpxml", cmdVolDumpXML, opts_vol_dumpxml, info_vol_dumpxml, 0, NULL},
+    {"vol-info", cmdVolInfo, opts_vol_info, info_vol_info, 0, NULL},
+    {"vol-key", cmdVolKey, opts_vol_key, info_vol_key, 0, NULL},
+    {"vol-list", cmdVolList, opts_vol_list, info_vol_list, 0, NULL},
+    {"vol-name", cmdVolName, opts_vol_name, info_vol_name, 0, NULL},
+    {"vol-path", cmdVolPath, opts_vol_path, info_vol_path, 0, NULL},
+    {"vol-pool", cmdVolPool, opts_vol_pool, info_vol_pool, 0, NULL},
+    {"vol-upload", cmdVolUpload, opts_vol_upload, info_vol_upload, 0, NULL},
+    {"vol-wipe", cmdVolWipe, opts_vol_wipe, info_vol_wipe, 0, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdDef networkCmds[] = {
     {"net-autostart", cmdNetworkAutostart, opts_network_autostart,
-     info_network_autostart, 0},
+     info_network_autostart, 0, NULL},
     {"net-create", cmdNetworkCreate, opts_network_create,
-     info_network_create, 0},
+     info_network_create, 0, NULL},
     {"net-define", cmdNetworkDefine, opts_network_define,
-     info_network_define, 0},
+     info_network_define, 0, NULL},
     {"net-destroy", cmdNetworkDestroy, opts_network_destroy,
-     info_network_destroy, 0},
+     info_network_destroy, 0, NULL},
     {"net-dumpxml", cmdNetworkDumpXML, opts_network_dumpxml,
-     info_network_dumpxml, 0},
-    {"net-edit", cmdNetworkEdit, opts_network_edit, info_network_edit, 0},
-    {"net-info", cmdNetworkInfo, opts_network_info, info_network_info, 0},
-    {"net-list", cmdNetworkList, opts_network_list, info_network_list, 0},
-    {"net-name", cmdNetworkName, opts_network_name, info_network_name, 0},
-    {"net-start", cmdNetworkStart, opts_network_start, info_network_start, 0},
+     info_network_dumpxml, 0, NULL},
+    {"net-edit", cmdNetworkEdit, opts_network_edit, info_network_edit, 0, NULL},
+    {"net-info", cmdNetworkInfo, opts_network_info, info_network_info, 0, NULL},
+    {"net-list", cmdNetworkList, opts_network_list, info_network_list, 0, NULL},
+    {"net-name", cmdNetworkName, opts_network_name, info_network_name, 0, NULL},
+    {"net-start", cmdNetworkStart, opts_network_start,
+     info_network_start, 0, NULL},
     {"net-undefine", cmdNetworkUndefine, opts_network_undefine,
-     info_network_undefine, 0},
-    {"net-uuid", cmdNetworkUuid, opts_network_uuid, info_network_uuid, 0},
-    {NULL, NULL, NULL, NULL, 0}
+     info_network_undefine, 0, NULL},
+    {"net-uuid", cmdNetworkUuid, opts_network_uuid, info_network_uuid, 0, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdDef nodedevCmds[] = {
     {"nodedev-create", cmdNodeDeviceCreate, opts_node_device_create,
-     info_node_device_create, 0},
+     info_node_device_create, 0, NULL},
     {"nodedev-destroy", cmdNodeDeviceDestroy, opts_node_device_destroy,
-     info_node_device_destroy, 0},
+     info_node_device_destroy, 0, NULL},
     {"nodedev-dettach", cmdNodeDeviceDettach, opts_node_device_dettach,
-     info_node_device_dettach, 0},
+     info_node_device_dettach, 0, NULL},
     {"nodedev-dumpxml", cmdNodeDeviceDumpXML, opts_node_device_dumpxml,
-     info_node_device_dumpxml, 0},
+     info_node_device_dumpxml, 0, NULL},
     {"nodedev-list", cmdNodeListDevices, opts_node_list_devices,
-     info_node_list_devices, 0},
+     info_node_list_devices, 0, NULL},
     {"nodedev-reattach", cmdNodeDeviceReAttach, opts_node_device_reattach,
-     info_node_device_reattach, 0},
+     info_node_device_reattach, 0, NULL},
     {"nodedev-reset", cmdNodeDeviceReset, opts_node_device_reset,
-     info_node_device_reset, 0},
-    {NULL, NULL, NULL, NULL, 0}
+     info_node_device_reset, 0, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdDef ifaceCmds[] = {
     {"iface-begin", cmdInterfaceBegin, opts_interface_begin,
-     info_interface_begin, 0},
+     info_interface_begin, 0, NULL},
     {"iface-commit", cmdInterfaceCommit, opts_interface_commit,
-     info_interface_commit, 0},
+     info_interface_commit, 0, NULL},
     {"iface-define", cmdInterfaceDefine, opts_interface_define,
-     info_interface_define, 0},
+     info_interface_define, 0, NULL},
     {"iface-destroy", cmdInterfaceDestroy, opts_interface_destroy,
-     info_interface_destroy, 0},
+     info_interface_destroy, 0, NULL},
     {"iface-dumpxml", cmdInterfaceDumpXML, opts_interface_dumpxml,
-     info_interface_dumpxml, 0},
+     info_interface_dumpxml, 0, NULL},
     {"iface-edit", cmdInterfaceEdit, opts_interface_edit,
-     info_interface_edit, 0},
+     info_interface_edit, 0, NULL},
     {"iface-list", cmdInterfaceList, opts_interface_list,
-     info_interface_list, 0},
+     info_interface_list, 0, NULL},
     {"iface-mac", cmdInterfaceMAC, opts_interface_mac,
-     info_interface_mac, 0},
+     info_interface_mac, 0, NULL},
     {"iface-name", cmdInterfaceName, opts_interface_name,
-     info_interface_name, 0},
+     info_interface_name, 0, NULL},
     {"iface-rollback", cmdInterfaceRollback, opts_interface_rollback,
-     info_interface_rollback, 0},
+     info_interface_rollback, 0, NULL},
     {"iface-start", cmdInterfaceStart, opts_interface_start,
-     info_interface_start, 0},
+     info_interface_start, 0, NULL},
     {"iface-undefine", cmdInterfaceUndefine, opts_interface_undefine,
-     info_interface_undefine, 0},
-    {NULL, NULL, NULL, NULL, 0}
+     info_interface_undefine, 0, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdDef nwfilterCmds[] = {
     {"nwfilter-define", cmdNWFilterDefine, opts_nwfilter_define,
-     info_nwfilter_define, 0},
+     info_nwfilter_define, 0, NULL},
     {"nwfilter-dumpxml", cmdNWFilterDumpXML, opts_nwfilter_dumpxml,
-     info_nwfilter_dumpxml, 0},
+     info_nwfilter_dumpxml, 0, NULL},
     {"nwfilter-edit", cmdNWFilterEdit, opts_nwfilter_edit,
-     info_nwfilter_edit, 0},
+     info_nwfilter_edit, 0, NULL},
     {"nwfilter-list", cmdNWFilterList, opts_nwfilter_list,
-     info_nwfilter_list, 0},
+     info_nwfilter_list, 0, NULL},
     {"nwfilter-undefine", cmdNWFilterUndefine, opts_nwfilter_undefine,
-     info_nwfilter_undefine, 0},
-    {NULL, NULL, NULL, NULL, 0}
+     info_nwfilter_undefine, 0, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdDef secretCmds[] = {
     {"secret-define", cmdSecretDefine, opts_secret_define,
-     info_secret_define, 0},
+     info_secret_define, 0, NULL},
     {"secret-dumpxml", cmdSecretDumpXML, opts_secret_dumpxml,
-     info_secret_dumpxml, 0},
+     info_secret_dumpxml, 0, NULL},
     {"secret-get-value", cmdSecretGetValue, opts_secret_get_value,
-     info_secret_get_value, 0},
-    {"secret-list", cmdSecretList, NULL, info_secret_list, 0},
+     info_secret_get_value, 0, NULL},
+    {"secret-list", cmdSecretList, NULL, info_secret_list, 0, NULL},
     {"secret-set-value", cmdSecretSetValue, opts_secret_set_value,
-     info_secret_set_value, 0},
+     info_secret_set_value, 0, NULL},
     {"secret-undefine", cmdSecretUndefine, opts_secret_undefine,
-     info_secret_undefine, 0},
-    {NULL, NULL, NULL, NULL, 0}
+     info_secret_undefine, 0, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdDef virshCmds[] = {
-    {"cd", cmdCd, opts_cd, info_cd, VSH_CMD_FLAG_NOCONNECT},
-    {"echo", cmdEcho, opts_echo, info_echo, VSH_CMD_FLAG_NOCONNECT},
-    {"exit", cmdQuit, NULL, info_quit, VSH_CMD_FLAG_NOCONNECT},
-    {"help", cmdHelp, opts_help, info_help, VSH_CMD_FLAG_NOCONNECT},
-    {"pwd", cmdPwd, NULL, info_pwd, VSH_CMD_FLAG_NOCONNECT},
-    {"quit", cmdQuit, NULL, info_quit, VSH_CMD_FLAG_NOCONNECT},
-    {NULL, NULL, NULL, NULL, 0}
+    {"cd", cmdCd, opts_cd, info_cd, VSH_CMD_FLAG_NOCONNECT, NULL},
+    {"echo", cmdEcho, opts_echo, info_echo, VSH_CMD_FLAG_NOCONNECT, NULL},
+    {"exit", cmdQuit, NULL, info_quit, VSH_CMD_FLAG_NOCONNECT, NULL},
+    {"help", cmdHelp, opts_help, info_help, VSH_CMD_FLAG_NOCONNECT, NULL},
+    {"pwd", cmdPwd, NULL, info_pwd, VSH_CMD_FLAG_NOCONNECT, NULL},
+    {"quit", cmdQuit, NULL, info_quit, VSH_CMD_FLAG_NOCONNECT, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdDef snapshotCmds[] = {
     {"snapshot-create", cmdSnapshotCreate, opts_snapshot_create,
-     info_snapshot_create, 0},
+     info_snapshot_create, 0, NULL},
     {"snapshot-create-as", cmdSnapshotCreateAs, opts_snapshot_create_as,
-     info_snapshot_create_as, 0},
+     info_snapshot_create_as, 0, NULL},
     {"snapshot-current", cmdSnapshotCurrent, opts_snapshot_current,
-     info_snapshot_current, 0},
+     info_snapshot_current, 0, NULL},
     {"snapshot-delete", cmdSnapshotDelete, opts_snapshot_delete,
-     info_snapshot_delete, 0},
+     info_snapshot_delete, 0, NULL},
     {"snapshot-dumpxml", cmdSnapshotDumpXML, opts_snapshot_dumpxml,
-     info_snapshot_dumpxml, 0},
+     info_snapshot_dumpxml, 0, NULL},
     {"snapshot-list", cmdSnapshotList, opts_snapshot_list,
-     info_snapshot_list, 0},
+     info_snapshot_list, 0, NULL},
     {"snapshot-revert", cmdDomainSnapshotRevert, opts_snapshot_revert,
-     info_snapshot_revert, 0},
-    {NULL, NULL, NULL, NULL, 0}
+     info_snapshot_revert, 0, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdDef hostAndHypervisorCmds[] = {
-    {"capabilities", cmdCapabilities, NULL, info_capabilities, 0},
+    {"capabilities", cmdCapabilities, NULL, info_capabilities, 0, NULL},
     {"connect", cmdConnect, opts_connect, info_connect,
-     VSH_CMD_FLAG_NOCONNECT},
-    {"freecell", cmdFreecell, opts_freecell, info_freecell, 0},
-    {"hostname", cmdHostname, NULL, info_hostname, 0},
-    {"nodecpustats", cmdNodeCpuStats, opts_node_cpustats, info_nodecpustats, 0},
-    {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0},
-    {"nodememstats", cmdNodeMemStats, opts_node_memstats, info_nodememstats, 0},
+     VSH_CMD_FLAG_NOCONNECT, NULL},
+    {"freecell", cmdFreecell, opts_freecell, info_freecell, 0, NULL},
+    {"hostname", cmdHostname, NULL, info_hostname, 0, NULL},
+    {"nodecpustats", cmdNodeCpuStats, opts_node_cpustats,
+     info_nodecpustats, 0, NULL},
+    {"nodeinfo", cmdNodeinfo, NULL, info_nodeinfo, 0, NULL},
+    {"nodememstats", cmdNodeMemStats, opts_node_memstats,
+     info_nodememstats, 0, NULL},
     {"qemu-monitor-command", cmdQemuMonitorCommand, opts_qemu_monitor_command,
-     info_qemu_monitor_command, 0},
-    {"sysinfo", cmdSysinfo, NULL, info_sysinfo, 0},
-    {"uri", cmdURI, NULL, info_uri, 0},
-    {NULL, NULL, NULL, NULL, 0}
+     info_qemu_monitor_command, 0, NULL},
+    {"sysinfo", cmdSysinfo, NULL, info_sysinfo, 0, NULL},
+    {"uri", cmdURI, NULL, info_uri, 0, NULL},
+    {NULL, NULL, NULL, NULL, 0, NULL}
 };
 
 static const vshCmdGrp cmdGroups[] = {
@@ -13598,6 +13612,7 @@ vshReadlineOptionsGenerator(const char *text, int state)
     static int list_index, len;
     static const vshCmdDef *cmd = NULL;
     const char *name;
+    static char *completer_ret = NULL;
 
     if (!state) {
         /* determine command name */
@@ -13614,11 +13629,18 @@ vshReadlineOptionsGenerator(const char *text, int state)
         list_index = 0;
         len = strlen(text);
         VIR_FREE(cmdname);
+        if (cmd && cmd->completer &&
+            ((completer_ret = cmd->completer(text, state)) != NULL))
+                return completer_ret;
     }
 
     if (!cmd)
         return NULL;
 
+    if (cmd->completer && completer_ret &&
+        ((completer_ret = cmd->completer(text, state)) != NULL))
+            return completer_ret;
+
     if (!cmd->opts)
         return NULL;
 
-- 
1.7.5.rc3




More information about the libvir-list mailing list