Files
ispctl/command/delete.go
T
DeniskaRediska 8b8815d2f2 add 'contain' command for common configs
add flag 'full' for 'get' command
update bash complete
2019-10-30 14:58:50 +03:00

63 lines
1.3 KiB
Go

package command
import (
"encoding/json"
"github.com/codegangsta/cli"
"github.com/tidwall/sjson"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
)
func Delete() cli.Command {
return cli.Command{
Name: "delete",
Usage: "delete configuration by module_name",
Action: deleteComm.action,
BashComplete: bash.Module.ModuleName_ModuleData,
}
}
var deleteComm deleteCommand
type deleteCommand struct{}
func (d deleteCommand) action(ctx *cli.Context) {
if err := flag.CheckGlobal(ctx); err != nil {
utils.PrintError(err)
return
}
moduleName := ctx.Args().First()
pathObject := ctx.Args().Get(1)
moduleConfiguration, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil {
utils.PrintError(err)
return
}
pathObject, err = utils.CheckPath(pathObject)
if err != nil {
utils.PrintError(err)
return
}
if pathObject == "" {
utils.CreateUpdateConfig("", moduleConfiguration)
} else {
jsonObject, err := json.Marshal(moduleConfiguration.Data)
if err != nil {
utils.PrintError(err)
return
}
if stringToChange, err := sjson.Delete(string(jsonObject), pathObject); err != nil {
utils.PrintError(err)
return
} else {
utils.CreateUpdateConfig(stringToChange, moduleConfiguration)
}
}
}