Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 1.4.0 #15

Merged
merged 8 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/hooks/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

git push
2 changes: 1 addition & 1 deletion .github/hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

#Step 1: lint
gofmt -w -s $(git rev-parse --show-toplevel)
golangci-lint run
#golangci-lint run
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
run:

linters-settings:
maligned:
suggest-new: true
gocritic:
disabled-checks:
- singleCaseSwitch

linters:
disable:
- gochecknoglobals
enable-all: true
1 change: 1 addition & 0 deletions cmd/bbhj.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

var envCommand = &cobra.Command{
Use: "env",
Short: "show env",
Long: "Show Enviroment",
Long: "Show Environment",
DisableFlagParsing: true,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("adb_config=~/.adb/config.json")
Expand Down
3 changes: 2 additions & 1 deletion cmd/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"log"
"os/exec"
"strings"

"github.com/spf13/cobra"
)

var hostCommand = &cobra.Command{
Expand Down
72 changes: 69 additions & 3 deletions cmd/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ var gitInitCommand = &cobra.Command{
Long: "git operation",
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()
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")

},
}

Expand Down Expand Up @@ -55,9 +69,18 @@ var brewInitCommand = &cobra.Command{
Short: "brew operation",
Long: "brew operation",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("brew outdated")
fmt.Println("brew tap aidb/taps")
fmt.Println("brew install adb")
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()
},
}

Expand All @@ -71,3 +94,46 @@ var githubInitCommand = &cobra.Command{
fmt.Println("gh --repo bbhj/lbs issue view 1")
},
}

var vimInitCommand = &cobra.Command{
Use: "vim",
Short: "vim configuration",
Long: "vim configuration",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("VIM Common Plugins:")
fmt.Println("")
fmt.Printf("\tgit clone %s %s\n",
"http://github.com/fatih/vim-go.git",
"~/.vim/pack/plugins/start/vim-go",
)
},
}

var osinitCommand = &cobra.Command{
Use: "osinit",
Short: "init linux os",
Long: "init linux os",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("User-Data for Cloud Server(EC2/CVM/ECS)")
fmt.Println("")
fmt.Println("\tcurl https://init.airdb.host/osinit/ubuntu_init.sh | bash -")
},
}

var kubeCommand = &cobra.Command{
Use: "kube",
Short: "kubeneters command",
Long: "kubeneters command",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("kubeneters and helm commands)")
fmt.Println("")
fmt.Println("\tsudo snap install helm --classic")
fmt.Println("")
fmt.Println("\thelm plugin install https://github.com/airdb/helm-kube")
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("\thelm install chart airdb/mychat")
fmt.Println("\thelm install chart airdb/mychat --dry-run --debug")
},
}
1 change: 1 addition & 0 deletions cmd/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var mysqlCommand = &cobra.Command{
}

