/
cmd_info.go
228 lines (211 loc) · 8.19 KB
/
cmd_info.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package cmd
import (
"github.com/MickMake/GoSungrow/iSolarCloud/api/GoStruct/output"
"fmt"
"github.com/MickMake/GoUnify/Only"
"github.com/MickMake/GoUnify/cmdHelp"
"github.com/spf13/cobra"
)
//goland:noinspection GoNameStartsWithPackageName
type CmdInfo CmdDefault
func NewCmdInfo() *CmdInfo {
var ret *CmdInfo
for range Only.Once {
ret = &CmdInfo{
Error: nil,
cmd: nil,
SelfCmd: nil,
}
}
return ret
}
func (c *CmdInfo) AttachCommand(cmd *cobra.Command) *cobra.Command {
for range Only.Once {
if cmd == nil {
break
}
c.cmd = cmd
// ******************************************************************************** //
c.SelfCmd = &cobra.Command{
Use: "info",
Aliases: []string{},
Annotations: map[string]string{"group": "Info"},
Short: fmt.Sprintf("General iSolarCloud functions."),
Long: fmt.Sprintf("General iSolarCloud functions."),
Deprecated: "show",
Hidden: true,
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
Args: cobra.MinimumNArgs(1),
}
cmd.AddCommand(c.SelfCmd)
c.SelfCmd.Example = cmdHelp.PrintExamples(c.SelfCmd, "get <endpoint>", "put <endpoint>")
// ********************************************************************************
var cmdInfoGet = &cobra.Command{
Use: "get",
Aliases: []string{output.StringTypeTable},
Annotations: map[string]string{"group": "Info"},
Short: fmt.Sprintf("Get info from iSolarCloud (table)"),
Long: fmt.Sprintf("Get info from iSolarCloud (table)"),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
Args: cobra.MinimumNArgs(1),
}
c.SelfCmd.AddCommand(cmdInfoGet)
cmdInfoGet.Example = cmdHelp.PrintExamples(cmdInfoGet, "[area.]<endpoint>")
// c.AttachCmdInfo(cmdInfoGet)
// ********************************************************************************
var cmdInfoRaw = &cobra.Command{
Use: output.StringTypeRaw,
Aliases: []string{},
Annotations: map[string]string{"group": "Info"},
Short: fmt.Sprintf("Get info from iSolarCloud (raw)"),
Long: fmt.Sprintf("Get info from iSolarCloud (raw)"),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
Args: cobra.MinimumNArgs(1),
}
c.SelfCmd.AddCommand(cmdInfoRaw)
cmdInfoRaw.Example = cmdHelp.PrintExamples(cmdInfoRaw, "[area.]<endpoint>")
// c.AttachCmdInfo(cmdInfoRaw)
// ********************************************************************************
var cmdInfoJson = &cobra.Command{
Use: output.StringTypeJson,
Aliases: []string{},
Annotations: map[string]string{"group": "Info"},
Short: fmt.Sprintf("Get info from iSolarCloud (json)"),
Long: fmt.Sprintf("Get info from iSolarCloud (json)"),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
Args: cobra.MinimumNArgs(1),
}
c.SelfCmd.AddCommand(cmdInfoJson)
cmdInfoJson.Example = cmdHelp.PrintExamples(cmdInfoJson, "[area.]<endpoint>")
// c.AttachCmdInfo(cmdInfoJson)
// ********************************************************************************
var cmdInfoCsv = &cobra.Command{
Use: output.StringTypeCsv,
Aliases: []string{},
Annotations: map[string]string{"group": "Info"},
Short: fmt.Sprintf("Get info from iSolarCloud (json)"),
Long: fmt.Sprintf("Get info from iSolarCloud (json)"),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
Args: cobra.MinimumNArgs(1),
}
c.SelfCmd.AddCommand(cmdInfoCsv)
cmdInfoCsv.Example = cmdHelp.PrintExamples(cmdInfoCsv, "[area.]<endpoint>")
// c.AttachCmdInfo(cmdInfoCsv)
// ********************************************************************************
var cmdInfoMarkDown = &cobra.Command{
Use: output.StringTypeMarkDown,
Aliases: []string{},
Annotations: map[string]string{"group": "Info"},
Short: fmt.Sprintf("Get info from iSolarCloud (MarkDown)"),
Long: fmt.Sprintf("Get info from iSolarCloud (MarkDown)"),
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
Args: cobra.MinimumNArgs(1),
}
c.SelfCmd.AddCommand(cmdInfoMarkDown)
cmdInfoMarkDown.Example = cmdHelp.PrintExamples(cmdInfoMarkDown, "[area.]<endpoint>")
// c.AttachCmdInfo(cmdInfoMarkDown)
// // ********************************************************************************
// var cmdInfoPut = &cobra.Command{
// Use: "put",
// Aliases: []string{"set", "write"},
// Annotations: map[string]string{"group": "Info"},
// Short: fmt.Sprintf("Set info on iSolarCloud"),
// Long: fmt.Sprintf("Set info on iSolarCloud"),
// DisableFlagParsing: false,
// DisableFlagsInUseLine: false,
// PreRunE: cmds.SunGrowArgs,
// Run: cmds.CmdInfoPut,
// Args: cobra.ExactArgs(2),
// }
// c.SelfCmd.AddCommand(cmdInfoPut)
// cmdInfoPut.Example = cmdHelp.PrintExamples(cmdInfoPut, "[area.]<endpoint> <value>")
}
return c.SelfCmd
}
// func (c *CmdInfo) AttachCmdInfo(cmd *cobra.Command) *cobra.Command {
// for range Only.Once {
// if cmd == nil {
// break
// }
//
// // c.AttachCmdInfoStats(cmd)
//
// // c.AttachCmdInfoRealTime(cmd)
// }
// return cmd
// }
// func (c *CmdInfo) AttachCmdInfoStats(cmd *cobra.Command) *cobra.Command {
// // ********************************************************************************
// var c2 = &cobra.Command{
// Use: "stats",
// Aliases: []string{},
// Annotations: map[string]string{"group": "Data"},
// Short: fmt.Sprintf("Get current inverter stats, (last 5 minutes)."),
// Long: fmt.Sprintf("Get current inverter stats, (last 5 minutes)."),
// DisableFlagParsing: false,
// DisableFlagsInUseLine: false,
// PreRunE: cmds.SunGrowArgs,
// RunE: func(cmd *cobra.Command, args []string) error {
// _ = cmds.SetOutputType(cmd)
// return cmds.Api.SunGrow.PrintCurrentStats()
// },
// Args: cobra.ExactArgs(0),
// }
// cmd.AddCommand(c2)
// c2.Example = cmdHelp.PrintExamples(c2, "")
//
// return cmd
// }
// func (c *CmdInfo) AttachCmdInfoRealTime(cmd *cobra.Command) *cobra.Command {
// // ********************************************************************************
// var c2 = &cobra.Command{
// Use: "real-time",
// Aliases: []string{"realtime"},
// Annotations: map[string]string{"group": "Data"},
// Short: fmt.Sprintf("Get iSolarCloud real-time data."),
// Long: fmt.Sprintf("Get iSolarCloud real-time data."),
// DisableFlagParsing: false,
// DisableFlagsInUseLine: false,
// PreRunE: cmds.SunGrowArgs,
// RunE: func(cmd *cobra.Command, args []string) error {
// _ = cmds.SetOutputType(cmd)
// args = MinimumArraySize(1, args)
// return cmds.Api.SunGrow.GetRealTimeData(args[0])
// },
// Args: cobra.RangeArgs(0, 1),
// }
// cmd.AddCommand(c2)
// c2.Example = cmdHelp.PrintExamples(c2, "")
//
// return cmd
// }