summaryrefslogtreecommitdiff
path: root/interface.go
blob: 24f61c3db35f256a45dc9367af036e9615d34c0d (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
package prep

// this is a work in progress

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

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

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

type buildtimeI interface {
	Buildtime() (string, string)
}

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

type guiI interface {
	// Version returns the version string that will be printed on a line by itself
	// at the top of the help message.
	ArgvGui() error
}

type exitI interface {
	// allows a custom app Exit()
	Exit()
}

// Described is the interface that the destination struct should implement to
func findAppInfo(tmp interface{}) {
	if tmp, ok := tmp.(appnameI); ok {
		myAuto.ARGNAME = tmp.Appname()
	} else {
		panic("you must define in your app the function: (argv) func Appname() string")
	}

	if tmp, ok := tmp.(buildtimeI); ok {
		myAuto.buildtime = tmp.Buildtime
		myAuto.BUILDTIME, myAuto.VERSION = myAuto.buildtime()
	} else {
		// panic("your app is missing (argv) func Buildtime() (string, string)")
	}

	if tmp, ok := tmp.(examplesI); ok {
		myAuto.examples = tmp.Examples
	}

	if tmp, ok := tmp.(guiI); ok {
		myAuto.guiFunc = tmp.ArgvGui
	} else {
		// panic("you must add this function to argv.go: (argv) func ArgvGui() error")
	}

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

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

	if tmp, ok := tmp.(exitI); ok {
		myAuto.appExit = tmp.Exit
	} else {
		// panic("you need to make the function argv.Exit()")
	}
}