Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit 8422276

Browse files
authored
Merge pull request #1 from ingbyr/dev
2 parents 6cbfb36 + 1a7f5b9 commit 8422276

19 files changed

+186
-228
lines changed

cmd/group.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package cmd
66

77
import (
8+
"github.com/ingbyr/gohost/conf"
89
"github.com/ingbyr/gohost/host"
910
"github.com/spf13/cobra"
1011
"strings"
@@ -22,10 +23,10 @@ var (
2223
Run: func(cmd *cobra.Command, args []string) {
2324
hostName := args[0]
2425
if groupDel != "" {
25-
host.Manager.DeleteHostGroups(hostName, strings.Split(groupDel, ","))
26+
host.Manager.DeleteHostGroups(hostName, strings.Split(groupDel, conf.SepInCmd))
2627
}
2728
if groupAdd != "" {
28-
host.Manager.AddGroup(hostName, strings.Split(groupAdd, ","))
29+
host.Manager.AddGroup(hostName, strings.Split(groupAdd, conf.SepInCmd))
2930
}
3031
if groupList {
3132
host.Manager.PrintGroup(hostName)

cmd/new.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55
package cmd
66

77
import (
8+
"github.com/ingbyr/gohost/conf"
89
"github.com/ingbyr/gohost/host"
910
"github.com/spf13/cobra"
11+
"strings"
1012
)
1113

1214
var (
1315
newCmd = &cobra.Command{
1416
Use: "new",
1517
Short: "create new host file",
16-
Args: cobra.MinimumNArgs(1),
18+
Args: cobra.RangeArgs(1, 2),
1719
Run: func(cmd *cobra.Command, args []string) {
18-
host.Manager.CreateNewHost(args[0], args[1:])
20+
if len(args) == 1 {
21+
host.Manager.CreateNewHost(args[0], []string{})
22+
} else {
23+
host.Manager.CreateNewHost(args[0], strings.Split(args[1], conf.SepInCmd))
24+
}
1925
},
2026
}
2127
)

cmd/remove.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@
55
package cmd
66

77
import (
8+
"github.com/ingbyr/gohost/conf"
89
"github.com/ingbyr/gohost/host"
910
"github.com/spf13/cobra"
11+
"strings"
1012
)
1113

1214
var (
1315
removeGroup bool
1416
removeCmd = &cobra.Command{
1517
Use: "rm",
1618
Short: "Delete host or group",
19+
Args: cobra.ExactArgs(1),
1720
Run: func(cmd *cobra.Command, args []string) {
1821
if removeGroup {
19-
host.Manager.DeleteGroups(args)
22+
host.Manager.DeleteGroups(strings.Split(args[0], conf.SepInCmd))
2023
} else {
21-
host.Manager.DeleteHostsByNames(args)
24+
host.Manager.DeleteHosts(strings.Split(args[0], conf.SepInCmd))
2225
}
2326
},
2427
}

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var rootCmd = &cobra.Command{
1717
func Execute() {
1818
rootCmd.AddCommand(listCmd)
1919
rootCmd.AddCommand(editCmd)
20-
rootCmd.AddCommand(applyCmd)
20+
rootCmd.AddCommand(useCmd)
2121
rootCmd.AddCommand(newCmd)
2222
rootCmd.AddCommand(renameCmd)
2323
rootCmd.AddCommand(sysCmd)

cmd/use.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ import (
1010
)
1111

1212
var (
13-
applyCmd = &cobra.Command{
13+
useSimulateFlag bool
14+
15+
useCmd = &cobra.Command{
1416
Use: "use",
15-
Short: "apply group host to system host",
17+
Short: "use group host as system host",
1618
Args: cobra.ExactArgs(1),
1719
Run: func(cmd *cobra.Command, args []string) {
18-
host.Manager.ApplyGroup(args[0])
20+
host.Manager.ApplyGroup(args[0], useSimulateFlag)
1921
},
2022
}
2123
)
24+
25+
func init() {
26+
useCmd.PersistentFlags().BoolVarP(&useSimulateFlag, "simulate", "s", false, "just print host content")
27+
}

compile.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

3-
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o gohost-windows-32bit.exe .
4-
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o gohost-windows-64bit.exe .
3+
#CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o gohost-windows-32bit.exe .
4+
#CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o gohost-windows-64bit.exe .
55

66
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o gohost-linux-32bit .
77
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gohost-linux-64bit .
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
package _const
1+
package conf
22

33
import (
44
"os/user"
55
"path/filepath"
66
)
77

88
const (
9-
SepGroup = "_"
9+
SepGroupInFile = "_"
10+
SepInCmd = ","
1011
TmpCombinedHost = ".tmp_combined"
12+
BaseHostFileName = "base"
1113
)
1214

1315
var (
14-
BaseHostFile string
1516
BaseDir string
16-
ConfigFile string
17+
BaseHostFile string
1718
)
1819

1920
func init() {
2021
curr, err := user.Current()
2122
if err != nil {
2223
panic(err)
2324
}
25+
2426
BaseDir = filepath.Join(curr.HomeDir, ".gohost")
25-
BaseHostFile = filepath.Join(BaseDir, "base")
26-
ConfigFile = filepath.Join(BaseDir, ".conf")
27+
BaseHostFile = filepath.Join(BaseDir, "."+BaseHostFileName)
2728
}

display/display.go renamed to display/logger.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package display
66

77
import (
88
"fmt"
9-
"github.com/olekukonko/tablewriter"
109
"os"
1110
)
1211

@@ -29,9 +28,7 @@ func ErrExit(err error) {
2928
}
3029
}
3130

32-
func Table(header []string, data [][]string) {
33-
table := tablewriter.NewWriter(os.Stdout)
34-
table.SetHeader(header)
35-
table.AppendBulk(data)
36-
table.Render()
31+
func Panic(msg string, err error) {
32+
fmt.Printf("[panic] %s\n", msg)
33+
ErrExit(err)
3734
}

display/table.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
@Author: ingbyr
3+
*/
4+
5+
package display
6+
7+
import (
8+
"github.com/olekukonko/tablewriter"
9+
"os"
10+
)
11+
12+
func Table(header []string, data [][]string) {
13+
table := tablewriter.NewWriter(os.Stdout)
14+
table.SetHeader(header)
15+
table.AppendBulk(data)
16+
table.Render()
17+
}

editor/micro.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

editor/vim.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ import (
66
"os/exec"
77
)
88

9-
const (
10-
vim = "vim"
11-
noSwap = "-n"
12-
)
13-
149
func OpenByVim(filePath string) error {
10+
const vim = "vim"
11+
const noSwap = "-n"
1512
if _, err := exec.LookPath(vim); err != nil {
1613
return fmt.Errorf("please install vim before editing file\n")
1714
}

go.mod

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,7 @@ module github.com/ingbyr/gohost
33
go 1.16
44

55
require (
6-
github.com/go-errors/errors v1.4.0 // indirect
7-
github.com/ingbyr/micro/v2 v2.1.3
8-
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
9-
github.com/mattn/go-isatty v0.0.14 // indirect
106
github.com/mattn/go-runewidth v0.0.13 // indirect
11-
github.com/npat-efault/poller v2.0.0+incompatible // indirect
127
github.com/olekukonko/tablewriter v0.0.5
13-
github.com/sergi/go-diff v1.2.0 // indirect
148
github.com/spf13/cobra v1.2.1
15-
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
16-
github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 // indirect
17-
github.com/zyedidia/poller v2.0.0+incompatible // indirect
18-
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 // indirect
19-
golang.org/x/text v0.3.7 // indirect
20-
layeh.com/gopher-luar v1.0.10 // indirect
219
)

0 commit comments

Comments
 (0)