Skip to content

Commit

Permalink
出错不打印Usage
Browse files Browse the repository at this point in the history
  • Loading branch information
vouv committed Jan 2, 2021
1 parent cc2bf86 commit 179fd44
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
27 changes: 27 additions & 0 deletions cmd/srun/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import (
"github.com/vouv/srun/store"
)

func Login(cmd *cobra.Command, args []string) {
err := LoginE(cmd, args)
if err != nil {
log.Error(err)
}
}

func LoginE(cmd *cobra.Command, args []string) error {
account, err := store.ReadAccount()
if err != nil {
Expand All @@ -30,6 +37,13 @@ func LoginE(cmd *cobra.Command, args []string) error {
return store.WriteAccount(account)
}

func Logout(cmd *cobra.Command, args []string) {
err := LogoutE(cmd, args)
if err != nil {
log.Error(err)
}
}

func LogoutE(cmd *cobra.Command, args []string) error {
var err error
account, err := store.ReadAccount()
Expand All @@ -44,6 +58,13 @@ func LogoutE(cmd *cobra.Command, args []string) error {
return store.WriteAccount(account)
}

func Info(cmd *cobra.Command, args []string) {
err := InfoE(cmd, args)
if err != nil {
log.Error(err)
}
}

func InfoE(cmd *cobra.Command, args []string) error {
info, err := core.Info()
if err != nil {
Expand All @@ -53,6 +74,12 @@ func InfoE(cmd *cobra.Command, args []string) error {
return nil
}

func Config(cmd *cobra.Command, args []string) {
err := ConfigE(cmd, args)
if err != nil {
log.Error(err)
}
}
func ConfigE(cmd *cobra.Command, args []string) error {

in := os.Stdin
Expand Down
12 changes: 6 additions & 6 deletions cmd/srun/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ import (
"github.com/spf13/cobra"
)

const Version = "v1.1.4"
const Version = "v1.1.5"

var loginCmd = &cobra.Command{
Use: "login",
Short: "Login srun",
RunE: LoginE,
Run: Login,
}

var logoutCmd = &cobra.Command{
Use: "logout",
Short: "Logout srun",
RunE: LogoutE,
Run: Logout,
}

var infoCmd = &cobra.Command{
Use: "info",
Short: "Get srun info",
RunE: InfoE,
Run: Info,
}

var configCmd = &cobra.Command{
Use: "config",
Short: "Config srun",
RunE: ConfigE,
Run: Config,
}

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -63,7 +63,7 @@ func main() {
log.SetOutput(os.Stdout)
log.SetLevel(log.InfoLevel)
log.SetFormatter(&log.TextFormatter{
//DisableTimestamp: true,
// DisableTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
})
Expand Down

0 comments on commit 179fd44

Please sign in to comment.