feat: add prop clone command

This commit is contained in:
Jose Diaz-Gonzalez
2020-02-17 18:48:06 -05:00
parent ebd27cd666
commit d336d7c5c2
3 changed files with 30 additions and 0 deletions

View File

@@ -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)

View File

@@ -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"

View File

@@ -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)