mirror of
https://github.com/gryf/boxpy.git
synced 2025-12-18 21:10:17 +01:00
Added --type switch for start command
This commit is contained in:
42
box.py
42
box.py
@@ -18,7 +18,7 @@ import requests
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
__version__ = "1.8"
|
__version__ = "1.9"
|
||||||
|
|
||||||
CACHE_DIR = os.environ.get('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
|
CACHE_DIR = os.environ.get('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
|
||||||
CLOUD_IMAGE = "ci.iso"
|
CLOUD_IMAGE = "ci.iso"
|
||||||
@@ -137,13 +137,37 @@ _boxpy() {
|
|||||||
if [[ ${prev} == ${cmd} ]]; then
|
if [[ ${prev} == ${cmd} ]]; then
|
||||||
COMPREPLY=( $(compgen -W "bash" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "bash" -- ${cur}) )
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
|
start)
|
||||||
|
items=(--type)
|
||||||
|
if [[ ${prev} == ${cmd} ]]; then
|
||||||
|
if [[ ${cmd} = "start" ]]; then
|
||||||
|
_vms_comp vms
|
||||||
|
else
|
||||||
|
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
_get_excluded_items "${items[@]}"
|
||||||
|
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
|
||||||
|
|
||||||
|
case "${prev}" in
|
||||||
|
--type)
|
||||||
|
COMPREPLY=( $(compgen -W "gui headless sdl separate" \
|
||||||
|
-- ${cur}) )
|
||||||
|
;;
|
||||||
|
--*)
|
||||||
|
COMPREPLY=( )
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
;;
|
;;
|
||||||
create|rebuild)
|
create|rebuild)
|
||||||
items=(--cpus --disable-nested --disk-size --default-user --distro
|
items=(--cpus --disable-nested --disk-size --default-user --distro
|
||||||
--forwarding --image --key --memory --hostname --port --config
|
--forwarding --image --key --memory --hostname --port --config
|
||||||
--version --type)
|
--version --type)
|
||||||
if [[ ${prev} == ${cmd} ]]; then
|
if [[ ${prev} == ${cmd} ]]; then
|
||||||
if [[ ${cmd} = "rebuild" ]]; then
|
if [[ ${cmd} = "rebuild" || ${cmd} == "start" ]]; then
|
||||||
_vms_comp vms
|
_vms_comp vms
|
||||||
else
|
else
|
||||||
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
|
||||||
@@ -195,11 +219,6 @@ _boxpy() {
|
|||||||
_vms_comp runningvms
|
_vms_comp runningvms
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
start)
|
|
||||||
if [[ ${prev} == ${cmd} ]]; then
|
|
||||||
_vms_comp vms
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
stop)
|
stop)
|
||||||
if [[ ${prev} == ${cmd} ]]; then
|
if [[ ${prev} == ${cmd} ]]; then
|
||||||
_vms_comp runningvms
|
_vms_comp runningvms
|
||||||
@@ -1583,7 +1602,7 @@ def connect(args):
|
|||||||
return Run(cmd, False).returncode
|
return Run(cmd, False).returncode
|
||||||
|
|
||||||
|
|
||||||
def _set_vmstate(name, state):
|
def _set_vmstate(name, state, guitype=None):
|
||||||
|
|
||||||
vbox = VBoxManage(name)
|
vbox = VBoxManage(name)
|
||||||
if not vbox.get_vm_info():
|
if not vbox.get_vm_info():
|
||||||
@@ -1599,13 +1618,13 @@ def _set_vmstate(name, state):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if state == "start":
|
if state == "start":
|
||||||
vbox.poweron()
|
vbox.poweron(guitype)
|
||||||
else:
|
else:
|
||||||
vbox.acpipowerbutton()
|
vbox.acpipowerbutton()
|
||||||
|
|
||||||
|
|
||||||
def vmstart(args):
|
def vmstart(args):
|
||||||
_set_vmstate(args.name, 'start')
|
_set_vmstate(args.name, 'start', args.type)
|
||||||
|
|
||||||
|
|
||||||
def vmstop(args):
|
def vmstop(args):
|
||||||
@@ -1720,6 +1739,9 @@ def main():
|
|||||||
|
|
||||||
start = subparsers.add_parser('start', help='start VM')
|
start = subparsers.add_parser('start', help='start VM')
|
||||||
start.add_argument('name', help='name or UUID of the VM')
|
start.add_argument('name', help='name or UUID of the VM')
|
||||||
|
start.add_argument('-t', '--type', default='headless',
|
||||||
|
help="VM run type, headless by default.",
|
||||||
|
choices=['gui', 'headless', 'sdl', 'separate'])
|
||||||
start.set_defaults(func=vmstart)
|
start.set_defaults(func=vmstart)
|
||||||
|
|
||||||
stop = subparsers.add_parser('stop', help='stop VM')
|
stop = subparsers.add_parser('stop', help='stop VM')
|
||||||
|
|||||||
Reference in New Issue
Block a user