OSDN Git Service

new repo
[bytom/vapor.git] / cmd / vaporcli / commands / txfeed.go
1 package commands
2
3 import (
4         "os"
5
6         "github.com/spf13/cobra"
7         jww "github.com/spf13/jwalterweatherman"
8
9         "github.com/vapor/util"
10 )
11
12 var createTransactionFeedCmd = &cobra.Command{
13         Use:   "create-transaction-feed <alias> <filter>",
14         Short: "Create a transaction feed filter",
15         Args:  cobra.ExactArgs(2),
16         Run: func(cmd *cobra.Command, args []string) {
17                 var in txFeed
18                 in.Alias = args[0]
19                 in.Filter = args[1]
20
21                 _, exitCode := util.ClientCall("/create-transaction-feed", &in)
22                 if exitCode != util.Success {
23                         os.Exit(exitCode)
24                 }
25
26                 jww.FEEDBACK.Println("Successfully created transaction feed")
27         },
28 }
29
30 var listTransactionFeedsCmd = &cobra.Command{
31         Use:   "list-transaction-feeds",
32         Short: "list all of transaction feeds",
33         Args:  cobra.NoArgs,
34         Run: func(cmd *cobra.Command, args []string) {
35                 data, exitCode := util.ClientCall("/list-transaction-feeds")
36                 if exitCode != util.Success {
37                         os.Exit(exitCode)
38                 }
39                 printJSONList(data)
40         },
41 }
42
43 var deleteTransactionFeedCmd = &cobra.Command{
44         Use:   "delete-transaction-feed <alias>",
45         Short: "Delete a transaction feed filter",
46         Args:  cobra.ExactArgs(1),
47         Run: func(cmd *cobra.Command, args []string) {
48                 var in txFeed
49                 in.Alias = args[0]
50
51                 _, exitCode := util.ClientCall("/delete-transaction-feed", &in)
52                 if exitCode != util.Success {
53                         os.Exit(exitCode)
54                 }
55
56                 jww.FEEDBACK.Println("Successfully deleted transaction feed")
57         },
58 }
59
60 var getTransactionFeedCmd = &cobra.Command{
61         Use:   "get-transaction-feed <alias>",
62         Short: "get a transaction feed by alias",
63         Args:  cobra.ExactArgs(1),
64         Run: func(cmd *cobra.Command, args []string) {
65                 var in txFeed
66                 in.Alias = args[0]
67
68                 data, exitCode := util.ClientCall("/get-transaction-feed", &in)
69                 if exitCode != util.Success {
70                         os.Exit(exitCode)
71                 }
72                 printJSON(data)
73         },
74 }
75
76 var updateTransactionFeedCmd = &cobra.Command{
77         Use:   "update-transaction-feed <alias> <fiter>",
78         Short: "Update transaction feed",
79         Args:  cobra.ExactArgs(2),
80         Run: func(cmd *cobra.Command, args []string) {
81                 var in txFeed
82                 in.Alias = args[0]
83                 in.Filter = args[1]
84
85                 if _, exitCode := util.ClientCall("/update-transaction-feed", &in); exitCode != util.Success {
86                         os.Exit(exitCode)
87                 }
88                 jww.FEEDBACK.Println("Successfully updated transaction feed")
89         },
90 }