This repository has been archived by the owner on Jun 3, 2022. It is now read-only.
forked from fyne-io/fyne
/
main.go
88 lines (73 loc) · 1.51 KB
/
main.go
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
// Run a command line helper for various Fyne tools.
package main
import (
"flag"
"fmt"
"os"
)
var commands map[string]command
var provider command
func printUsage() {
fmt.Println("Usage: fyne [command] [parameters], where command is one of:")
fmt.Print(" ")
i := 0
for id := range commands {
fmt.Print(id)
if i < len(commands)-1 {
fmt.Print(", ")
}
i++
}
fmt.Println(" or help")
fmt.Println()
if provider != nil {
provider.printHelp(" ")
} else {
for id, provider := range commands {
fmt.Printf(" %s\n", id)
provider.printHelp(" ")
fmt.Printf(" For more information run \"fyne help %s\"\n", id)
fmt.Println("")
}
}
flag.PrintDefaults()
}
func help() {
printUsage()
os.Exit(2) // consistent with flag.Parse() with -help
}
func loadCommands() {
commands = make(map[string]command)
commands["bundle"] = &bundler{}
commands["package"] = &packager{}
}
func main() {
loadCommands()
flag.Usage = printUsage
// first let's extract the first "command"
args := os.Args[1:]
if len(args) < 1 {
help()
}
command := args[0]
if command[0] == '-' { // there was a parameter instead of a command
help()
}
if command == "help" {
if len(args) >= 2 {
provider = commands[args[1]]
provider.addFlags()
}
help()
} else {
provider = commands[command]
if provider == nil {
fmt.Fprintln(os.Stderr, "Unsupported command", command)
return
}
provider.addFlags()
// then parse the remaining args
flag.CommandLine.Parse(args[1:])
provider.run(flag.Args())
}
}