Move the config into own package and outside of cli

This commit is contained in:
Djordje Lukic 2020-06-06 22:22:30 +02:00
Родитель 67fb49c98c
Коммит 22d4d250a9
7 изменённых файлов: 20 добавлений и 20 удалений

Просмотреть файл

@ -33,7 +33,7 @@ import (
"github.com/spf13/cobra"
cliconfig "github.com/docker/api/cli/config"
"github.com/docker/api/config"
"github.com/docker/api/context/store"
)
@ -56,7 +56,7 @@ func runUse(ctx context.Context, name string) error {
return err
}
}
if err := cliconfig.WriteCurrentContext(cliconfig.Dir(ctx), name); err != nil {
if err := config.WriteCurrentContext(config.Dir(ctx), name); err != nil {
return err
}
fmt.Println(name)

Просмотреть файл

@ -32,15 +32,8 @@ import (
"path/filepath"
"github.com/spf13/pflag"
)
const (
// ConfigFileName is the name of config file
ConfigFileName = "config.json"
// ConfigFileDir is the default folder where the config file is stored
ConfigFileDir = ".docker"
// ConfigFlagName is the name of the config flag
ConfigFlagName = "config"
"github.com/docker/api/config"
)
// ConfigFlags are the global CLI flags
@ -51,7 +44,7 @@ type ConfigFlags struct {
// AddConfigFlags adds persistent (global) flags
func (c *ConfigFlags) AddConfigFlags(flags *pflag.FlagSet) {
flags.StringVar(&c.Config, ConfigFlagName, confDir(), "Location of the client config files `DIRECTORY`")
flags.StringVar(&c.Config, config.ConfigFlagName, confDir(), "Location of the client config files `DIRECTORY`")
}
func confDir() string {
@ -60,5 +53,5 @@ func confDir() string {
return env
}
home, _ := os.UserHomeDir()
return filepath.Join(home, ConfigFileDir)
return filepath.Join(home, config.ConfigFileDir)
}

Просмотреть файл

@ -38,10 +38,6 @@ import (
"syscall"
"time"
"github.com/docker/api/cli/cmd/login"
"github.com/docker/api/cli/dockerclassic"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -54,9 +50,11 @@ import (
"github.com/docker/api/cli/cmd"
"github.com/docker/api/cli/cmd/compose"
contextcmd "github.com/docker/api/cli/cmd/context"
"github.com/docker/api/cli/cmd/login"
"github.com/docker/api/cli/cmd/run"
cliconfig "github.com/docker/api/cli/config"
"github.com/docker/api/cli/dockerclassic"
cliopts "github.com/docker/api/cli/options"
"github.com/docker/api/config"
apicontext "github.com/docker/api/context"
"github.com/docker/api/context/store"
)
@ -151,7 +149,7 @@ func main() {
fatal(errors.New("config path cannot be empty"))
}
configDir := opts.Config
ctx = cliconfig.WithDir(ctx, configDir)
ctx = config.WithDir(ctx, configDir)
currentContext, err := determineCurrentContext(opts.Context, configDir)
if err != nil {
@ -206,7 +204,7 @@ func newSigContext() (context.Context, func()) {
func determineCurrentContext(flag string, configDir string) (string, error) {
res := flag
if res == "" {
config, err := cliconfig.LoadFile(configDir)
config, err := config.LoadFile(configDir)
if err != nil {
return "", err
}

Просмотреть файл

@ -40,7 +40,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/docker/api/cli/config"
"github.com/docker/api/config"
)
var contextSetConfig = []byte(`{

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -27,6 +27,15 @@
package config
const (
// ConfigFileName is the name of config file
ConfigFileName = "config.json"
// ConfigFileDir is the default folder where the config file is stored
ConfigFileDir = ".docker"
// ConfigFlagName is the name of the config flag
ConfigFlagName = "config"
)
const (
// currentContextKey is the key used in the Docker config file to set the
// default context