Skip to content

Commit

Permalink
feat: ✨ add the possibility to remove elements
Browse files Browse the repository at this point in the history
  • Loading branch information
graugans committed Jul 25, 2024
1 parent c1172a3 commit 4e67709
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
42 changes: 42 additions & 0 deletions cmd/ovp8xx/cmd/remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright © 2023 Christian Ege <[email protected]>
*/
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 <pointer>",
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)
}
21 changes: 21 additions & 0 deletions pkg/ovp8xx/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4e67709

Please sign in to comment.