From d336d7c5c24cdd85de8c8b11b9f207d980147f6b Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 17 Feb 2020 18:48:06 -0500 Subject: [PATCH] feat: add `prop clone` command --- plugins/common/properties.go | 16 ++++++++++++++++ plugins/common/property-functions | 6 ++++++ plugins/common/src/prop/prop.go | 8 ++++++++ 3 files changed, 30 insertions(+) diff --git a/plugins/common/properties.go b/plugins/common/properties.go index cbbf75349..5483914b6 100644 --- a/plugins/common/properties.go +++ b/plugins/common/properties.go @@ -44,6 +44,22 @@ func CommandPropertySet(pluginName, appName, property, value string, properties } } +// PropertyClone clones a set of properties from one app to another +func PropertyClone(pluginName string, oldAppName string, newAppName string) error { + properties, err := PropertyGetAll(pluginName, oldAppName) + if err != nil { + return err + } + + for property, value := range properties { + if err := PropertyWrite(pluginName, newAppName, property, value); err != nil { + return err + } + } + + return nil +} + // PropertyDelete deletes a property from the plugin properties for an app func PropertyDelete(pluginName string, appName string, property string) error { propertyPath := getPropertyPath(pluginName, appName, property) diff --git a/plugins/common/property-functions b/plugins/common/property-functions index 72330838d..8f20ad8b4 100755 --- a/plugins/common/property-functions +++ b/plugins/common/property-functions @@ -9,6 +9,12 @@ fn-plugin-property-get() { fn-plugin-property-get-default "$PLUGIN" "$APP" "$KEY" "$DEFAULT" } +fn-plugin-property-clone() { + declare desc="destroy the properties for an app" + declare PLUGIN="$1" OLD_APP="$2" NEW_APP="$3" + "$PLUGIN_CORE_AVAILABLE_PATH/common/prop" "clone" "$PLUGIN" "$OLD_APP" "$NEW_APP" +} + fn-plugin-property-destroy() { declare desc="destroy the properties for an app" declare PLUGIN="$1" APP="$2" diff --git a/plugins/common/src/prop/prop.go b/plugins/common/src/prop/prop.go index 1850f7562..8614d9a0f 100644 --- a/plugins/common/src/prop/prop.go +++ b/plugins/common/src/prop/prop.go @@ -33,6 +33,14 @@ func main() { pluginName := flag.Arg(1) switch cmd { + case "clone": + oldAppName := flag.Arg(2) + newAppName := flag.Arg(3) + err := common.PropertyClone(pluginName, oldAppName, newAppName) + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } case "del": appName := flag.Arg(2) property := flag.Arg(3)