Debian Codegraph @

cmd/ctr-remote/main.go

raw
1 /*
2 Copyright The containerd Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package main
18
19 import (
20 "fmt"
21 "os"
22
23 "github.com/containerd/containerd/cmd/ctr/app"
24 "github.com/containerd/containerd/pkg/seed"
25 "github.com/containerd/stargz-snapshotter/cmd/ctr-remote/commands"
26 "github.com/urfave/cli"
27 )
28
29 func init() {
30 seed.WithTimeAndRand()
31 }
32
33 func main() {
34 customCommands := []cli.Command{
35 commands.RpullCommand,
36 commands.OptimizeCommand,
37 commands.ConvertCommand,
38 commands.GetTOCDigestCommand,
39 commands.IPFSPushCommand,
40 }
41 app := app.New()
42 for i := range app.Commands {
43 if app.Commands[i].Name == "images" {
44 sc := map[string]cli.Command{}
45 for _, subcmd := range customCommands {
46 sc[subcmd.Name] = subcmd
47 }
48
49 // First, replace duplicated subcommands
50 for j := range app.Commands[i].Subcommands {
51 for name, subcmd := range sc {
52 if name == app.Commands[i].Subcommands[j].Name {
53 app.Commands[i].Subcommands[j] = subcmd
54 delete(sc, name)
55 }
56 }
57 }
58
59 // Next, append all new sub commands
60 for _, subcmd := range sc {
61 app.Commands[i].Subcommands = append(app.Commands[i].Subcommands, subcmd)
62 }
63 break
64 }
65 }
66 app.Commands = append(app.Commands, commands.FanotifyCommand)
67 if err := app.Run(os.Args); err != nil {
68 fmt.Fprintf(os.Stderr, "ctr-remote: %v\n", err)
69 os.Exit(1)
70 }
71 }