summaryrefslogtreecommitdiff
path: root/debugger.go
blob: 34ebbbbe95f9352babefbb073ae6b14a7cd4e055 (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
package prep

// initializes logging and command line options

import (
	"go.wit.com/dev/alexflint/arg"
	"go.wit.com/log"
)

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

var argDebugger ArgsDebugger

// This struct can be used with the go-arg package
type ArgsDebugger struct {
	Debugger bool `arg:"--debugger" help:"open the debugger window"`
	Logger   bool `arg:"--logger" help:"open the log.* control window"`
}

// returns true if --gui-debug was passed from the command line
func ArgDebug() bool {
	return argDebugger.Debugger
}

func ArgLogger() bool {
	return argDebugger.Logger
}

func Debugger() {
	arg.Register(&argDebugger)

	full := "go.wit.com/bug/debugger"
	short := "bugger"

	INFO = log.NewFlag("INFO", false, full, short, "simple debugging Info()")
	POLL = log.NewFlag("POLL", false, full, short, "watch the debugger poll things")
	CHAN = log.NewFlag("CHAN", true, full, short, "chan() test code output")
	WARN = log.NewFlag("WARN", true, full, short, "should warn the user")
}

// Versioned is the interface that the destination struct should implement to
// make a version string appear at the top of the help message.
type Appnamed interface {
	// Version returns the version string that will be printed on a line by itself
	// at the top of the help message.
	Appname() string
}

type AutoFuncd interface {
	// Version returns the version string that will be printed on a line by itself
	// at the top of the help message.
	DoAutoComplete(*Auto)
}

// Described is the interface that the destination struct should implement to
func newTest(tmp interface{}) {
	if tmp, ok := tmp.(Appnamed); ok {
		myAuto.appName = tmp.Appname()
	} else {
		panic("you need to make the function argv.Appname()")
	}

	if tmp, ok := tmp.(AutoFuncd); ok {
		myAuto.autoFunc = tmp.DoAutoComplete
	} else {
		panic("you need to make the function argv.DoAutoComplete()")
	}
}