Skip to content

Commit

Permalink
Merge pull request #33 from airdb/dev
Browse files Browse the repository at this point in the history
release new version
  • Loading branch information
webank authored Aug 2, 2020
2 parents 2cf6e13 + a2f760c commit 858de41
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 108 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()
}
106 changes: 15 additions & 91 deletions cmd/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,24 @@ 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{
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://[email protected]'.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)
},
}

Expand Down Expand Up @@ -61,29 +49,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()
},
}

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")
fmt.Println(adblib.BrewDoc)
},
}

Expand Down Expand Up @@ -131,25 +97,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)
},
}

Expand All @@ -158,17 +106,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)
},
}

Expand All @@ -177,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 2>/dev/null")
fmt.Println("\tcert -f md www.airdb.com")
fmt.Println("")
fmt.Println("\tRefer: https://github.com/genkiroid/cert")
fmt.Println(adblib.OpenSSLDoc)
},
}

Expand All @@ -194,12 +124,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)
},
}

Expand All @@ -210,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)
Expand Down
19 changes: 3 additions & 16 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,7 @@ 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)
rootCmd.AddCommand(wikiCommand)
wikiCommand.AddCommand(interviewWikiCommand)
Expand All @@ -53,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
16 changes: 16 additions & 0 deletions 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 Down
124 changes: 124 additions & 0 deletions internal/adblib/man.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
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
SELECT DISTINCT column1, column2 FROM table_name;
`)

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
`)

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://[email protected]'.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 2>/dev/null
cert -f md www.airdb.com
Refer: https://github.com/genkiroid/cert
`)
)
Loading

0 comments on commit 858de41

Please sign in to comment.