From 4e67709831ae8b81e4f55804758df87ecb6ee105 Mon Sep 17 00:00:00 2001 From: Christian Ege Date: Thu, 25 Jul 2024 08:39:38 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20the=20possibility=20t?= =?UTF-8?q?o=20remove=20elements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/postCreateCommand.sh | 3 ++- cmd/ovp8xx/cmd/remove.go | 42 ++++++++++++++++++++++++++++++ pkg/ovp8xx/rpc.go | 21 +++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 cmd/ovp8xx/cmd/remove.go diff --git a/.devcontainer/postCreateCommand.sh b/.devcontainer/postCreateCommand.sh index 4183b47..188d6e9 100755 --- a/.devcontainer/postCreateCommand.sh +++ b/.devcontainer/postCreateCommand.sh @@ -2,7 +2,8 @@ # install missing packages sudo apt-get update && - sudo apt-get install -q -y git-lfs \ + sudo apt-get install -q -y \ + git-lfs \ python3-pip \ python3-venv \ shfmt \ diff --git a/cmd/ovp8xx/cmd/remove.go b/cmd/ovp8xx/cmd/remove.go new file mode 100644 index 0000000..4224956 --- /dev/null +++ b/cmd/ovp8xx/cmd/remove.go @@ -0,0 +1,42 @@ +/* +Copyright © 2023 Christian Ege +*/ +package cmd + +import ( + "fmt" + + "github.com/graugans/go-ovp8xx/v2/pkg/ovp8xx" + "github.com/spf13/cobra" +) + +func removeCommand(cmd *cobra.Command, args []string) error { + p := args[0] + host, err := rootCmd.PersistentFlags().GetString("ip") + if err != nil { + return err + } + + o3r := ovp8xx.NewClient( + ovp8xx.WithHost(host), + ) + + return o3r.Remove(p) +} + +// removeCmd represents the get command +var removeCmd = &cobra.Command{ + Use: "remove ", + Short: "remove the OVP8xx", + RunE: removeCommand, + Args: func(cmd *cobra.Command, args []string) error { + if len(args) != 1 { + return fmt.Errorf("requires exactly one positional argument") + } + return nil + }, +} + +func init() { + rootCmd.AddCommand(removeCmd) +} diff --git a/pkg/ovp8xx/rpc.go b/pkg/ovp8xx/rpc.go index e4604ef..f3a560d 100644 --- a/pkg/ovp8xx/rpc.go +++ b/pkg/ovp8xx/rpc.go @@ -171,6 +171,27 @@ func (device *Client) RebootToSWUpdate() error { return client.Call("rebootToRecovery", nil, nil) } +// Remove does remove an element from the device temporary configuration. +// The scope of this method is limited to the following regular expressions: +// - ^\/applications\/instances\/app\d+$ +// - ^\/device\/log\/components\/[a-zA-Z0-9\-_]+$ +// - ^\/applications\/instances\/app\d+/presets/\d+$ +// +// If an error occurs during the connection or the method call, it is returned. +func (device *Client) Remove(pointer string) error { + client, err := xmlrpc.NewClient(device.url) + if err != nil { + return err + } + defer client.Close() + + arg := &struct { + Pointer string + }{Pointer: pointer} + + return client.Call("remove", arg, nil) +} + // GetFiltered retrieves a filtered configuration from the DiagnosisClient. // It takes a Config object as input and returns a Config object and an error. func (device *DiagnosisClient) GetFiltered(conf Config) (Config, error) {