-
Notifications
You must be signed in to change notification settings - Fork 64
/
cloud.go
123 lines (94 loc) · 3.8 KB
/
cloud.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2023, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package cloud
import (
"context"
"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"kraftkit.sh/internal/cli/kraft/cloud/certificate"
"kraftkit.sh/internal/cli/kraft/cloud/compose"
"kraftkit.sh/internal/cli/kraft/cloud/deploy"
"kraftkit.sh/internal/cli/kraft/cloud/img"
"kraftkit.sh/internal/cli/kraft/cloud/instance"
"kraftkit.sh/internal/cli/kraft/cloud/metros"
"kraftkit.sh/internal/cli/kraft/cloud/quotas"
"kraftkit.sh/internal/cli/kraft/cloud/scale"
"kraftkit.sh/internal/cli/kraft/cloud/service"
"kraftkit.sh/internal/cli/kraft/cloud/tunnel"
"kraftkit.sh/internal/cli/kraft/cloud/volume"
"kraftkit.sh/cmdfactory"
)
type CloudOptions struct {
Metro string `long:"metro" env:"UNIKRAFTCLOUD_METRO" usage:"Set the UnikraftCloud metro"`
Token string `long:"token" env:"UNIKRAFTCLOUD_TOKEN" usage:"Set the UnikraftCloud token"`
}
func NewCmd() *cobra.Command {
cmd, err := cmdfactory.New(&CloudOptions{}, cobra.Command{
Short: "Manage resources on the KraftCloud platform",
Use: "cloud [FLAGS] [SUBCOMMAND|DIR]",
Aliases: []string{"cl"},
Long: heredoc.Docf(`
▄▀▄▀ kraft.cloud
Manage resources on The Millisecond Platform.
Learn more & sign up for the beta at https://kraft.cloud
Quickly switch between metros using the %[1]s--metro%[1]s flag or use the
%[1]sUNIKRAFTCLOUD_METRO%[1]s environmental variable.
Set authentication by using %[1]skraft login%[1]s or set
%[1]sUNIKRAFTCLOUD_TOKEN%[1]s environmental variable.
`, "`"),
Example: heredoc.Doc(`
# List all images in your account
$ kraft cloud image list
# List all instances in Frankfurt
$ kraft cloud --metro fra0 instance list
# Create a new NGINX instance in Frankfurt and start it immediately
$ kraft cloud --metro fra0 instance create -S \
-p 80:443/http+redirect \
-p 443:8080/http+tls \
nginx:latest
# Get the status of an instance based on its UUID and output as JSON
$ kraft cloud --metro fra0 instance status -o json UUID
# Stop an instance based on its UUID
$ kraft cloud instance stop UUID
# Start an instance based on its UUID
$ kraft cloud instance start UUID
# Get logs of an instance based on its UUID
$ kraft cloud instance logs UUID
# Delete an instance based on its UUID
$ kraft cloud instance remove UUID
`),
Annotations: map[string]string{
cmdfactory.AnnotationHelpGroup: "kraftcloud",
cmdfactory.AnnotationHelpHidden: "true",
},
})
if err != nil {
panic(err)
}
cmd.AddCommand(deploy.NewCmd())
cmd.AddCommand(quotas.NewCmd())
cmd.AddCommand(tunnel.NewCmd())
cmd.AddGroup(&cobra.Group{ID: "kraftcloud-img", Title: "IMAGE COMMANDS"})
cmd.AddCommand(img.NewCmd())
cmd.AddGroup(&cobra.Group{ID: "kraftcloud-instance", Title: "INSTANCE COMMANDS"})
cmd.AddCommand(instance.NewCmd())
cmd.AddGroup(&cobra.Group{ID: "kraftcloud-vol", Title: "VOLUME COMMANDS"})
cmd.AddCommand(volume.NewCmd())
cmd.AddGroup(&cobra.Group{ID: "kraftcloud-scale", Title: "SCALE COMMANDS"})
cmd.AddCommand(scale.NewCmd())
cmd.AddGroup(&cobra.Group{ID: "kraftcloud-svc", Title: "SERVICE COMMANDS"})
cmd.AddCommand(service.NewCmd())
cmd.AddGroup(&cobra.Group{ID: "kraftcloud-certificate", Title: "CERTIFICATE COMMANDS"})
cmd.AddCommand(certificate.NewCmd())
cmd.AddGroup(&cobra.Group{ID: "kraftcloud-metro", Title: "METRO COMMANDS"})
cmd.AddCommand(metros.NewCmd())
cmd.AddGroup(&cobra.Group{ID: "kraftcloud-compose", Title: "COMPOSE COMMANDS"})
cmd.AddCommand(compose.NewCmd())
return cmd
}
func (opts *CloudOptions) Run(_ context.Context, args []string) error {
return pflag.ErrHelp
}