goldwarden-vaultwarden-bitw.../cmd/send.go

60 lines
1.3 KiB
Go
Raw Normal View History

2024-02-04 19:34:09 +01:00
package cmd
import (
"fmt"
"os"
2024-02-04 19:34:09 +01:00
"github.com/quexten/goldwarden/ipc/messages"
"github.com/spf13/cobra"
)
var sendCmd = &cobra.Command{
Use: "send",
Short: "Commands for managing sends",
Long: `Commands for managing sends.`,
Run: func(cmd *cobra.Command, args []string) {
_ = cmd.Help()
2024-02-04 19:34:09 +01:00
},
}
var sendCreateCmd = &cobra.Command{
Use: "create",
Short: "Uploads a Bitwarden send.",
Long: `Uploads a Bitwarden send.`,
Run: func(cmd *cobra.Command, args []string) {
2024-03-15 16:22:45 +01:00
err := loginIfRequired()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
2024-02-04 19:34:09 +01:00
name, _ := cmd.Flags().GetString("name")
text, _ := cmd.Flags().GetString("text")
result, err := commandClient.SendToAgent(messages.CreateSendRequest{
Name: name,
Text: text,
})
if err != nil {
handleSendToAgentError(err)
return
}
switch result.(type) {
case messages.CreateSendResponse:
fmt.Println("Send created: " + result.(messages.CreateSendResponse).URL)
return
2024-02-04 19:34:09 +01:00
case messages.ActionResponse:
fmt.Println("Error: " + result.(messages.ActionResponse).Message)
2024-02-04 19:34:09 +01:00
return
}
},
}
func init() {
rootCmd.AddCommand(sendCmd)
sendCmd.AddCommand(sendCreateCmd)
sendCreateCmd.Flags().StringP("name", "n", "", "Name of the send")
sendCreateCmd.Flags().StringP("text", "t", "", "Text of the send")
}