This repository was archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
109 lines (101 loc) · 2.3 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"cli/client"
"cli/cmd"
"log"
"net/url"
"os"
"sort"
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/urfave/cli/v2"
)
var transport *httptransport.Runtime
func main() {
app := &cli.App{
Description: "command line tool for access to deploy-f api",
Version: Version,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "token, t",
Usage: "Personal Access Token for access to api",
EnvVars: []string{"DF_API_TOKEN"},
Required: true,
},
&cli.StringFlag{
Name: "host",
Usage: "Api host",
Value: "https://api.deploy-f.com",
EnvVars: []string{"DF_HOST"},
},
},
Commands: []*cli.Command{
{
Name: "set-image",
Aliases: []string{"si"},
Usage: "Set an image to application",
Action: cmd.SetImage,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "app-id, a",
Usage: "Application id",
EnvVars: []string{"DF_APP_ID"},
Required: true,
},
&cli.StringFlag{
Name: "image, i",
Usage: "Docker image",
Required: true,
},
},
},
{
Name: "start",
Aliases: []string{"s"},
Usage: "Start or restart application",
Action: cmd.Start,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "app-id, a",
Usage: "Application id",
EnvVars: []string{"DF_APP_ID"},
Required: true,
},
},
},
{
Name: "stop",
Aliases: []string{"st"},
Usage: "Stop application",
Action: cmd.Stop,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "app-id, a",
Usage: "Application id",
EnvVars: []string{"DF_APP_ID"},
Required: true,
},
},
},
},
Before: initApp,
}
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func initApp(c *cli.Context) error {
uri, err := url.Parse(c.String("host"))
if err != nil {
panic(err)
}
transport = httptransport.New(uri.Host, "", []string{uri.Scheme})
transport.Producers["application/*+json"] = runtime.JSONProducer()
cmd.Auth = httptransport.BearerToken(c.String("token"))
cmd.Api = client.New(transport, strfmt.Default)
return nil
}