This repository has been archived by the owner on Jun 13, 2021. It is now read-only.
/
root.go
145 lines (127 loc) · 4.3 KB
/
root.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
145
package commands
import (
"io/ioutil"
"github.com/docker/app/internal/store"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/config"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
// NewRootCmd returns the base root command.
func NewRootCmd(use string, dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Short: "Docker Application",
Long: `A tool to build and manage Docker Applications.`,
Use: use,
Annotations: map[string]string{"experimentalCLI": "true"},
}
addCommands(cmd, dockerCli)
return cmd
}
func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
cmd.AddCommand(
installCmd(dockerCli),
upgradeCmd(dockerCli),
uninstallCmd(dockerCli),
listCmd(dockerCli),
statusCmd(dockerCli),
initCmd(dockerCli),
inspectCmd(dockerCli),
mergeCmd(dockerCli),
renderCmd(dockerCli),
splitCmd(),
validateCmd(dockerCli),
versionCmd(dockerCli),
completionCmd(dockerCli, cmd),
bundleCmd(dockerCli),
pushCmd(dockerCli),
pullCmd(dockerCli),
)
}
func firstOrEmpty(list []string) string {
if len(list) != 0 {
return list[0]
}
return ""
}
func muteDockerCli(dockerCli command.Cli) func() {
stdout := dockerCli.Out()
stderr := dockerCli.Err()
dockerCli.Apply(command.WithCombinedStreams(ioutil.Discard)) //nolint:errcheck // WithCombinedStreams cannot error
return func() {
dockerCli.Apply(command.WithOutputStream(stdout), command.WithErrorStream(stderr)) //nolint:errcheck // as above
}
}
func prepareStores(targetContext string) (store.BundleStore, store.InstallationStore, store.CredentialStore, error) {
appstore, err := store.NewApplicationStore(config.Dir())
if err != nil {
return nil, nil, nil, err
}
installationStore, err := appstore.InstallationStore(targetContext)
if err != nil {
return nil, nil, nil, err
}
bundleStore, err := appstore.BundleStore()
if err != nil {
return nil, nil, nil, err
}
credentialStore, err := appstore.CredentialStore(targetContext)
if err != nil {
return nil, nil, nil, err
}
return bundleStore, installationStore, credentialStore, nil
}
func prepareBundleStore() (store.BundleStore, error) {
appstore, err := store.NewApplicationStore(config.Dir())
if err != nil {
return nil, err
}
bundleStore, err := appstore.BundleStore()
if err != nil {
return nil, err
}
return bundleStore, nil
}
type parametersOptions struct {
parametersFiles []string
overrides []string
}
func (o *parametersOptions) addFlags(flags *pflag.FlagSet) {
flags.StringArrayVar(&o.parametersFiles, "parameters-file", []string{}, "Override parameters file")
flags.StringArrayVarP(&o.overrides, "set", "s", []string{}, "Override parameter value")
}
type credentialOptions struct {
targetContext string
credentialsets []string
credentials []string
sendRegistryAuth bool
}
func (o *credentialOptions) addFlags(flags *pflag.FlagSet) {
flags.StringVar(&o.targetContext, "target-context", "", "Context on which the application is installed (default: <current-context>)")
flags.StringArrayVar(&o.credentialsets, "credential-set", []string{}, "Use a YAML file containing a credential set or a credential set present in the credential store")
flags.StringArrayVar(&o.credentials, "credential", nil, "Add a single credential, additive ontop of any --credential-set used")
flags.BoolVar(&o.sendRegistryAuth, "with-registry-auth", false, "Sends registry auth")
}
func (o *credentialOptions) SetDefaultTargetContext(dockerCli command.Cli) {
o.targetContext = getTargetContext(o.targetContext, dockerCli.CurrentContext())
}
func (o *credentialOptions) CredentialSetOpts(dockerCli command.Cli, credentialStore store.CredentialStore) []credentialSetOpt {
return []credentialSetOpt{
addNamedCredentialSets(credentialStore, o.credentialsets),
addCredentials(o.credentials),
addDockerCredentials(o.targetContext, dockerCli.ContextStore()),
addRegistryCredentials(o.sendRegistryAuth, dockerCli),
}
}
type registryOptions struct {
insecureRegistries []string
}
func (o *registryOptions) addFlags(flags *pflag.FlagSet) {
flags.StringSliceVar(&o.insecureRegistries, "insecure-registries", nil, "Use HTTP instead of HTTPS when pulling from/pushing to those registries")
}
type pullOptions struct {
pull bool
}
func (o *pullOptions) addFlags(flags *pflag.FlagSet) {
flags.BoolVar(&o.pull, "pull", false, "Pull the bundle")
}