summaryrefslogtreecommitdiff
path: root/argv.go
blob: 6f5af8f4922041fb1d125a6c703b9a4503e1bdc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main

import (
	"fmt"
	"os"

	"go.wit.com/log"
)

/*
	this parses the command line arguements

	this enables command line options from other packages like 'gui' and 'log'
*/

var argv args

type args struct {
	List      *ListCmd    `arg:"subcommand:list"                      help:"list things"`
	Droplet   *DropletCmd `arg:"subcommand:droplet"                   help:"send events to a droplet"`
	Config    string      `arg:"env:VIRTIGO_HOME"                     help:"defaults to ~/.config/virtigo/"`
	Server    string      `arg:"env:VIRTIGO_SERVER"                   help:"what virtigo cluster to connect to"`
	Localhost bool        `arg:"--localhost"                          help:"use the local libvirt"`
	Daemon    bool        `arg:"--daemon"                             help:"run as a daemon"`
	Verbose   bool        `arg:"--verbose"                            help:"talk more"`
	Port      int         `arg:"--port"     default:"8080"            help:"allow droplet events via http"`
	Xml       []string    `arg:"--libvirt"                            help:"import qemu xml files: --libvirt /etc/libvirt/qemu/*.xml"`
	Admin     bool        `arg:"--admin"                              help:"enter admin mode"`
	Bash      bool        `arg:"--bash"                               help:"generate bash completion"`
	BashAuto  []string    `arg:"--auto-complete"                      help:"todo: move this to go-arg"`
}

type EmptyCmd struct {
}

type testCmd string

type ListCmd struct {
	Droplets    *EmptyCmd `arg:"subcommand:droplets"              help:"list droplets"`
	Hypervisors *EmptyCmd `arg:"subcommand:hypervisors"           help:"list hypervisors"`
	On          bool      `arg:"--on"                             help:"only show things that are on"`
}

type DropletCmd struct {
	Start   *EmptyCmd `arg:"subcommand:start"                 help:"start droplet"`
	Stop    *EmptyCmd `arg:"subcommand:stop"                  help:"stop droplet"`
	Show    *EmptyCmd `arg:"subcommand:show"                  help:"show droplet"`
	Console *EmptyCmd `arg:"subcommand:console"               help:"open serial console"`
	VNC     *EmptyCmd `arg:"subcommand:vnc"                   help:"open VNC console"`
	Spice   *EmptyCmd `arg:"subcommand:spice"                 help:"open spiceconsole"`
	Name    string    `arg:"--name"                           help:"what droplet to start"`
}

func (a args) Description() string {
	return `
	virtigo: control your cluster

This maintains a master list of all your vm's (aka 'droplets')
in your homelab cloud.  You can import libvirt xml files. 
This app talks to your hypervisors via the virtigod daemon. 
`
}

func (args) Version() string {
	return ARGNAME + " " + VERSION + "    Built on " + BUILDTIME
}

var INFO *log.LogFlag
var POLL *log.LogFlag
var WARN *log.LogFlag
var EVENT *log.LogFlag

func init() {
	full := "go.wit.com/apps/virtigo"
	short := "virtigo"

	INFO = log.NewFlag("INFO", false, full, short, "general virtigo")
	POLL = log.NewFlag("POLL", false, full, short, "virtigo polling")
	WARN = log.NewFlag("WARN", true, full, short, "bad things")
	EVENT = log.NewFlag("EVENT", true, full, short, "hypeprvisor/droplet events")
}

/*
	handles shell autocomplete
*/

func (a args) DoAutoComplete(argv []string) {
	switch argv[0] {
	case "list":
		fmt.Println("droplets hypervisors")
	case "droplet":
		fmt.Println("start stop")
	case "devel":
		fmt.Println("--force")
	case "master":
		fmt.Println("")
	case "verify":
		fmt.Println("user devel master")
	default:
		if argv[0] == ARGNAME {
			// list the subcommands here
			fmt.Println("--bash list droplet")
		}
	}
	os.Exit(0)
}