add folder commands

This commit is contained in:
Samuel Lorch 2021-09-08 11:12:34 +02:00
parent b0303103da
commit 1b129332ae
12 changed files with 432 additions and 2 deletions

57
folder/move.go Normal file
View file

@ -0,0 +1,57 @@
package folder
import (
"context"
"fmt"
"github.com/speatzle/go-passbolt-cli/util"
"github.com/speatzle/go-passbolt/helper"
"github.com/spf13/cobra"
)
// FolderMoveCmd Moves a Passbolt Folder
var FolderMoveCmd = &cobra.Command{
Use: "folder",
Short: "Moves a Passbolt Folder into a Folder",
Long: `Moves a Passbolt Folder into a Folder`,
RunE: FolderMove,
}
func init() {
FolderMoveCmd.Flags().String("id", "", "id of Folder to Move")
FolderMoveCmd.Flags().StringP("folderParentID", "f", "", "Folder in which to Move the Folder")
FolderMoveCmd.MarkFlagRequired("id")
FolderMoveCmd.MarkFlagRequired("folderParentID")
}
func FolderMove(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.MoveFolder(
ctx,
client,
id,
folderParentID,
)
if err != nil {
return fmt.Errorf("Moving Folder: %w", err)
}
return nil
}