From 483ff5b293ded5394007263ab767226d186acb7a Mon Sep 17 00:00:00 2001 From: Tejus P Date: Sun, 2 Oct 2022 17:47:17 -0700 Subject: [PATCH] Update to v1.0.7 --- commands/commands.go | 64 --------------------------------------- commands/commands_test.go | 46 ---------------------------- commands/version.go | 21 ------------- commands/version_test.go | 24 --------------- go.mod | 15 ++++----- go.sum | 30 +++++++++--------- main.go | 3 +- 7 files changed, 26 insertions(+), 177 deletions(-) delete mode 100644 commands/commands.go delete mode 100644 commands/commands_test.go delete mode 100644 commands/version.go delete mode 100644 commands/version_test.go diff --git a/commands/commands.go b/commands/commands.go deleted file mode 100644 index 8217182..0000000 --- a/commands/commands.go +++ /dev/null @@ -1,64 +0,0 @@ -package commands - -import ( - "fmt" - "sync" - - cli "github.com/urfave/cli/v2" -) - -// CommandName is the name of the command -type CommandName string - -// Command is the interface that all commands must implement -type Command interface { - Name() CommandName - Aliases() []string - Usage() string - Subcommands() []*cli.Command - Flags() []cli.Flag - Action(c *cli.Context) error -} - -// CommandOpts is the options for a command -type CommandOpts struct { - // Treat all flags as normal arguments if true - SkipFlagParsing bool -} - -var ( - commandMu sync.RWMutex - commands = make(map[CommandName]*cli.Command) -) - -// RegisterCommand registers a command -func RegisterCommand(name CommandName, command Command, opts *CommandOpts) error { - commandMu.Lock() - defer commandMu.Unlock() - if command == nil { - return fmt.Errorf("command is nil") - } - if _, dup := commands[name]; dup { - return fmt.Errorf("command already registered: %s", name) - } - commands[name] = &cli.Command{ - Name: string(command.Name()), - Aliases: command.Aliases(), - Usage: command.Usage(), - Subcommands: command.Subcommands(), - Flags: command.Flags(), - Action: command.Action, - SkipFlagParsing: opts != nil && opts.SkipFlagParsing, - } - return nil -} - -// GetCommands returns the registered commands -func GetCommands() []*cli.Command { - commands["version"] = getVersion() - cmds := make([]*cli.Command, 0) - for _, command := range commands { - cmds = append(cmds, command) - } - return cmds -} diff --git a/commands/commands_test.go b/commands/commands_test.go deleted file mode 100644 index c8f388f..0000000 --- a/commands/commands_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package commands - -import ( - "reflect" - "testing" - - cli "github.com/urfave/cli/v2" -) - -func TestRegisterCommand(t *testing.T) { - type args struct { - name CommandName - command Command - opts *CommandOpts - } - tests := []struct { - name string - args args - wantErr bool - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := RegisterCommand(tt.args.name, tt.args.command, tt.args.opts); (err != nil) != tt.wantErr { - t.Errorf("RegisterCommand() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func TestGetCommands(t *testing.T) { - tests := []struct { - name string - want []*cli.Command - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := GetCommands(); !reflect.DeepEqual(got, tt.want) { - t.Errorf("GetCommands() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/commands/version.go b/commands/version.go deleted file mode 100644 index 3ceeec7..0000000 --- a/commands/version.go +++ /dev/null @@ -1,21 +0,0 @@ -package commands - -import ( - "fmt" - - cli "github.com/urfave/cli/v2" -) - -const appVersion = "v1.0.2" - -func getVersion() *cli.Command { - return &cli.Command{ - Name: "version", - Aliases: []string{"v"}, - Usage: "Print the version of zetools", - Action: func(c *cli.Context) error { - fmt.Println(appVersion) - return nil - }, - } -} diff --git a/commands/version_test.go b/commands/version_test.go deleted file mode 100644 index 1bd146c..0000000 --- a/commands/version_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package commands - -import ( - "reflect" - "testing" - - cli "github.com/urfave/cli/v2" -) - -func Test_getVersion(t *testing.T) { - tests := []struct { - name string - want *cli.Command - }{ - // TODO: Add test cases. - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := getVersion(); !reflect.DeepEqual(got, tt.want) { - t.Errorf("getVersion() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/go.mod b/go.mod index cf55bd0..ddcfdf6 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,14 @@ module github.com/tejzpr/zetools go 1.18 require ( - github.com/tejzpr/zetools-base64 v1.0.1 - github.com/tejzpr/zetools-cat v1.0.2 - github.com/tejzpr/zetools-checkport v1.0.1 - github.com/tejzpr/zetools-hmac v1.0.1 - github.com/tejzpr/zetools-ls v1.0.2 - github.com/tejzpr/zetools-ping v1.0.1 - github.com/tejzpr/zetools-tail v1.0.1 + github.com/tejzpr/commands-zetools v1.0.2 + github.com/tejzpr/zetools-base64 v1.0.2 + github.com/tejzpr/zetools-cat v1.0.3 + github.com/tejzpr/zetools-checkport v1.0.2 + github.com/tejzpr/zetools-hmac v1.0.2 + github.com/tejzpr/zetools-ls v1.0.3 + github.com/tejzpr/zetools-ping v1.0.2 + github.com/tejzpr/zetools-tail v1.0.2 github.com/urfave/cli/v2 v2.17.1 ) diff --git a/go.sum b/go.sum index 02056ef..f4d4c05 100644 --- a/go.sum +++ b/go.sum @@ -14,20 +14,22 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/tejzpr/zetools-base64 v1.0.1 h1:SjetWQ3N7v7s7TNTJBdgYbTyPT7MqLaPT3/94HUAwx0= -github.com/tejzpr/zetools-base64 v1.0.1/go.mod h1:uHVhUo02kBsdS0ggTsch79iGcKeMihRweLBmvX7ghmA= -github.com/tejzpr/zetools-cat v1.0.2 h1:emSM54LGPHD+0HckNTGRAcM1s88Ewj4yG2uGmt0g9Ks= -github.com/tejzpr/zetools-cat v1.0.2/go.mod h1:gg1NcvxE2WgcckOC3Cd3leS6sa+f8XBBPNKjZ8MUWHs= -github.com/tejzpr/zetools-checkport v1.0.1 h1:AZMJpnn10nXToYLGgushzmI6vKh28y/Dj79m1sYkWcc= -github.com/tejzpr/zetools-checkport v1.0.1/go.mod h1:i2n0MJ0Q66WOSTTja52oSCFJ64yGaFReBMavn4lowgg= -github.com/tejzpr/zetools-hmac v1.0.1 h1:KaptuDLelZJcB4E2BamMKMd4BdR0KUoHp7aqNWsqhQ4= -github.com/tejzpr/zetools-hmac v1.0.1/go.mod h1:VgdlmQqRJUTzYzvzwAc7Ldr1bhmpu9frIF+wWOWZYPM= -github.com/tejzpr/zetools-ls v1.0.2 h1:C9e28I8zryf7kGiDCI9hMfB8uyrayjgYHOiwcYygFi8= -github.com/tejzpr/zetools-ls v1.0.2/go.mod h1:tHyxTTAV5sZTMLYjnKIh+h3j7Qeb6hoZCS0qfMsEPeE= -github.com/tejzpr/zetools-ping v1.0.1 h1:ytzbNOhNg8brKEBXoBoDYTY5LzTfKyj7HRCS4nzG+GI= -github.com/tejzpr/zetools-ping v1.0.1/go.mod h1:BpANlDKErliT9E4Mw2nF/IwccwGUPZDWOb1GW6WMfSc= -github.com/tejzpr/zetools-tail v1.0.1 h1:HxB9NhY5WlI5vUGMUIBMXEKtwfq2hDGvsdazgcIHAW0= -github.com/tejzpr/zetools-tail v1.0.1/go.mod h1:JQVVanfOXDWCCDSIz6bJFAGhmmqgj/T9KbaDdql9C+w= +github.com/tejzpr/commands-zetools v1.0.2 h1:ZBccfHp0UQ0I9WQp/fKo6WtNHaOkkXmWJiREAAShPiw= +github.com/tejzpr/commands-zetools v1.0.2/go.mod h1:HFgSY/rTvNWI6MefY7N0YVlJnNiorvRHA8y2mK3LQCo= +github.com/tejzpr/zetools-base64 v1.0.2 h1:yxDwK1FJ3U8W3BD+0hgP+y/gY7ndk5AhvgxwSVc25oY= +github.com/tejzpr/zetools-base64 v1.0.2/go.mod h1:dzRF8sahtqBEacC1FZPpzV/goY9H2XGu7VKb2SeG2rE= +github.com/tejzpr/zetools-cat v1.0.3 h1:uQElNdnNJQIkpFe6JX+lG/IZfD7i2Z+7nRGulpKkOaE= +github.com/tejzpr/zetools-cat v1.0.3/go.mod h1:vIwWrP9XZeZvFYGsrHuqNC5wW/tX74sTvyskptHQnMI= +github.com/tejzpr/zetools-checkport v1.0.2 h1:y22S89AoF2iDkzw6y4lVTCgXjkj3e419oDCgzoIfglM= +github.com/tejzpr/zetools-checkport v1.0.2/go.mod h1:m1QNyRQEcjAx2vOcZKKE6G8/COsNS7gZ4Kdtvqs/oo4= +github.com/tejzpr/zetools-hmac v1.0.2 h1:84/XPBv0gXBoNNeetrqNbPShAS3pb/SX0vBViWcihRs= +github.com/tejzpr/zetools-hmac v1.0.2/go.mod h1:dg+JGaYob88Fc3LYWfQ9PdsOYuEF5ZnvC51X2wLDgJw= +github.com/tejzpr/zetools-ls v1.0.3 h1:tpzpfRGltwKI6G/Da03RbNpdw9X8JpbfmyS7/b2s/ck= +github.com/tejzpr/zetools-ls v1.0.3/go.mod h1:vjfw4dJNVq0YsUCCKT3D9/Kn4m2VYL/enE4BdhqrUq4= +github.com/tejzpr/zetools-ping v1.0.2 h1:R1hceuadwLyexsC+Um8iMxr84bYD6IRz2N+wxsh2k68= +github.com/tejzpr/zetools-ping v1.0.2/go.mod h1:gAFrwdwrfjElGgG22V6erU367okS2ZB0rYwO+gTNgL0= +github.com/tejzpr/zetools-tail v1.0.2 h1:e019LNj3SWY5nkKiFJVYz6ihnXdEOsRFNQals0XfGg0= +github.com/tejzpr/zetools-tail v1.0.2/go.mod h1:hZ0pPWjuBnzzLEtqWHTnljtUVyeTf5mkVpQyUaAS23g= github.com/urfave/cli/v2 v2.17.1 h1:UzjDEw2dJQUE3iRaiNQ1VrVFbyAtKGH3VdkMoHA58V0= github.com/urfave/cli/v2 v2.17.1/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= diff --git a/main.go b/main.go index e556546..e43f730 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/tejzpr/zetools/commands" + "github.com/tejzpr/commands-zetools" // Available command plugins _ "github.com/tejzpr/zetools-base64" @@ -21,6 +21,7 @@ import ( ) func main() { + commands.SetVersion("v1.0.7") app := &cli.App{ Usage: "Unified commandline tools for common tasks", Commands: commands.GetCommands(),