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:
38
plugins/config/functions.go
Normal file
38
plugins/config/functions.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user