-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (39 loc) · 1.03 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
package main
import (
"fmt"
"os"
"github.com/stilvoid/please/internal/cmd"
)
func printHelp() {
fmt.Println("Usage: please <COMMAND> [arg...]")
fmt.Println()
fmt.Println("Commands:")
fmt.Println(" identify Identify the structured data on stdin")
fmt.Println(" request Make a web request and output the result")
fmt.Println(" respond Listen for a web request and respond to it")
fmt.Println(" parse Get values from structured data and convert between formats")
fmt.Println(" serve Serve a folder as a web site")
fmt.Println()
fmt.Println("Run 'please COMMAND' for more information on a command.")
}
func main() {
if len(os.Args) < 2 {
printHelp()
os.Exit(1)
}
command := os.Args[1]
args := os.Args[1:]
// Deal with aliases
if alias, ok := cmd.Aliases[command]; ok {
newArgs := make([]string, 1, len(args)+1)
newArgs[0] = alias
args = append(newArgs, args...)
command = alias
}
commandFunc, ok := cmd.Commands[command]
if !ok {
printHelp()
os.Exit(1)
}
commandFunc(args)
}