Skip to content

Commit

Permalink
fix golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
xwjdsh committed Jan 5, 2022
1 parent c4febd3 commit 35e2595
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
8 changes: 6 additions & 2 deletions cmd/manssh/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func backupCmd(c *cli.Context) error {
return printErrorWithHelp(c, err)
}
backupPath := c.Args().First()
os.MkdirAll(backupPath, os.ModePerm)
if err := os.MkdirAll(backupPath, os.ModePerm); err != nil {
return cli.NewExitError(err, 1)
}

paths, err := manssh.GetFilePaths(path)
if err != nil {
Expand All @@ -141,7 +143,9 @@ func backupCmd(c *cli.Context) error {
bp := backupPath
if p != path && strings.HasPrefix(p, pathDir) {
bp = filepath.Join(bp, strings.Replace(p, pathDir, "", 1))
os.MkdirAll(filepath.Dir(bp), os.ModePerm)
if err := os.MkdirAll(filepath.Dir(bp), os.ModePerm); err != nil {
return cli.NewExitError(err, 1)
}
}
if err := exec.Command("cp", p, bp).Run(); err != nil {
return cli.NewExitError(err, 1)
Expand Down
9 changes: 6 additions & 3 deletions cmd/manssh/kv_flag.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"fmt"
"strings"
)
Expand Down Expand Up @@ -30,6 +29,10 @@ func (kv *kvFlag) String() string {
if kv == nil {
return ""
}
jsonBytes, _ := json.Marshal(kv)
return string(jsonBytes)

item := make([]string, len(kv.m))
for k, v := range kv.m {
item = append(item, k+"="+v)
}
return strings.Join(item, ",")
}
6 changes: 5 additions & 1 deletion cmd/manssh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package main

import (
"fmt"
"log"
"os"

"github.com/urfave/cli"

"github.com/xwjdsh/manssh/utils"
)

Expand All @@ -18,7 +20,9 @@ func main() {
app.Version = version
app.Flags = flags()
app.Commands = commands()
app.Run(os.Args)
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}

func flags() []cli.Flag {
Expand Down
4 changes: 3 additions & 1 deletion cmd/manssh/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
)

func printErrorWithHelp(c *cli.Context, err error) error {
cli.ShowSubcommandHelp(c)
if err := cli.ShowSubcommandHelp(c); err != nil {
return err
}
fmt.Println()
return cli.NewExitError(err, 1)
}
Expand Down
4 changes: 3 additions & 1 deletion manssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ func Add(p string, ao *AddOption) (*HostConfig, error) {
Patterns: []*ssh_config.Pattern{pattern},
Nodes: nodes,
})
writeConfig(ao.Path, cfg)
if err := writeConfig(ao.Path, cfg); err != nil {
return nil, err
}

_, aliasMap, err = parseConfig(p)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions manssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ var (
)

func initConfig() {
os.MkdirAll(configRootDir, os.ModePerm)
os.MkdirAll(filepath.Join(configRootDir, "config.d"), os.ModePerm)
_ = os.MkdirAll(configRootDir, os.ModePerm)
_ = os.MkdirAll(filepath.Join(configRootDir, "config.d"), os.ModePerm)
if err := ioutil.WriteFile(mainConfigPath, []byte(fmt.Sprintf(mainConfigContent, configRootDir)), 0644); err != nil {
panic(err)
}
Expand Down Expand Up @@ -109,12 +109,14 @@ func TestList(t *testing.T) {
hosts, err = List(mainConfigPath, ListOption{
Keywords: []string{"Test"},
})
require.Nil(t, err)
require.Equal(t, 1, len(hosts))

hosts, err = List(mainConfigPath, ListOption{
Keywords: []string{"Test"},
IgnoreCase: true,
})
require.Nil(t, err)
require.Equal(t, 3, len(hosts))
}

Expand Down

0 comments on commit 35e2595

Please sign in to comment.