Skip to content

Commit 682880d

Browse files
committed
Opt: Engineering Optimization
1 parent affa708 commit 682880d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+274
-315
lines changed

Makefile

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
PACKAGE := github.com/Driver-C/tryssh/cmd/version
1+
BIN_NAME := "tryssh"
2+
CMD_PACKAGE := github.com/Driver-C/tryssh/cmd/version
23
GO_VERSION := $(shell go version | awk '{print $$3}')
34
BUILD_TIME := $(shell date -u '+%Y-%m-%d %H:%M:%S')
45
LDFLAGS :=
@@ -12,16 +13,14 @@ ifdef VERSION
1213
endif
1314
BINARY_VERSION ?= $(GIT_TAG)
1415

15-
# Only set Version if building a tag or VERSION is set
16-
ifneq ($(BINARY_VERSION),)
17-
LDFLAGS += -X '$(PACKAGE).TrysshVersion=$(BINARY_VERSION)'
18-
else
16+
ifneq ($(BINARY_VERSION),"")
1917
# If cannot find any information that can be used as a version number, change it to debug
2018
BINARY_VERSION = "debug"
2119
endif
2220

23-
LDFLAGS += -X '$(PACKAGE).BuildGoVersion=$(GO_VERSION)'
24-
LDFLAGS += -X '$(PACKAGE).BuildTime=$(BUILD_TIME) UTC'
21+
LDFLAGS += -X '$(CMD_PACKAGE).Version=$(BINARY_VERSION)'
22+
LDFLAGS += -X '$(CMD_PACKAGE).BuildGoVersion=$(GO_VERSION)'
23+
LDFLAGS += -X '$(CMD_PACKAGE).BuildTime=$(BUILD_TIME) UTC'
2524

2625
.PHONY: default
2726
default: build
@@ -37,6 +36,7 @@ tidy: clean
3736
.PHONY: clean
3837
clean:
3938
@go clean
39+
@rm -f ./$(BIN_NAME)
4040
@rm -rf ./release
4141

4242
.PHONY: multi
@@ -45,15 +45,15 @@ multi: tidy
4545
os=$(shell echo "$(n)" | cut -d : -f 1);\
4646
arch=$(shell echo "$(n)" | cut -d : -f 2);\
4747
target_suffix=$(BINARY_VERSION)-$${os}-$${arch};\
48-
bin_name="tryssh";\
49-
if [ $${os} = "windows" ]; then bin_name="tryssh.exe"; fi;\
48+
bin_name="$(BIN_NAME)";\
49+
if [ $${os} = "windows" ]; then bin_name="$(BIN_NAME).exe"; fi;\
5050
echo "[==> Build $${os}-$${arch} start... <==]";\
5151
mkdir -p ./release/$${os}-$${arch};\
5252
cp ./LICENSE ./release/$${os}-$${arch}/;\
5353
env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} go build -v -trimpath -ldflags "$(LDFLAGS)" \
5454
-o ./release/$${os}-$${arch}/$${bin_name};\
5555
cd ./release;\
56-
zip -rq tryssh-$${target_suffix}.zip $${os}-$${arch};\
56+
zip -rq $(BIN_NAME)-$${target_suffix}.zip $${os}-$${arch};\
5757
rm -rf $${os}-$${arch};\
5858
cd ..;\
5959
echo "[==> Build $${os}-$${arch} done <==]";\

cmd/alias/alias.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package alias
22

33
import (
4-
"github.com/Driver-C/tryssh/cmd/alias/list"
5-
"github.com/Driver-C/tryssh/cmd/alias/set"
6-
"github.com/Driver-C/tryssh/cmd/alias/unset"
74
"github.com/spf13/cobra"
85
)
96

@@ -13,8 +10,8 @@ func NewAliasCommand() *cobra.Command {
1310
Short: "Set, unset, and list aliases, aliases can be used to log in to servers",
1411
Long: "Set, unset, and list aliases, aliases can be used to log in to servers",
1512
}
16-
aliasCmd.AddCommand(list.NewAliasListCommand())
17-
aliasCmd.AddCommand(set.NewAliasSetCommand())
18-
aliasCmd.AddCommand(unset.NewAliasUnsetCommand())
13+
aliasCmd.AddCommand(NewAliasListCommand())
14+
aliasCmd.AddCommand(NewAliasSetCommand())
15+
aliasCmd.AddCommand(NewAliasUnsetCommand())
1916
return aliasCmd
2017
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package list
1+
package alias
22

