-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmdgive.go
47 lines (44 loc) · 1.3 KB
/
cmdgive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"github.com/nlm/briq-cli/briq"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func init() {
GiveBriqCmd.Flags().String("to", "", "username to give to")
GiveBriqCmd.Flags().String("message", "Have a Briq! #Rock-solid", "message to send")
GiveBriqCmd.Flags().Uint("amount", 1, "how many briqs to give")
GiveBriqCmd.MarkFlagRequired("to")
Register(&GiveBriqCmd)
}
var GiveBriqCmd = cobra.Command{
Use: "give",
Aliases: []string{"g"},
Short: "Give one or more briqs to someone, with a limit of 5",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
argTo, err := cmd.Flags().GetString("to")
cobra.CheckErr(err)
argMesg, err := cmd.Flags().GetString("message")
cobra.CheckErr(err)
argAmount, err := cmd.Flags().GetUint("amount")
cobra.CheckErr(err)
client, err := briq.NewClient(viper.GetString(viperKeyBriqSecretKey))
cobra.CheckErr(err)
user, err := client.GetUser(
cmd.Context(),
&briq.GetUserRequest{Username: argTo},
)
cobra.CheckErr(err)
for i := uint(0); i < CapBriqAmount(argAmount); i++ {
req := &briq.CreateTransactionRequest{
App: briq.AppGive,
Comment: argMesg,
To: user.Id,
}
res, err := client.CreateTransaction(cmd.Context(), req)
cobra.CheckErr(err)
cobra.CheckErr(Render(res))
}
},
}