-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vouv
committed
Nov 1, 2020
1 parent
237e45d
commit 49abe97
Showing
82 changed files
with
12,428 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,10 @@ | |
|
||
## Update Log | ||
|
||
2020.11.1 | ||
2020.11.2 | ||
|
||
- 优化新版登陆逻辑 | ||
- 优化命令行框架 | ||
- 删除无用代码 | ||
|
||
2020.9.6 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,72 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
log "github.com/sirupsen/logrus" | ||
log2 "log" | ||
"net/http" | ||
"github.com/spf13/cobra" | ||
"os" | ||
"time" | ||
) | ||
|
||
const ( | ||
Version = "v0.1.24" | ||
Timeout = 3 * time.Second | ||
) | ||
|
||
var LogLevel = log.InfoLevel | ||
const Version = "v0.1.25" | ||
|
||
var CommandMap = map[string]Func{ | ||
"config": DefaultClient.SetAccount, | ||
"login": DefaultClient.Login, | ||
"logout": DefaultClient.Logout, | ||
"info": DefaultClient.GetInfo, | ||
"update": DefaultClient.Update, | ||
var loginCmd = &cobra.Command{ | ||
Use: "login", | ||
Short: "login srun", | ||
RunE: LoginE, | ||
} | ||
|
||
"help": DefaultClient.CmdHelp, | ||
var logoutCmd = &cobra.Command{ | ||
Use: "logout", | ||
Short: "logout srun", | ||
RunE: LogoutE, | ||
} | ||
|
||
var optionDocs = map[string]string{ | ||
"-d": "Show debug message", | ||
"-v": "Print version information and quit", | ||
"-h": "Show help", | ||
var infoCmd = &cobra.Command{ | ||
Use: "info", | ||
Short: "get srun info", | ||
RunE: InfoE, | ||
} | ||
|
||
var cmdDocs = map[string][]string{ | ||
"config": {"srun config", "Set Username and Password"}, | ||
"login": {"srun [login]", "Login Srun"}, | ||
"logout": {"srun logout", "Logout Srun"}, | ||
"info": {"srun info", "Get Srun Info"}, | ||
"update": {"srun update", "Update srun"}, | ||
var configCmd = &cobra.Command{ | ||
Use: "config", | ||
Short: "config srun", | ||
RunE: ConfigE, | ||
} | ||
|
||
func main() { | ||
var debugMode bool | ||
var helpMode bool | ||
var versionMode bool | ||
var rootCmd = &cobra.Command{ | ||
Use: "srun [command]", | ||
Short: "A efficient client for BIT campus network", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if debugMode { | ||
log.SetLevel(log.DebugLevel) | ||
} | ||
return LoginE(cmd, args) | ||
}, | ||
} | ||
|
||
flag.BoolVar(&debugMode, "d", false, "debug mode") | ||
flag.BoolVar(&helpMode, "h", false, "show help") | ||
flag.BoolVar(&versionMode, "v", false, "show version") | ||
var debugMode bool | ||
|
||
flag.Parse() | ||
func main() { | ||
|
||
var cmd string | ||
var params []string | ||
rootCmd.PersistentFlags().BoolVarP(&debugMode, "debug", "d", false, "debug mode") | ||
|
||
args := flag.Args() | ||
if len(args) > 0 { | ||
cmd = args[0] | ||
params = args[1:] | ||
} else { | ||
cmd = "login" | ||
} | ||
// version | ||
rootCmd.Version = Version | ||
rootCmd.SetVersionTemplate(VersionString()) | ||
|
||
switch { | ||
case helpMode: | ||
DefaultClient.CmdHelp(cmd, args...) | ||
return | ||
case versionMode: | ||
DefaultClient.ShowVersion() | ||
return | ||
case debugMode: | ||
LogLevel = log.DebugLevel | ||
} | ||
rootCmd.AddCommand(loginCmd) | ||
rootCmd.AddCommand(logoutCmd) | ||
rootCmd.AddCommand(infoCmd) | ||
rootCmd.AddCommand(configCmd) | ||
|
||
// config | ||
http.DefaultClient.Timeout = Timeout | ||
log2.SetOutput(nil) | ||
log.SetOutput(os.Stdout) | ||
log.SetLevel(LogLevel) | ||
log.SetLevel(log.InfoLevel) | ||
log.SetFormatter(&log.TextFormatter{ | ||
//DisableTimestamp: true, | ||
TimestampFormat: "2006-01-02 15:04:05", | ||
FullTimestamp: true, | ||
}) | ||
|
||
if handle, ok := CommandMap[cmd]; ok { | ||
handle(cmd, params...) | ||
} else { | ||
DefaultClient.CmdHelp(cmd, params...) | ||
if err := rootCmd.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.