mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 09:39:08 +00:00
Add a ~/.moby directory for config
Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
parent
cde8329d2f
commit
cf8d8ca014
@ -17,6 +17,9 @@ var (
|
|||||||
|
|
||||||
// GitCommit hash, set at compile time
|
// GitCommit hash, set at compile time
|
||||||
GitCommit = "unknown"
|
GitCommit = "unknown"
|
||||||
|
|
||||||
|
// MobyDir is the location of the cache directory ~/.moby by default
|
||||||
|
MobyDir string
|
||||||
)
|
)
|
||||||
|
|
||||||
// infoFormatter overrides the default format for Info() log events to
|
// infoFormatter overrides the default format for Info() log events to
|
||||||
@ -37,6 +40,13 @@ func version() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mobyDefaultDir string = ".moby"
|
||||||
|
|
||||||
|
func defaultMobyConfigDir() string {
|
||||||
|
home := homeDir()
|
||||||
|
return filepath.Join(home, mobyDefaultDir)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0]))
|
fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0]))
|
||||||
@ -53,9 +63,13 @@ func main() {
|
|||||||
flagQuiet := flag.Bool("q", false, "Quiet execution")
|
flagQuiet := flag.Bool("q", false, "Quiet execution")
|
||||||
flagVerbose := flag.Bool("v", false, "Verbose execution")
|
flagVerbose := flag.Bool("v", false, "Verbose execution")
|
||||||
|
|
||||||
|
// config and cache directory
|
||||||
|
flagConfigDir := flag.String("config", defaultMobyConfigDir(), "Configuration directory")
|
||||||
|
|
||||||
// Set up logging
|
// Set up logging
|
||||||
log.SetFormatter(new(infoFormatter))
|
log.SetFormatter(new(infoFormatter))
|
||||||
log.SetLevel(log.InfoLevel)
|
log.SetLevel(log.InfoLevel)
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *flagQuiet && *flagVerbose {
|
if *flagQuiet && *flagVerbose {
|
||||||
fmt.Printf("Can't set quiet and verbose flag at the same time\n")
|
fmt.Printf("Can't set quiet and verbose flag at the same time\n")
|
||||||
@ -77,6 +91,12 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MobyDir = *flagConfigDir
|
||||||
|
err := os.MkdirAll(MobyDir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Could not create config directory [%s]: %v", MobyDir, err)
|
||||||
|
}
|
||||||
|
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
case "build":
|
case "build":
|
||||||
build(args[1:])
|
build(args[1:])
|
||||||
|
11
cmd/moby/util_unix.go
Normal file
11
cmd/moby/util_unix.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func homeDir() string {
|
||||||
|
return os.Getenv("HOME")
|
||||||
|
}
|
9
cmd/moby/util_windows.go
Normal file
9
cmd/moby/util_windows.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func homeDir() string {
|
||||||
|
return os.Getenv("USERPROFILE")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user