Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
deancn committed Aug 2, 2020
1 parent fa6192a commit a2f760c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
15 changes: 15 additions & 0 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ var loginCommand = &cobra.Command{
},
}

var loginWithToken bool

func initLogin() {
rootCmd.AddCommand(loginCommand)

loginCommand.PersistentFlags().BoolVarP(&loginWithToken, "token", "t", false, "login with token")

// hostSSHCmd.PersistentFlags().StringVarP(&sshFlags.IdentityFile, "identity_file", "i", "~/.adb/id_rsa", "identity file")
}

func login() {
if loginWithToken {
adblib.LoginWithToken()
return
}

adblib.Login()
}
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func Execute() {
rootCmd.AddCommand(bbhjCommand)
rootCmd.AddCommand(releaseCommand)

rootCmd.AddCommand(loginCommand)
rootCmd.AddCommand(weatherCommand)
rootCmd.AddCommand(wikiCommand)
wikiCommand.AddCommand(interviewWikiCommand)
Expand All @@ -39,6 +38,8 @@ func Execute() {
initSlack()
initManCommand()

initLogin()

updateCmdInit()

if err := rootCmd.Execute(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/AlecAivazis/survey/v2 v2.0.8
github.com/MakeNowJust/heredoc v1.0.0
github.com/airdb/sailor v1.4.0-85dfa77
github.com/airdb/sailor v1.1.2-0.20200802151610-a033b3f2a246
github.com/aliyun/alibaba-cloud-sdk-go v1.61.279
github.com/imroc/req v0.2.4
github.com/mitchellh/go-homedir v1.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/airdb/sailor v1.1.2-0.20200802151610-a033b3f2a246 h1:5URmvEzDlQ5RoyiyUvrX5Ao5F7nlycdbUKoGuiVecjA=
github.com/airdb/sailor v1.1.2-0.20200802151610-a033b3f2a246/go.mod h1:Txr7LHYpg61npbaDGkfud/lRaOFEaAB1f0anzuglOmI=
github.com/airdb/sailor v1.4.0-85dfa77 h1:ieXE0OhZKknCUZU3vi2bcYoWLt3BAiFDKosBTHH35pI=
github.com/airdb/sailor v1.4.0-85dfa77/go.mod h1:Txr7LHYpg61npbaDGkfud/lRaOFEaAB1f0anzuglOmI=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down
17 changes: 16 additions & 1 deletion internal/adblib/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package adblib

import (
"fmt"
"time"

"github.com/AlecAivazis/survey/v2"
"github.com/airdb/sailor"
Expand All @@ -14,6 +15,21 @@ type User struct {
Password string `json:"password" survey:"Password" mapstructure:"password"`
}

func LoginWithToken() {
fmt.Print(TokenRequest)

var bar sailor.ProcessBar

bar.NewOption(0, 100)

for i := 0; i <= 100; i++ {
time.Sleep(100 * time.Millisecond)
bar.Play(int64(i))
}

bar.Finish()
}

// The questions to ask.
var userLogin = []*survey.Question{
{
Expand All @@ -31,7 +47,6 @@ var userLogin = []*survey.Question{
func Login() {
var user User

fmt.Println(TokenRequest)
// pPerform the questions.
err := survey.Ask(userLogin, &user)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/adblib/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

var TokenRequest = heredoc.Doc(`
https://sfc.baobeihuijia.com/release/oauth2/token
>
https://sfc.baobeihuijia.com/release/oauth2/token?request_id=f572d396fae9206628714fb2ce00f72e94f2258f
please login with Github, and wait for 30s after you login.
`)

0 comments on commit a2f760c

Please sign in to comment.