add resource commands

This commit is contained in:
Samuel Lorch 2021-09-08 11:07:38 +02:00
parent f952b51065
commit b0303103da
14 changed files with 521 additions and 1 deletions

57
resource/move.go Normal file
View file

@ -0,0 +1,57 @@
package resource
import (
"context"
"fmt"
"github.com/speatzle/go-passbolt-cli/util"
"github.com/speatzle/go-passbolt/helper"
"github.com/spf13/cobra"
)
// ResourceMoveCmd Moves a Passbolt Resource
var ResourceMoveCmd = &cobra.Command{
Use: "resource",
Short: "Moves a Passbolt Resource into a Folder",
Long: `Moves a Passbolt Resource into a Folder`,
RunE: ResourceMove,
}
func init() {
ResourceMoveCmd.Flags().String("id", "", "id of Resource to Move")
ResourceMoveCmd.Flags().StringP("folderParentID", "f", "", "Folder in which to Move the Resource")
ResourceMoveCmd.MarkFlagRequired("id")
ResourceMoveCmd.MarkFlagRequired("folderParentID")
}
func ResourceMove(cmd *cobra.Command, args []string) error {
id, err := cmd.Flags().GetString("id")
if err != nil {
return err
}
folderParentID, err := cmd.Flags().GetString("folderParentID")
if err != nil {
return err
}
ctx := util.GetContext()
client, err := util.GetClient(ctx)
if err != nil {
return err
}
defer client.Logout(context.TODO())
cmd.SilenceUsage = true
err = helper.MoveResource(
ctx,
client,
id,
folderParentID,
)
if err != nil {
return fmt.Errorf("Moving Resource: %w", err)
}
return nil
}