fix: implement config-export hook

This will allow dropping many of the "source config/functions" calls littered over the codebase. Plugin triggers are the way to perform cross-plugin communication :)
This commit is contained in:
Jose Diaz-Gonzalez
2021-02-11 06:41:11 -05:00
parent 291f59999c
commit 0405b36ab4
7 changed files with 80 additions and 34 deletions

View File

@@ -0,0 +1,38 @@
package config
import "fmt"
func export(appName string, global bool, merged bool, format string) error {
appName, err := getAppNameOrGlobal(appName, global)
if err != nil {
return err
}
env := getEnvironment(appName, merged)
exportType := ExportFormatExports
suffix := "\n"
exportTypes := map[string]ExportFormat{
"exports": ExportFormatExports,
"envfile": ExportFormatEnvfile,
"docker-args": ExportFormatDockerArgs,
"docker-args-keys": ExportFormatDockerArgsKeys,
"shell": ExportFormatShell,
"pretty": ExportFormatPretty,
"json": ExportFormatJSON,
"json-list": ExportFormatJSONList,
}
exportType, ok := exportTypes[format]
if !ok {
return fmt.Errorf("Unknown export format: %v", format)
}
if exportType == ExportFormatShell {
suffix = " "
}
exported := env.Export(exportType)
fmt.Print(exported + suffix)
return nil
}