This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
128 lines (124 loc) · 3.65 KB
/
commands.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
package main
import (
"dr/command"
"dr/config"
"dr/errcodes"
"fmt"
"github.com/urfave/cli"
"os"
"strings"
)
var outputFlag = cli.StringFlag{
Name: "output, o",
Usage: "output format for all commands [json, plain]",
}
// Commands available to the application. Array of all commands that can be used in dr
var Commands = []cli.Command{
{
Name: "list",
ShortName: "ls",
Usage: "List remote images for the default repository",
Action: command.ListRepositoryImages,
Flags: append([]cli.Flag{
cli.BoolFlag{
Name: "t, tags, show-tags",
Hidden: false,
Usage: "When showing images, also show the tag (as a suffix)",
},
cli.BoolFlag{
Name: "repo, show-repo",
Hidden: false,
Usage: "Prefix each image name with the repository where it comes from",
},
}, outputFlag),
UsageText: "dr list",
BashComplete: command.TagsAuto,
},
{
Name: "tags",
ShortName: "t",
Aliases: []string{"tag"},
Usage: "List available tags for a remote image",
Action: command.Tags,
Flags: []cli.Flag{outputFlag},
UsageText: "dr tags busybox",
ArgsUsage: "dr tags <repository>",
BashComplete: command.TagsAuto,
},
{
Name: "context",
ShortName: "cont",
Usage: "Manage configuration for contexts",
UsageText: "dr context <subcommand>",
Subcommands: []cli.Command{
{
Name: "set",
Aliases: []string{"use"},
Usage: "Set the current context. The name of the context must exist",
Action: command.SetCurrentContext,
ArgsUsage: "Name of the context that you want to use as the 'currentContext'.",
UsageText: "dr context set <name-of-the-context>",
},
{
Name: "get",
Aliases: []string{"list", "ls", "show"},
Usage: "Get the currently configured contexts, including the name",
Action: command.GetCurrentContexts,
UsageText: "dr context get",
Flags: []cli.Flag{outputFlag},
},
},
},
{
Name: "config",
ShortName: "conf",
Usage: "Manage configuration",
Flags: []cli.Flag{},
UsageText: "dr config <subcommand>",
Subcommands: []cli.Command{
{
Name: "get",
Aliases: []string{"show"},
Usage: "Get the current configuration",
Action: command.ShowCurrentConfiguration,
UsageText: "dr config get",
},
{
Name: "set",
Usage: "Set a configuration parameter",
UsageText: "dr config set <subcommand>",
Subcommands: []cli.Command{
{
Name: "output",
Aliases: []string{"o", "format", "fmt"},
Usage: "Set the default output to the specified",
UsageText: "dr config set output <output format> -- Valid formats are: [" + strings.Join(config.GetValidOutputFormatsShort(), ", ") + "]",
Action: command.SetOutputFormat,
},
},
},
},
},
{
Name: "info",
ShortName: "i",
Aliases: []string{"manifest", "mf", "m"},
Usage: "Show additional information about a layer",
Flags: []cli.Flag{outputFlag},
UsageText: "dr info image:tag",
Action: command.ManifestInfo,
BashComplete: command.ManifestInfoAuto,
},
{
Name: "login",
Usage: "Saves the pasword for a given context in the OS keyring",
UsageText: "dr login <contextName>",
Action: command.Login,
BashComplete: command.LoginComplete,
},
}
// CommandNotFound default handler for when a command is not found, with custom exit error
func CommandNotFound(c *cli.Context, command string) {
_, _ = fmt.Fprintf(os.Stderr, "%s: '%s' is not a %s command. See '%s --help'.\n", c.App.Name, command, c.App.Name, c.App.Name)
os.Exit(errcodes.CommandNotFound)
}