33
import (
4-
"github.com/Driver-C/tryssh/config"
5-
"github.com/Driver-C/tryssh/control/alias"
4+
"github.com/Driver-C/tryssh/pkg/config"
5+
"github.com/Driver-C/tryssh/pkg/control"
66
"github.com/spf13/cobra"
77
)
88

@@ -14,7 +14,7 @@ func NewAliasListCommand() *cobra.Command {
1414
Aliases: []string{"ls"},
1515
Run: func(cmd *cobra.Command, args []string) {
1616
configuration := config.LoadConfig()
17-
aliasController := alias.NewAliasController("", configuration, "")
17+
aliasController := control.NewAliasController("", configuration, "")
1818
aliasController.ListAlias()
1919
},
2020
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package set
1+
package alias
22

33
import (
4-
"github.com/Driver-C/tryssh/config"
5-
"github.com/Driver-C/tryssh/control/alias"
4+
"github.com/Driver-C/tryssh/pkg/config"
5+
"github.com/Driver-C/tryssh/pkg/control"
66
"github.com/spf13/cobra"
77
)
88

@@ -16,7 +16,7 @@ func NewAliasSetCommand() *cobra.Command {
1616
aliasContent := args[0]
1717
targetAddress, _ := cmd.Flags().GetString("target")
1818
configuration := config.LoadConfig()
19-
aliasController := alias.NewAliasController(targetAddress, configuration, aliasContent)
19+
aliasController := control.NewAliasController(targetAddress, configuration, aliasContent)
2020
aliasController.SetAlias()
2121
},
2222
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package unset
1+
package alias
22

33
import (
4-
"github.com/Driver-C/tryssh/config"
5-
"github.com/Driver-C/tryssh/control/alias"
4+
"github.com/Driver-C/tryssh/pkg/config"
5+
"github.com/Driver-C/tryssh/pkg/control"
66
"github.com/spf13/cobra"
77
)
88

@@ -15,7 +15,7 @@ func NewAliasUnsetCommand() *cobra.Command {
1515
Run: func(cmd *cobra.Command, args []string) {
1616
aliasContent := args[0]
1717
configuration := config.LoadConfig()
18-
aliasController := alias.NewAliasController("", configuration, aliasContent)
18+
aliasController := control.NewAliasController("", configuration, aliasContent)
1919
aliasController.UnsetAlias()
2020
},
2121
}
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
package caches
1+
package create
22

33
import (
44
"encoding/json"
5-
"github.com/Driver-C/tryssh/config"
6-
"github.com/Driver-C/tryssh/control/create"
7-
"github.com/Driver-C/tryssh/utils"
5+
"github.com/Driver-C/tryssh/pkg/config"
6+
"github.com/Driver-C/tryssh/pkg/control"
7+
"github.com/Driver-C/tryssh/pkg/utils"
88
"github.com/spf13/cobra"
99
)
1010

11-
const createType = "caches"
12-
1311
func NewCachesCommand() *cobra.Command {
1412
cachesCmd := &cobra.Command{
1513
Use: "caches <cache>",
@@ -22,7 +20,7 @@ func NewCachesCommand() *cobra.Command {
2220
newPort, _ := cmd.Flags().GetString("port")
2321
newPassword, _ := cmd.Flags().GetString("pwd")
2422
newAlias, _ := cmd.Flags().GetString("alias")
25-
newCacheContent := create.CacheContent{
23+
newCacheContent := control.CacheContent{
2624
Ip: newIp,
2725
User: newUser,
2826
Port: newPort,
@@ -35,7 +33,7 @@ func NewCachesCommand() *cobra.Command {
3533
return
3634
}
3735
configuration := config.LoadConfig()
38-
createCtl := create.NewCreateController(createType, string(contentJson), configuration)
36+
createCtl := control.NewCreateController(control.TypeCaches, string(contentJson), configuration)
3937
createCtl.ExecuteCreate()
4038
},
4139
}

cmd/create/create.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package create
22

33
import (
4-
"github.com/Driver-C/tryssh/cmd/create/caches"
5-
"github.com/Driver-C/tryssh/cmd/create/passwords"
6-
"github.com/Driver-C/tryssh/cmd/create/ports"
7-
"github.com/Driver-C/tryssh/cmd/create/users"
84
"github.com/spf13/cobra"
95
)
106

@@ -15,10 +11,10 @@ func NewCreateCommand() *cobra.Command {
1511
Long: "Create alternate username, port number, password, and login cache information",
1612
Aliases: []string{"cre", "crt", "add"},
1713
}
18-
createCmd.AddCommand(users.NewUsersCommand())
19-
createCmd.AddCommand(ports.NewPortsCommand())
20-
createCmd.AddCommand(passwords.NewPasswordsCommand())
21-
createCmd.AddCommand(caches.NewCachesCommand())
14+
createCmd.AddCommand(NewUsersCommand())
15+
createCmd.AddCommand(NewPortsCommand())
16+
createCmd.AddCommand(NewPasswordsCommand())
17+
createCmd.AddCommand(NewCachesCommand())
2218
createCmd.AddCommand(NewKeysCommand())
2319
return createCmd
2420
}

cmd/create/keys.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package create
22

33
import (
4-
"github.com/Driver-C/tryssh/config"
5-
"github.com/Driver-C/tryssh/control/create"
4+
"github.com/Driver-C/tryssh/pkg/config"
5+
"github.com/Driver-C/tryssh/pkg/control"
66
"github.com/spf13/cobra"
77
)
88

9-
const createType = "keys"
10-
119
func NewKeysCommand() *cobra.Command {
1210
cmd := &cobra.Command{
1311
Use: "keys <keyFilePath>",
@@ -18,7 +16,7 @@ func NewKeysCommand() *cobra.Command {
1816
Run: func(cmd *cobra.Command, args []string) {
1917
keyPath := args[0]
2018
configuration := config.LoadConfig()
21-
ctl := create.NewCreateController(createType, keyPath, configuration)
19+
ctl := control.NewCreateController(control.TypeKeys, keyPath, configuration)
2220
ctl.ExecuteCreate()
2321
},
2422
}
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
package passwords
1+
package create
22

33
import (
4-
"github.com/Driver-C/tryssh/config"
5-
"github.com/Driver-C/tryssh/control/create"
4+
"github.com/Driver-C/tryssh/pkg/config"
5+
"github.com/Driver-C/tryssh/pkg/control"
66
"github.com/spf13/cobra"
77
)
88

9-
const createType = "passwords"
10-
119
func NewPasswordsCommand() *cobra.Command {
1210
passwordsCmd := &cobra.Command{
1311
Use: "passwords <password>",
@@ -18,7 +16,7 @@ func NewPasswordsCommand() *cobra.Command {
1816
Run: func(cmd *cobra.Command, args []string) {
1917
password := args[0]
2018
configuration := config.LoadConfig()
21-
createCtl := create.NewCreateController(createType, password, configuration)
19+
createCtl := control.NewCreateController(control.TypePasswords, password, configuration)
2220
createCtl.ExecuteCreate()
2321
},
2422
}
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
package ports
1+
package create
22

33
import (
4-
"github.com/Driver-C/tryssh/config"
5-
"github.com/Driver-C/tryssh/control/create"
4+
"github.com/Driver-C/tryssh/pkg/config"
5+
"github.com/Driver-C/tryssh/pkg/control"
66
"github.com/spf13/cobra"
77
)
88

9-
const createType = "ports"
10-
119
func NewPortsCommand() *cobra.Command {
1210
portsCmd := &cobra.Command{
1311
Use: "ports <port>",
@@ -18,7 +16,7 @@ func NewPortsCommand() *cobra.Command {
1816
Run: func(cmd *cobra.Command, args []string) {
1917
port := args[0]
2018
configuration := config.LoadConfig()
21-
createCtl := create.NewCreateController(createType, port, configuration)
19+
createCtl := control.NewCreateController(control.TypePorts, port, configuration)
2220
createCtl.ExecuteCreate()
2321
},
2422
}

0 commit comments

Comments
 (0)