From 5c9ef8e3fd285c8445a85d5f6c2a2af82511e86c Mon Sep 17 00:00:00 2001 From: deancn Date: Thu, 30 Jul 2020 01:02:18 +0800 Subject: [PATCH 1/4] update --- cmd/manual.go | 60 ++++++---------------------------- internal/adblib/man.go | 73 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 51 deletions(-) create mode 100644 internal/adblib/man.go diff --git a/cmd/manual.go b/cmd/manual.go index dad2c48..96d6724 100644 --- a/cmd/manual.go +++ b/cmd/manual.go @@ -3,13 +3,15 @@ package cmd import ( "fmt" + "github.com/airdb/adb/internal/adblib" "github.com/spf13/cobra" ) var manCommand = &cobra.Command{ - Use: "man", - Short: "man command like linux", - Long: "display manual pages", + Use: "man", + Short: "man command like linux", + Long: "display manual pages", + Example: adblib.MysqlDoc, } var gitInitCommand = &cobra.Command{ @@ -61,18 +63,7 @@ var brewInitCommand = &cobra.Command{ Short: "brew operation", Long: "brew operation", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("Brew Common Command:") - fmt.Println("\tbrew outdated") - fmt.Println("\tbrew ") - fmt.Println("\tbrew cask outdated") - fmt.Println("\tbrew outdated adb --verbose --debug") - fmt.Println("\tbrew install github/gh/gh") - fmt.Println("\tbrew install aliyun-cli") - fmt.Println() - fmt.Println("\tbrew tap aidb/taps") - fmt.Println("\tbrew install airdb/taps/adb") - fmt.Println("\tbrew install adb") - fmt.Println() + fmt.Println(adblib.BrewDoc) }, } @@ -131,25 +122,7 @@ var helmCommand = &cobra.Command{ Short: "helm command", Long: "helm command", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("helm commands)") - fmt.Println("") - fmt.Println("\tsudo apt update") - fmt.Println("\tsudo apt install snapd") - fmt.Println("\tsudo snap install helm --classic") - fmt.Println("") - fmt.Println("\thelm plugin install https://github.com/airdb/helm-kube") - fmt.Println("") - fmt.Println("\thelm repo add airdb https://www.airdb.com/helm/") - fmt.Println("\thelm repo update") - fmt.Println("\thelm search repo helm/mychart") - fmt.Println("") - fmt.Println("\thelm show readme airdb/mychat") - fmt.Println("") - fmt.Println("\thelm install chart airdb/mychat") - fmt.Println("\thelm install chart airdb/mychat --dry-run --debug") - fmt.Println("") - fmt.Println("\thelm get notes mychat") - fmt.Println("") + fmt.Println(adblib.HelmDoc) }, } @@ -158,17 +131,7 @@ var terraformCommand = &cobra.Command{ Short: "terraform command", Long: "terraform command", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("terraform commands") - fmt.Println("") - fmt.Println("\tterraform -install-autocomplete") - fmt.Println("\tterraform init -upgrade") - fmt.Println("") - fmt.Println("\tterraform validate") - fmt.Println("\tterraform plan") - fmt.Println("\tterraform apply") - fmt.Println("\t#terraform destroy") - fmt.Println("") - fmt.Println("\tRefer: https://github.com/airdb/init/tree/master/terraform") + fmt.Println(adblib.TerraformDoc) }, } @@ -194,12 +157,7 @@ var toolsCommand = &cobra.Command{ Short: "tools command", Long: "tools command", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("tools") - fmt.Println("") - fmt.Println("\tasciinema play https://asciinema.org/a/349488") - fmt.Println("\tdocker run --rm -v $PWD:/data asciinema/asciicast2gif -s 2 -t solarized-dark demo.json demo.gif") - fmt.Println("") - fmt.Println("wget https://github.com/airdb/init/releases/latest/download/tools-linux-amd64.zip") + fmt.Println(adblib.ToolsDoc) }, } diff --git a/internal/adblib/man.go b/internal/adblib/man.go new file mode 100644 index 0000000..e76ac28 --- /dev/null +++ b/internal/adblib/man.go @@ -0,0 +1,73 @@ +package adblib + +import ( + "github.com/MakeNowJust/heredoc" +) + +var ( + MysqlDoc = heredoc.Doc(` +$ mysql +> ALTER TABLE xx_tab change status process int(10) +> ALTER TABLE xx_tab modify status int(10) after id +> ALTER TABLE xx_tab modify status varchar(600) NOT NULL + `) + + ToolsDoc = heredoc.Doc(` +$ tools + asciinema play https://asciinema.org/a/349488 + docker run --rm -v $PWD:/data asciinema/asciicast2gif -s 2 -t solarized-dark demo.json demo.gif + + docker run --rm -v $PWD:/data asciinema/asciicast2gif -s 2 -t solarized-dark demo.json demo.gif +`) + + HelmDoc = heredoc.Doc(` +$ helm commands + + sudo apt update + sudo apt install snapd + sudo snap install helm --classic + + helm plugin install https://github.com/airdb/helm-kube + + helm repo add airdb https://www.airdb.com/helm/" + helm repo update + helm search repo helm/mychart + + helm show readme airdb/mychat + + helm install chart airdb/mychat + helm install chart airdb/mychat --dry-run --debug + + helm get notes mychat +`) + + TerraformDoc = heredoc.Doc(` +$ terraform commands + + terraform -install-autocomplete + terraform init -upgrade + + terraform validate + terraform plan + terraform apply + #terraform destroy + + Refer: https://github.com/airdb/init/tree/master/terraform +`) + + BrewDoc = heredoc.Docf(` +$ Brew Common Command: + + brew outdated + + brew cask outdated + brew outdated adb --verbose --debug + brew install github/gh/gh + brew install aliyun-cli + + brew tap aidb/taps + brew install airdb/taps/adb + brew install adb + +`) +) From 4f6cda8143fced0af3104b2631feaa1da99202bb Mon Sep 17 00:00:00 2001 From: Dean Date: Thu, 30 Jul 2020 09:58:32 +0800 Subject: [PATCH 2/4] update docs --- cmd/manual.go | 46 +++++-------------------------------- internal/adblib/man.go | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 40 deletions(-) diff --git a/cmd/manual.go b/cmd/manual.go index 96d6724..f9651b4 100644 --- a/cmd/manual.go +++ b/cmd/manual.go @@ -15,26 +15,12 @@ var manCommand = &cobra.Command{ } var gitInitCommand = &cobra.Command{ - Use: "git", - Short: "git operation", - Long: "git operation", + Use: "git", + Short: "git operation", + Long: "git operation", + Aliases: []string{"github", "gh"}, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("git config --global core.hooksPath .github/hooks") - fmt.Println("git config --global core.excludefile .gitignore_global") - fmt.Println("git config --global url.'ssh://git@github.com'.insteadOf https://github.com") - fmt.Println() - fmt.Println("For Close Github Issue, commit message should as follow:") - fmt.Println("\t", "close #x") - fmt.Println("\t", "closes #x") - fmt.Println("\t", "closed #x") - fmt.Println("\t", "fix #x") - fmt.Println("\t", "fixes #x") - fmt.Println("\t", "fixed #x") - fmt.Println("\t", "resolve #x") - fmt.Println("\t", "resolves #x") - fmt.Println("\t", "resolved #x") - fmt.Println("\t", "add new quick sort algorithm, fixes #4, resolve #6, closed #12") - + fmt.Println(adblib.GithubDoc) }, } @@ -67,17 +53,6 @@ var brewInitCommand = &cobra.Command{ }, } -var githubInitCommand = &cobra.Command{ - Use: "gh", - Short: "github operation", - Long: "github operation", - Run: func(cmd *cobra.Command, args []string) { - fmt.Println("brew install github/gh/gh") - fmt.Println("gh --repo bbhj/lbs issue status") - fmt.Println("gh --repo bbhj/lbs issue view 1") - }, -} - var vimInitCommand = &cobra.Command{ Use: "vim", Short: "vim configuration", @@ -140,15 +115,7 @@ var opensslCommand = &cobra.Command{ Short: "openssl command", Long: "openssl command", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("openssl commands") - fmt.Println("") - fmt.Println("\topenssl x509 -text -in ssl.chain.crt") - fmt.Println("\topenssl req -noout -text -in ssl.csr") - fmt.Println("") - fmt.Println("\topenssl s_client -servername www.airdb.com -connect www.airdb.com:443 /dev/null") - fmt.Println("\tcert -f md www.airdb.com") - fmt.Println("") - fmt.Println("\tRefer: https://github.com/genkiroid/cert") + fmt.Println(adblib.OpenSSLDoc) }, } @@ -168,7 +135,6 @@ func initManCommand() { manCommand.AddCommand(dockerInitCommand) manCommand.AddCommand(cloudInitCommand) manCommand.AddCommand(brewInitCommand) - manCommand.AddCommand(githubInitCommand) manCommand.AddCommand(vimInitCommand) manCommand.AddCommand(osinitCommand) manCommand.AddCommand(kubeCommand) diff --git a/internal/adblib/man.go b/internal/adblib/man.go index e76ac28..ef04dea 100644 --- a/internal/adblib/man.go +++ b/internal/adblib/man.go @@ -10,6 +10,8 @@ $ mysql > ALTER TABLE xx_tab change status process int(10) > ALTER TABLE xx_tab modify status int(10) after id > ALTER TABLE xx_tab modify status varchar(600) NOT NULL + +SELECT DISTINCT column1, column2 FROM table_name; `) ToolsDoc = heredoc.Doc(` @@ -69,5 +71,54 @@ $ Brew Common Command: brew install airdb/taps/adb brew install adb +`) + + GithubDoc = heredoc.Docf(` +$ Github or Git Command: + + 1. Maintain a repo without permission + git remote add upstream https://github.com/bfenetworks/bfe.git + git fetch upstream + git checkout develop + + git merge upstream/develop + + git rebase upstream/develop + + Refer: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/syncing-a-fork + + + 2. git config setting + git config --global core.hooksPath .github/hooks + git config --global core.excludefile .gitignore_global + git config --global url.'ssh://git@github.com'.insteadOf https://github.com + + 3. Github Commit. For Close Github Issue, commit message should as follow: + close #x + closes #x + closed #x + fix #x + fixes #x + fixed #x + resolve #x + resolves #x + resolved #x + add new quick sort algorithm, fixes #4, resolve #6, closed #12 + + 4. Github Command Line + brew install github/gh/gh + gh --repo bbhj/lbs issue status + gh --repo bbhj/lbs issue view 1 +`) + + OpenSSLDoc = heredoc.Doc(` +$ openssl commands + + openssl x509 -text -in ssl.chain.crt + openssl req -noout -text -in ssl.csr + openssl s_client -servername www.airdb.com -connect www.airdb.com:443 /dev/null + + cert -f md www.airdb.com + Refer: https://github.com/genkiroid/cert `) ) From fa6192ace29d1d0e30f673edee4d7d5711366783 Mon Sep 17 00:00:00 2001 From: Dean Date: Thu, 30 Jul 2020 13:37:55 +0800 Subject: [PATCH 3/4] update --- cmd/root.go | 14 -------------- internal/adblib/login.go | 1 + internal/adblib/token.go | 10 ++++++++++ 3 files changed, 11 insertions(+), 14 deletions(-) create mode 100644 internal/adblib/token.go diff --git a/cmd/root.go b/cmd/root.go index 9449000..578dc3f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,20 +23,6 @@ func Execute() { rootCmd.AddCommand(envCommand) rootCmd.AddCommand(bbhjCommand) rootCmd.AddCommand(releaseCommand) - // rootCmd.AddCommand(manCommand) - // manCommand.AddCommand(gitInitCommand) - // manCommand.AddCommand(dockerInitCommand) - // manCommand.AddCommand(cloudInitCommand) - // manCommand.AddCommand(toolsInitCommand) - // manCommand.AddCommand(brewInitCommand) - // manCommand.AddCommand(githubInitCommand) - // manCommand.AddCommand(vimInitCommand) - // manCommand.AddCommand(osinitCommand) - // manCommand.AddCommand(kubeCommand) - // manCommand.AddCommand(helmCommand) - // manCommand.AddCommand(terraformCommand) - // manCommand.AddCommand(opensslCommand) - // manCommand.AddCommand(toolsCommand) rootCmd.AddCommand(loginCommand) rootCmd.AddCommand(weatherCommand) diff --git a/internal/adblib/login.go b/internal/adblib/login.go index 721c478..6d43da9 100644 --- a/internal/adblib/login.go +++ b/internal/adblib/login.go @@ -31,6 +31,7 @@ var userLogin = []*survey.Question{ func Login() { var user User + fmt.Println(TokenRequest) // pPerform the questions. err := survey.Ask(userLogin, &user) if err != nil { diff --git a/internal/adblib/token.go b/internal/adblib/token.go new file mode 100644 index 0000000..31f54d4 --- /dev/null +++ b/internal/adblib/token.go @@ -0,0 +1,10 @@ +package adblib + +import ( + "github.com/MakeNowJust/heredoc" +) + +var TokenRequest = heredoc.Doc(` +https://sfc.baobeihuijia.com/release/oauth2/token +> +`) From a2f760cb32e78f99ba852046e1e34ab7aabad1b7 Mon Sep 17 00:00:00 2001 From: deancn Date: Mon, 3 Aug 2020 00:55:18 +0800 Subject: [PATCH 4/4] update --- cmd/login.go | 15 +++++++++++++++ cmd/root.go | 3 ++- go.mod | 2 +- go.sum | 2 ++ internal/adblib/login.go | 17 ++++++++++++++++- internal/adblib/token.go | 5 +++-- 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/cmd/login.go b/cmd/login.go index 71cc8d5..24a3ca4 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -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() } diff --git a/cmd/root.go b/cmd/root.go index 578dc3f..c42cb79 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -24,7 +24,6 @@ func Execute() { rootCmd.AddCommand(bbhjCommand) rootCmd.AddCommand(releaseCommand) - rootCmd.AddCommand(loginCommand) rootCmd.AddCommand(weatherCommand) rootCmd.AddCommand(wikiCommand) wikiCommand.AddCommand(interviewWikiCommand) @@ -39,6 +38,8 @@ func Execute() { initSlack() initManCommand() + initLogin() + updateCmdInit() if err := rootCmd.Execute(); err != nil { diff --git a/go.mod b/go.mod index a4e0fb4..be0bc26 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index ed54d82..68b3a00 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/adblib/login.go b/internal/adblib/login.go index 6d43da9..0f0990d 100644 --- a/internal/adblib/login.go +++ b/internal/adblib/login.go @@ -2,6 +2,7 @@ package adblib import ( "fmt" + "time" "github.com/AlecAivazis/survey/v2" "github.com/airdb/sailor" @@ -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{ { @@ -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 { diff --git a/internal/adblib/token.go b/internal/adblib/token.go index 31f54d4..d289547 100644 --- a/internal/adblib/token.go +++ b/internal/adblib/token.go @@ -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. `) +