-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
80 lines (73 loc) · 1.72 KB
/
main.go
File metadata and controls
80 lines (73 loc) · 1.72 KB
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
// Go project by arthur
// glih
// 2018
package main
import (
"fmt"
"github.com/pborman/getopt/v2"
"glih/pkg/repository"
"glih/pkg/sshkey"
"glih/pkg/whoami"
"os"
)
const (
version = "1.0"
baseURL = "https://blih.epitech.eu/"
baseUserAgent = "blih-" + version
)
var (
V = getopt.BoolLong("version", 'V', "")
u, t string
U = baseUserAgent
b = baseURL
)
func usage() {
fmt.Printf("Usage: %s [options] command ...\n\n", os.Args[0])
fmt.Printf("Global Options: \n")
fmt.Printf("\t-u user\t| --user=user\t\t-- Run as user\n")
fmt.Printf("\t-b url\t| --baseurl=url\t\t-- Base URL for BLIH\n")
fmt.Printf("\t-t\t| --token\t\t-- Specify token in the cmdline\n")
fmt.Printf("\t-V\t| --version\t\t-- Print this binary's version then exit\n")
fmt.Printf("\t-U\t| --useragent=\t\t-- User-Agent for BLIH\n\n")
fmt.Printf("Commands:\n")
fmt.Printf("\trepository\t\t\t-- Repository management\n")
fmt.Printf("\tsshkey\t\t\t\t-- SSH-KEYS management\n")
fmt.Printf("\twhoami\t\t\t\t-- Print who you are\n")
}
func init() {
getopt.FlagLong(&u, "user", 'u', "")
getopt.FlagLong(&U, "useragent", 'U', "")
getopt.FlagLong(&b, "baseurl", 'b', "")
getopt.FlagLong(&t, "token", 't', "")
}
func main() {
err := getopt.Getopt(nil)
if err != nil {
fmt.Println(err)
usage()
os.Exit(1)
}
if *V == true {
fmt.Println("blih version " + version)
return
}
args := getopt.Args()
if len(args) == 0 {
usage()
os.Exit(1)
}
switch args[0] {
case "repository":
err = repository.Execute(args[1:], b, u, t, U)
case "sshkey":
err = sshkey.Execute(args[1:], b, u, t, U)
case "whoami":
err = whoami.Execute(args[1:], b, u, t, U)
default:
usage()
os.Exit(1)
}
if err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
}
}