2024-02-04 19:34:09 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-03-15 16:23:11 +01:00
|
|
|
"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) {
|
2024-03-15 16:23:11 +01:00
|
|
|
_ = 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)
|
2024-03-15 16:23:11 +01:00
|
|
|
return
|
2024-02-04 19:34:09 +01:00
|
|
|
case messages.ActionResponse:
|
2024-02-08 16:35:07 +01:00
|
|
|
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")
|
|
|
|
}
|