2020-04-24 18:04:32 +02:00
|
|
|
/*
|
2020-09-22 12:13:00 +02:00
|
|
|
Copyright 2020 Docker Compose CLI authors
|
2020-06-18 16:13:24 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2020-04-24 18:04:32 +02:00
|
|
|
*/
|
|
|
|
|
2020-05-14 09:48:53 +02:00
|
|
|
package config
|
2020-04-08 16:21:02 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2020-05-14 09:48:53 +02:00
|
|
|
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
|
2021-01-15 16:55:10 +01:00
|
|
|
"github.com/docker/compose-cli/api/config"
|
2020-04-08 16:21:02 +02:00
|
|
|
)
|
|
|
|
|
2020-05-14 09:48:53 +02:00
|
|
|
// ConfigFlags are the global CLI flags
|
|
|
|
// nolint stutter
|
|
|
|
type ConfigFlags struct {
|
|
|
|
Config string
|
|
|
|
}
|
2020-04-08 16:21:02 +02:00
|
|
|
|
2020-05-14 09:48:53 +02:00
|
|
|
// AddConfigFlags adds persistent (global) flags
|
|
|
|
func (c *ConfigFlags) AddConfigFlags(flags *pflag.FlagSet) {
|
2020-06-06 22:22:30 +02:00
|
|
|
flags.StringVar(&c.Config, config.ConfigFlagName, confDir(), "Location of the client config files `DIRECTORY`")
|
2020-04-08 16:21:02 +02:00
|
|
|
}
|
|
|
|
|
2020-05-19 14:05:51 +02:00
|
|
|
func confDir() string {
|
|
|
|
env := os.Getenv("DOCKER_CONFIG")
|
|
|
|
if env != "" {
|
|
|
|
return env
|
|
|
|
}
|
2020-05-14 09:48:53 +02:00
|
|
|
home, _ := os.UserHomeDir()
|
2020-06-06 22:22:30 +02:00
|
|
|
return filepath.Join(home, config.ConfigFileDir)
|
2020-04-08 16:21:02 +02:00
|
|
|
}
|