Repository navigation
Expand file tree
/
Copy pathcheckpointctl.go
More file actions
60 lines (50 loc) · 1.52 KB
/
Copy pathcheckpointctl.go
File metadata and controls
60 lines (50 loc) · 1.52 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
// SPDX-License-Identifier: Apache-2.0
package main
import (
"os"
cmd "github.com/checkpoint-restore/checkpointctl/cmd"
"github.com/spf13/cobra"
)
var (
name string
version string
)
func main() {
rootCommand := &cobra.Command{
Use: name,
Short: name + " is a tool to read and manipulate checkpoint archives",
Long: name + " is a tool to read and manipulate checkpoint archives as " +
"created by Podman, CRI-O and containerd",
SilenceUsage: true,
}
rootCommand.AddCommand(cmd.Show())
rootCommand.AddCommand(cmd.Inspect())
rootCommand.AddCommand(cmd.MemParse())
rootCommand.AddCommand(cmd.List())
rootCommand.AddCommand(cmd.BuildCmd())
rootCommand.AddCommand(cmd.PluginCmd())
rootCommand.AddCommand(cmd.Diff())
// Discover and register external plugins from PATH.
// Plugins are executables named checkpointctl-<name> where <name>
// becomes a subcommand. Built-in commands take precedence.
builtinCommands := getBuiltinCommandNames(rootCommand)
for _, plugin := range cmd.DiscoverPlugins() {
// Skip plugins that would shadow built-in commands
if builtinCommands[plugin.Name] {
continue
}
rootCommand.AddCommand(cmd.CreatePluginCommand(plugin))
}
rootCommand.Version = version
if err := rootCommand.Execute(); err != nil {
os.Exit(1)
}
}
// getBuiltinCommandNames returns a set of command names already registered.
func getBuiltinCommandNames(root *cobra.Command) map[string]bool {
names := make(map[string]bool)
for _, c := range root.Commands() {
names[c.Name()] = true
}
return names
}