[config] refactor package structure

This commit is contained in:
Alex Quick
2017-10-15 20:10:46 -04:00
parent 03830562c2
commit 91c2164e49
13 changed files with 469 additions and 289 deletions

View File

@@ -2,10 +2,8 @@ package main
import (
"flag"
"fmt"
"os"
"github.com/dokku/dokku/plugins/common"
"github.com/dokku/dokku/plugins/config"
)
@@ -14,11 +12,5 @@ func main() {
global := args.Bool("global", false, "--global: use the global environment")
merged := args.Bool("merged", false, "--merged: merge app environment and global environment")
args.Parse(os.Args[2:])
appName, trailingArgs := config.GetCommonArgs(*global, args.Args())
if len(trailingArgs) > 0 {
common.LogFail(fmt.Sprintf("Trailing argument(s): %v", trailingArgs))
}
config := config.GetConfig(appName, *merged)
config.ExportBundle(os.Stdout)
config.CommandBundle(args.Args(), *global, *merged)
}

View File

@@ -2,12 +2,9 @@ package main
import (
"flag"
"fmt"
"os"
common "github.com/dokku/dokku/plugins/common"
"github.com/dokku/dokku/plugins/config"
"github.com/dokku/dokku/plugins/config/src/configenv"
)
// print the environment to stdout
@@ -19,28 +16,5 @@ func main() {
merged := args.Bool("merged", false, "--merged: merge app environment and global environment")
format := args.String("format", "exports", "--format: [ exports | envfile | docker-args | shell ] which format to export as)")
args.Parse(os.Args[2:])
appName, trailingArgs := config.GetCommonArgs(*global, args.Args())
if len(trailingArgs) > 0 {
common.LogFail(fmt.Sprintf("Trailing argument(s): %v", trailingArgs))
}
env := config.GetConfig(appName, *merged)
exportType := configenv.Exports
suffix := "\n"
switch *format {
case "exports":
exportType = configenv.Exports
case "envfile":
exportType = configenv.Envfile
case "docker-args":
exportType = configenv.DockerArgs
case "shell":
exportType = configenv.Shell
suffix = " "
default:
common.LogFail(fmt.Sprintf("Unknown export format: %v", *format))
}
exported := env.Export(exportType)
fmt.Print(exported + suffix)
config.CommandExport(args.Args(), *global, *merged, *format)
}

View File

@@ -2,12 +2,9 @@ package main
import (
"flag"
"fmt"
"os"
common "github.com/dokku/dokku/plugins/common"
"github.com/dokku/dokku/plugins/config"
"github.com/dokku/dokku/plugins/config/src/configenv"
)
// get the given entries from the specified environment
@@ -16,22 +13,5 @@ func main() {
global := args.Bool("global", false, "--global: use the global environment")
quoted := args.Bool("quoted", false, "--quoted: get the value quoted")
args.Parse(os.Args[2:])
appName, keys := config.GetCommonArgs(*global, args.Args())
if len(keys) > 1 {
common.LogFail(fmt.Sprintf("Unexpected argument(s): %v", keys[1:]))
}
if len(keys) == 0 {
common.LogFail("Expected: key")
}
if !config.HasKey(appName, keys[0]) {
os.Exit(1)
}
value := config.GetWithDefault(appName, keys[0], "")
if *quoted {
fmt.Printf("'%s'", configenv.SingleQuoteEscape(value))
} else {
fmt.Printf("%s", value)
}
config.CommandGet(args.Args(), *global, *quoted)
}

View File

@@ -2,10 +2,8 @@ package main
import (
"flag"
"fmt"
"os"
"github.com/dokku/dokku/plugins/common"
"github.com/dokku/dokku/plugins/config"
)
@@ -14,13 +12,5 @@ func main() {
global := args.Bool("global", false, "--global: use the global environment")
merged := args.Bool("merged", false, "--merged: merge app environment and global environment")
args.Parse(os.Args[2:])
appName, trailingArgs := config.GetCommonArgs(*global, args.Args())
if len(trailingArgs) > 0 {
common.LogFail(fmt.Sprintf("Trailing argument(s): %v", trailingArgs))
}
config := config.GetConfig(appName, *merged)
for _, k := range config.Keys() {
fmt.Println(k)
}
config.CommandKeys(args.Args(), *global, *merged)
}

View File

@@ -1,14 +1,10 @@
package main
import (
"encoding/base64"
"flag"
"fmt"
"os"
"strings"
common "github.com/dokku/dokku/plugins/common"
config "github.com/dokku/dokku/plugins/config"
"github.com/dokku/dokku/plugins/config"
)
// set the given entries from the specified environment
@@ -18,23 +14,5 @@ func main() {
encoded := args.Bool("encoded", false, "--encoded: interpret VALUEs as base64")
noRestart := args.Bool("no-restart", false, "--no-restart: no restart")
args.Parse(os.Args[2:])
appName, pairs := config.GetCommonArgs(*global, args.Args())
updated := make(map[string]string)
for _, e := range pairs {
parts := strings.SplitN(e, "=", 2)
if len(parts) == 1 {
common.LogFail("Invalid env pair: " + e)
}
key, value := parts[0], parts[1]
if *encoded {
decoded, err := base64.StdEncoding.DecodeString(value)
if err != nil {
common.LogFail(fmt.Sprintf("%s for key '%s'", err.Error(), key))
}
value = string(decoded)
}
updated[key] = value
}
config.SetMany(appName, updated, !*noRestart)
config.CommandSet(args.Args(), *global, *noRestart, *encoded)
}

View File

@@ -12,8 +12,6 @@ func main() {
args := flag.NewFlagSet("config:unset", flag.ExitOnError)
global := args.Bool("global", false, "--global: use the global environment")
noRestart := args.Bool("no-restart", false, "--no-restart: no restart")
args.Parse(os.Args[2:])
appName, keys := config.GetCommonArgs(*global, args.Args())
config.UnsetMany(appName, keys, !*noRestart)
config.CommandUnset(args.Args(), *global, *noRestart)
}