Browse code

Remove command line flag install from registry package.

Settings flags is the responsibility of the application (cmd/) not a library

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2017/08/30 04:55:09
Showing 4 changed files
... ...
@@ -5,6 +5,7 @@ import (
5 5
 
6 6
 	"github.com/docker/docker/daemon/config"
7 7
 	"github.com/docker/docker/opts"
8
+	"github.com/docker/docker/registry"
8 9
 	"github.com/spf13/pflag"
9 10
 )
10 11
 
... ...
@@ -19,7 +20,7 @@ const (
19 19
 func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
20 20
 	var maxConcurrentDownloads, maxConcurrentUploads int
21 21
 
22
-	conf.ServiceOptions.InstallCliFlags(flags)
22
+	installRegistryServiceFlags(&conf.ServiceOptions, flags)
23 23
 
24 24
 	flags.Var(opts.NewNamedListOptsRef("storage-opts", &conf.GraphOptions, nil), "storage-opt", "Storage driver options")
25 25
 	flags.Var(opts.NewNamedListOptsRef("authorization-plugins", &conf.AuthorizationPlugins, nil), "authorization-plugin", "Authorization plugins to load")
... ...
@@ -75,3 +76,17 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
75 75
 	conf.MaxConcurrentDownloads = &maxConcurrentDownloads
76 76
 	conf.MaxConcurrentUploads = &maxConcurrentUploads
77 77
 }
78
+
79
+func installRegistryServiceFlags(options *registry.ServiceOptions, flags *pflag.FlagSet) {
80
+	ana := opts.NewNamedListOptsRef("allow-nondistributable-artifacts", &options.AllowNondistributableArtifacts, registry.ValidateIndexName)
81
+	mirrors := opts.NewNamedListOptsRef("registry-mirrors", &options.Mirrors, registry.ValidateMirror)
82
+	insecureRegistries := opts.NewNamedListOptsRef("insecure-registries", &options.InsecureRegistries, registry.ValidateIndexName)
83
+
84
+	flags.Var(ana, "allow-nondistributable-artifacts", "Allow push of nondistributable artifacts to registry")
85
+	flags.Var(mirrors, "registry-mirror", "Preferred Docker registry mirror")
86
+	flags.Var(insecureRegistries, "insecure-registry", "Enable insecure registry communication")
87
+
88
+	if runtime.GOOS != "windows" {
89
+		flags.BoolVar(&options.V2Only, "disable-legacy-registry", true, "Disable contacting legacy registries")
90
+	}
91
+}
... ...
@@ -10,10 +10,8 @@ import (
10 10
 
11 11
 	"github.com/docker/distribution/reference"
12 12
 	registrytypes "github.com/docker/docker/api/types/registry"
13
-	"github.com/docker/docker/opts"
14 13
 	"github.com/pkg/errors"
15 14
 	"github.com/sirupsen/logrus"
16
-	"github.com/spf13/pflag"
17 15
 )
18 16
 
19 17
 // ServiceOptions holds command line options.
... ...
@@ -72,20 +70,6 @@ var (
72 72
 // for mocking in unit tests
73 73
 var lookupIP = net.LookupIP
74 74
 
75
-// InstallCliFlags adds command-line options to the top-level flag parser for
76
-// the current process.
77
-func (options *ServiceOptions) InstallCliFlags(flags *pflag.FlagSet) {
78
-	ana := opts.NewNamedListOptsRef("allow-nondistributable-artifacts", &options.AllowNondistributableArtifacts, ValidateIndexName)
79
-	mirrors := opts.NewNamedListOptsRef("registry-mirrors", &options.Mirrors, ValidateMirror)
80
-	insecureRegistries := opts.NewNamedListOptsRef("insecure-registries", &options.InsecureRegistries, ValidateIndexName)
81
-
82
-	flags.Var(ana, "allow-nondistributable-artifacts", "Allow push of nondistributable artifacts to registry")
83
-	flags.Var(mirrors, "registry-mirror", "Preferred Docker registry mirror")
84
-	flags.Var(insecureRegistries, "insecure-registry", "Enable insecure registry communication")
85
-
86
-	options.installCliPlatformFlags(flags)
87
-}
88
-
89 75
 // newServiceConfig returns a new instance of ServiceConfig
90 76
 func newServiceConfig(options ServiceOptions) *serviceConfig {
91 77
 	config := &serviceConfig{
... ...
@@ -2,10 +2,6 @@
2 2
 
3 3
 package registry
4 4
 
5
-import (
6
-	"github.com/spf13/pflag"
7
-)
8
-
9 5
 var (
10 6
 	// CertsDir is the directory where certificates are stored
11 7
 	CertsDir = "/etc/docker/certs.d"
... ...
@@ -18,8 +14,3 @@ var (
18 18
 func cleanPath(s string) string {
19 19
 	return s
20 20
 }
21
-
22
-// installCliPlatformFlags handles any platform specific flags for the service.
23
-func (options *ServiceOptions) installCliPlatformFlags(flags *pflag.FlagSet) {
24
-	flags.BoolVar(&options.V2Only, "disable-legacy-registry", true, "Disable contacting legacy registries")
25
-}
... ...
@@ -4,8 +4,6 @@ import (
4 4
 	"os"
5 5
 	"path/filepath"
6 6
 	"strings"
7
-
8
-	"github.com/spf13/pflag"
9 7
 )
10 8
 
11 9
 // CertsDir is the directory where certificates are stored
... ...
@@ -18,8 +16,3 @@ var CertsDir = os.Getenv("programdata") + `\docker\certs.d`
18 18
 func cleanPath(s string) string {
19 19
 	return filepath.FromSlash(strings.Replace(s, ":", "", -1))
20 20
 }
21
-
22
-// installCliPlatformFlags handles any platform specific flags for the service.
23
-func (options *ServiceOptions) installCliPlatformFlags(flags *pflag.FlagSet) {
24
-	// No Windows specific flags.
25
-}