func mysql(args []string) {
fmt.Println("args: ", args)
for dbname, item := range config.GetDatabases() {
host, port, _ := net.SplitHostPort(item.Address)
if item.Default {
Expand Down
5 changes: 3 additions & 2 deletions cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/imroc/req"
"github.com/spf13/cobra"
"log"
"os/exec"
"strings"

"github.com/imroc/req"
"github.com/spf13/cobra"
)

var releaseCommand = &cobra.Command{
Expand Down
8 changes: 5 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var rootCmd = &cobra.Command{
},
}

func init() {
func Execute() {
rootCmd.AddCommand(versionCommand)
rootCmd.AddCommand(sshCommand)
rootCmd.AddCommand(sftpCommand)
Expand All @@ -25,20 +25,22 @@ func init() {
rootCmd.AddCommand(releaseCommand)
rootCmd.AddCommand(mysqlCommand)
rootCmd.AddCommand(updateCommand)
rootCmd.AddCommand(completionBashCommand)
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)

rootCmd.AddCommand(loginCommand)
rootCmd.AddCommand(weatherCommand)
rootCmd.AddCommand(wikiCommand)
}

func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
30 changes: 5 additions & 25 deletions cmd/scaffold.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package cmd

import (
"bytes"
"fmt"
"html/template"
"io"
"os"
"os/exec"
"path/filepath"
"strings"

Expand All @@ -17,32 +15,13 @@ const (
GoScaffoldPath = "src/github.com/catchplay/scaffold"
)

func init() {
cmd := exec.Command("go", "env", "GOPATH")

var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
fmt.Println("please install golang at first.")
fmt.Println("Thanks for using adb tool!")

return
}

Gopath := strings.Trim(out.String(), "\n")

if Gopath == "" {
panic("cannot find $GOPATH environment variable")
}
}

var Gopath string

type scaffold struct {
debug bool
}

// nolint:golint
func New(debug bool) *scaffold {
return &scaffold{debug: debug}
}
Expand All @@ -53,7 +32,6 @@ func (s *scaffold) Generate(path string) error {
return err
}
projectName := filepath.Base(genAbsDir)
//TODO: have to check path MUST be under the $GOPATH/src folder
goProjectPath := strings.TrimPrefix(genAbsDir, filepath.Join(Gopath, "src")+"test")

d := data{
Expand Down Expand Up @@ -113,6 +91,7 @@ func (s *scaffold) genFromTemplate(templateSets []templateSet, d data) error {
return nil
}

// nolint: gosec
func unescaped(x string) interface{} { return template.HTML(x) }

func (s *scaffold) tmplExec(tmplSet templateSet, d data) error {
Expand Down Expand Up @@ -154,7 +133,9 @@ func (templEngine *templateEngine) visit(path string, f os.FileInfo, err error)
templateFileName := filepath.Base(path)

genFileBaeName := strings.TrimSuffix(templateFileName, ".tmpl") + ".go"
genFileBasePath, err := filepath.Rel(filepath.Join(Gopath, GoScaffoldPath, "template"), filepath.Join(filepath.Dir(path), genFileBaeName))
genFileBasePath, err := filepath.Rel(
filepath.Join(Gopath, GoScaffoldPath, "template"),
filepath.Join(filepath.Dir(path), genFileBaeName))
if err != nil {
return pkgErr.WithStack(err)
}
Expand All @@ -166,7 +147,6 @@ func (templEngine *templateEngine) visit(path string, f os.FileInfo, err error)
}

templEngine.Templates = append(templEngine.Templates, templ)

} else if mode := f.Mode(); mode.IsRegular() {
templateFileName := filepath.Base(path)

Expand Down
3 changes: 0 additions & 3 deletions cmd/scaffold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ package cmd
import (
"fmt"
"io/ioutil"
// "os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
)

func TestScaffold(t *testing.T) {

t.Log("xxx")
// 1tempDir, err := ioutil.TempDir(filepath.Join(Gopath, "src"), "test")
tempDir, err := ioutil.TempDir(filepath.Join("/tmp", "src"), "test")

Expand Down
5 changes: 3 additions & 2 deletions cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cmd

import (
"fmt"
"github.com/spf13/cobra"
"os"
"os/exec"
"strings"

"github.com/spf13/cobra"
)

var sshCommand = &cobra.Command{
Expand All @@ -31,7 +32,7 @@ var sftpCommand = &cobra.Command{
const (
CommandSSH = "ssh"
CommandSFTP = "sftp"
DefaultSshUser = "ubuntu"
DefaultSSHUser = "ubuntu"
)

const domainZone = "airdb.host"
Expand Down
30 changes: 27 additions & 3 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package cmd

import (
"fmt"
"github.com/imroc/req"
"github.com/spf13/cobra"
"log"
"os"
"os/exec"
"runtime"

"github.com/imroc/req"
"github.com/spf13/cobra"
)

var updateCommand = &cobra.Command{
Expand All @@ -25,7 +26,7 @@ func update() {
if runtime.GOOS == "darwin" {
dl = dl + "-" + runtime.GOOS
}
fmt.Printf("It will take about 1 minute for downloading.\nDonwload url: %s\n", dl)
fmt.Printf("It will take about 1 minute for downloading.\nDownload url: %s\n", dl)

resp, err := req.Get(dl)
tmpPath := "/tmp/adb-latest"
Expand Down Expand Up @@ -58,3 +59,26 @@ func updateBinary(tmpPath string) error {

return err
}

// completionCmd represents the completion command
var completionBashCommand = &cobra.Command{
Use: "completion",
Short: "Generates bash completion scripts",
Long: `To load completion run

. <(bitbucket completion)

To configure your bash shell to load completions for each session add to your bashrc

# MacOS:
# adb completion >/usr/local/etc/bash_completion.d/adb
# ~/.bashrc or ~/.profile
. <(bitbucket completion)
`,
Run: func(cmd *cobra.Command, args []string) {
err := rootCmd.GenBashCompletion(os.Stdout)
if err != nil {
fmt.Println("Generates bash completion scripts failed!")
}
},
}
Loading