-
Notifications
You must be signed in to change notification settings - Fork 64
/
kraft.go
144 lines (123 loc) · 3.73 KB
/
kraft.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, 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 main
import (
"fmt"
"os"
"github.com/MakeNowJust/heredoc"
"github.com/rancher/wrangler/pkg/signals"
"github.com/spf13/cobra"
"kraftkit.sh/cmdfactory"
"kraftkit.sh/config"
"kraftkit.sh/internal/cli"
kitupdate "kraftkit.sh/internal/update"
kitversion "kraftkit.sh/internal/version"
"kraftkit.sh/iostreams"
"kraftkit.sh/log"
"kraftkit.sh/cmd/kraft/build"
"kraftkit.sh/cmd/kraft/clean"
"kraftkit.sh/cmd/kraft/events"
"kraftkit.sh/cmd/kraft/fetch"
"kraftkit.sh/cmd/kraft/login"
"kraftkit.sh/cmd/kraft/logs"
"kraftkit.sh/cmd/kraft/menu"
"kraftkit.sh/cmd/kraft/net"
"kraftkit.sh/cmd/kraft/pkg"
"kraftkit.sh/cmd/kraft/prepare"
"kraftkit.sh/cmd/kraft/properclean"
"kraftkit.sh/cmd/kraft/ps"
"kraftkit.sh/cmd/kraft/rm"
"kraftkit.sh/cmd/kraft/run"
"kraftkit.sh/cmd/kraft/set"
"kraftkit.sh/cmd/kraft/stop"
"kraftkit.sh/cmd/kraft/unset"
"kraftkit.sh/cmd/kraft/version"
// Additional initializers
_ "kraftkit.sh/manifest"
_ "kraftkit.sh/oci"
)
type Kraft struct{}
func New() *cobra.Command {
cmd, err := cmdfactory.New(&Kraft{}, cobra.Command{
Short: "Build and use highly customized and ultra-lightweight unikernels",
Long: heredoc.Docf(`
.
/^\ Build and use highly customized and ultra-lightweight unikernels.
:[ ]:
| = | Version: %s
/|/=\|\ Documentation: https://kraftkit.sh/
(_:| |:_) Issues & support: https://github.com/unikraft/kraftkit/issues
v v
' '`, kitversion.Version()),
CompletionOptions: cobra.CompletionOptions{
HiddenDefaultCmd: true,
},
})
if err != nil {
panic(err)
}
cmd.AddGroup(&cobra.Group{ID: "build", Title: "BUILD COMMANDS"})
cmd.AddCommand(build.New())
cmd.AddCommand(clean.New())
cmd.AddCommand(fetch.New())
cmd.AddCommand(menu.New())
cmd.AddCommand(prepare.New())
cmd.AddCommand(properclean.New())
cmd.AddCommand(set.New())
cmd.AddCommand(unset.New())
cmd.AddGroup(&cobra.Group{ID: "pkg", Title: "PACKAGING COMMANDS"})
cmd.AddCommand(pkg.New())
cmd.AddGroup(&cobra.Group{ID: "run", Title: "RUNTIME COMMANDS"})
cmd.AddCommand(events.New())
cmd.AddCommand(logs.New())
cmd.AddCommand(ps.New())
cmd.AddCommand(rm.New())
cmd.AddCommand(run.New())
cmd.AddCommand(stop.New())
cmd.AddGroup(&cobra.Group{ID: "net", Title: "LOCAL NETWORKING COMMANDS"})
cmd.AddCommand(net.New())
cmd.AddGroup(&cobra.Group{ID: "misc", Title: "MISCELLANEOUS COMMANDS"})
cmd.AddCommand(login.New())
cmd.AddCommand(version.New())
return cmd
}
func (k *Kraft) Run(cmd *cobra.Command, args []string) error {
return cmd.Help()
}
func main() {
cmd := New()
ctx := signals.SetupSignalContext()
copts := &cli.CliOptions{}
for _, o := range []cli.CliOption{
cli.WithDefaultConfigManager(cmd),
cli.WithDefaultIOStreams(),
cli.WithDefaultPluginManager(),
cli.WithDefaultLogger(),
cli.WithDefaultHTTPClient(),
} {
if err := o(copts); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
// Set up the config manager in the context if it is available
if copts.ConfigManager != nil {
ctx = config.WithConfigManager(ctx, copts.ConfigManager)
}
// Set up the logger in the context if it is available
if copts.Logger != nil {
ctx = log.WithLogger(ctx, copts.Logger)
}
// Set up the iostreams in the context if it is available
if copts.IOStreams != nil {
ctx = iostreams.WithIOStreams(ctx, copts.IOStreams)
}
if !config.G[config.KraftKit](ctx).NoCheckUpdates {
if err := kitupdate.Check(ctx); err != nil {
log.G(ctx).Debugf("could not check for updates: %v", err)
}
}
cmdfactory.Main(ctx, cmd)
}