Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support go get and go install, closes #13 #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
81 changes: 38 additions & 43 deletions cmd/cmd_api.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package cmd

import (
"GoSungrow/iSolarCloud"
"GoSungrow/iSolarCloud/AppService/login"
"GoSungrow/iSolarCloud/api/GoStruct/output"
"errors"
"fmt"
"time"

"github.com/MickMake/GoSungrow/iSolarCloud"
"github.com/MickMake/GoSungrow/iSolarCloud/AppService/login"
"github.com/MickMake/GoSungrow/iSolarCloud/api/GoStruct/output"
"github.com/MickMake/GoUnify/Only"
"github.com/MickMake/GoUnify/cmdConfig"
"github.com/MickMake/GoUnify/cmdHelp"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"time"
)


const (
flagApiUrl = "host"
flagApiTimeout = "timeout"
Expand All @@ -31,27 +31,26 @@ type CmdApi struct {
CmdDefault

// iSolarCloud api
ApiTimeout time.Duration
Url string
Username string
Password string
AppKey string
LastLogin string
ApiToken string
ApiTimeout time.Duration
Url string
Username string
Password string
AppKey string
LastLogin string
ApiToken string
ApiTokenFile string
OutputType string
SaveFile bool
OutputType string
SaveFile bool

SunGrow *iSolarCloud.SunGrow
}


func NewCmdApi() *CmdApi {
var ret *CmdApi

for range Only.Once {
ret = &CmdApi {
CmdDefault: CmdDefault {
ret = &CmdApi{
CmdDefault: CmdDefault{
Error: nil,
cmd: nil,
SelfCmd: nil,
Expand Down Expand Up @@ -121,7 +120,7 @@ func (c *CmdApi) AttachCommand(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
c.Error = c.ApiLogin(true)
if c.Error != nil {
return c.Error
Expand All @@ -130,7 +129,7 @@ func (c *CmdApi) AttachCommand(cmd *cobra.Command) *cobra.Command {
c.SunGrow.Auth.Print()
return nil
},
Args: cobra.MinimumNArgs(0),
Args: cobra.MinimumNArgs(0),
}
cmdApi.AddCommand(cmdApiLogin)
cmdApiLogin.Example = cmdHelp.PrintExamples(cmdApiLogin, "")
Expand All @@ -145,12 +144,12 @@ func (c *CmdApi) AttachCommand(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
c.SunGrow.SaveAsFile = false
c.SunGrow.OutputType.SetJson()
return c.CmdApiGet(cmd, args)
},
Args: cobra.MinimumNArgs(1),
Args: cobra.MinimumNArgs(1),
}
cmdApi.AddCommand(cmdApiGet)
cmdApiGet.Example = cmdHelp.PrintExamples(cmdApiGet, "[area].<endpoint>")
Expand All @@ -165,12 +164,12 @@ func (c *CmdApi) AttachCommand(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
c.SunGrow.SaveAsFile = false
c.SunGrow.OutputType.SetRaw()
return c.CmdApiGet(cmd, args)
},
Args: cobra.MinimumNArgs(1),
Args: cobra.MinimumNArgs(1),
}
cmdApi.AddCommand(cmdApiRaw)
cmdApiRaw.Example = cmdHelp.PrintExamples(cmdApiRaw, "[area].<endpoint>")
Expand All @@ -185,12 +184,12 @@ func (c *CmdApi) AttachCommand(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
c.SunGrow.SaveAsFile = true
c.SunGrow.OutputType.SetJson()
return c.CmdApiGet(cmd, args)
},
Args: cobra.MinimumNArgs(1),
Args: cobra.MinimumNArgs(1),
}
cmdApi.AddCommand(cmdApiSave)
cmdApiSave.Example = cmdHelp.PrintExamples(cmdApiSave, "[area].<endpoint>")
Expand All @@ -205,12 +204,12 @@ func (c *CmdApi) AttachCommand(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
// c.SunGrow.SaveAsFile = true
c.SunGrow.OutputType.SetStruct()
return c.CmdApiGet(cmd, args)
},
Args: cobra.MinimumNArgs(1),
Args: cobra.MinimumNArgs(1),
}
cmdApi.AddCommand(cmdApiStruct)
cmdApiStruct.Example = cmdHelp.PrintExamples(cmdApiStruct, "[area].<endpoint>")
Expand Down Expand Up @@ -258,7 +257,6 @@ func (c *CmdApi) AttachFlags(cmd *cobra.Command, viper *viper.Viper) {
}
}


func (ca *Cmds) SunGrowArgs(cmd *cobra.Command, args []string) error {
for range Only.Once {
ca.Error = cmds.ProcessArgs(cmd, args)
Expand Down Expand Up @@ -307,7 +305,6 @@ func (ca *Cmds) SetOutputType(cmd *cobra.Command) error {
return err
}


func (c *CmdApi) CmdApi(cmd *cobra.Command, args []string) {
for range Only.Once {
if len(args) == 0 {
Expand All @@ -320,18 +317,18 @@ func (c *CmdApi) CmdApi(cmd *cobra.Command, args []string) {
func (c *CmdApi) CmdApiList(cmd *cobra.Command, args []string) {
for range Only.Once {
switch {
case len(args) == 0:
fmt.Println("Unknown sub-command.")
_ = cmd.Help()
case len(args) == 0:
fmt.Println("Unknown sub-command.")
_ = cmd.Help()

case args[0] == "endpoints":
c.Error = c.SunGrow.ListEndpoints("")
case args[0] == "endpoints":
c.Error = c.SunGrow.ListEndpoints("")

case args[0] == "areas":
c.SunGrow.ListAreas()
case args[0] == "areas":
c.SunGrow.ListAreas()

default:
c.Error = c.SunGrow.ListEndpoints(args[0])
default:
c.Error = c.SunGrow.ListEndpoints(args[0])
}
}
}
Expand Down Expand Up @@ -374,15 +371,14 @@ func (c *CmdApi) CmdApiPut(_ *cobra.Command, _ []string) {
}
}


func (c *CmdApi) ApiLogin(force bool) error {
func (c *CmdApi) ApiLogin(force bool) error {
for range Only.Once {
if c.SunGrow == nil {
c.Error = errors.New("sungrow instance not configured")
break
}

auth := login.SunGrowAuth {
auth := login.SunGrowAuth{
AppKey: c.AppKey,
UserAccount: c.Username,
UserPassword: c.Password,
Expand All @@ -399,15 +395,14 @@ func (c *CmdApi) ApiLogin(force bool) error {
c.ApiToken = c.SunGrow.GetToken()

sf := cmds.Api.SaveFile
cmds.Api.SaveFile = false // We don't want to lock this in the config.
cmds.Api.SaveFile = false // We don't want to lock this in the config.
c.Error = cmds.Unify.WriteConfig()
cmds.Api.SaveFile = sf
}
}
return c.Error
}


func MinimumArraySize(count int, args []string) []string {
var ret []string
for range Only.Once {
Expand Down
11 changes: 5 additions & 6 deletions cmd/cmd_data.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package cmd

import (
"GoSungrow/iSolarCloud"
"GoSungrow/iSolarCloud/api/GoStruct/output"
"fmt"

"github.com/MickMake/GoSungrow/iSolarCloud"
"github.com/MickMake/GoSungrow/iSolarCloud/api/GoStruct/output"
"github.com/MickMake/GoUnify/Only"
"github.com/MickMake/GoUnify/cmdHelp"
"github.com/spf13/cobra"
)


//goland:noinspection GoNameStartsWithPackageName
type CmdData CmdDefault

Expand Down Expand Up @@ -44,10 +44,10 @@ func (c *CmdData) AttachCommand(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
Args: cobra.MinimumNArgs(0),
Args: cobra.MinimumNArgs(0),
}
cmd.AddCommand(c.SelfCmd)
c.SelfCmd.Example = cmdHelp.PrintExamples(c.SelfCmd, "get <endpoint>", "put <endpoint>")
Expand Down Expand Up @@ -215,7 +215,6 @@ func (c *CmdData) AttachCommand(cmd *cobra.Command) *cobra.Command {
return c.SelfCmd
}


func (c *CmdData) GetEndpoints(cmd *cobra.Command, args []string) error {
// endpoints string, psIds string, date string
for range Only.Once {
Expand Down
13 changes: 6 additions & 7 deletions cmd/cmd_ha.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package cmd

import (
"GoSungrow/iSolarCloud"
"GoSungrow/iSolarCloud/api/GoStruct/output"
"fmt"
"strings"

"github.com/MickMake/GoSungrow/iSolarCloud"
"github.com/MickMake/GoSungrow/iSolarCloud/api/GoStruct/output"
"github.com/MickMake/GoUnify/Only"
"github.com/MickMake/GoUnify/cmdHelp"
"github.com/MickMake/GoUnify/cmdPath"
"github.com/spf13/cobra"
"strings"
)


//goland:noinspection GoNameStartsWithPackageName
type CmdHa CmdDefault

Expand Down Expand Up @@ -46,7 +46,7 @@ func (c *CmdHa) AttachCommand(cmd *cobra.Command) *cobra.Command {
DisableFlagParsing: false,
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
Args: cobra.MinimumNArgs(1),
Expand All @@ -65,15 +65,14 @@ func (c *CmdHa) AttachCommand(cmd *cobra.Command) *cobra.Command {
DisableFlagsInUseLine: false,
PreRunE: cmds.SunGrowArgs,
RunE: c.CmdLovelace,
Args: cobra.MinimumNArgs(0),
Args: cobra.MinimumNArgs(0),
}
c.SelfCmd.AddCommand(cmdHaGet)
cmdHaGet.Example = cmdHelp.PrintExamples(cmdHaGet, "[area.]<endpoint>")
}
return c.SelfCmd
}


func (c *CmdHa) CmdLovelace(cmd *cobra.Command, args []string) error {
for range Only.Once {
// if len(args) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cmd_info.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package cmd

import (
"GoSungrow/iSolarCloud/api/GoStruct/output"
"fmt"

"github.com/MickMake/GoSungrow/iSolarCloud/api/GoStruct/output"
"github.com/MickMake/GoUnify/Only"
"github.com/MickMake/GoUnify/cmdHelp"
"github.com/spf13/cobra"
)


//goland:noinspection GoNameStartsWithPackageName
type CmdInfo CmdDefault

Expand Down
Loading