From 557a06430d84f779875e1539f9d9d7c434e4099c Mon Sep 17 00:00:00 2001 From: David Florness Date: Thu, 3 Feb 2022 23:52:16 -0500 Subject: [PATCH] Switch from cmdtab to cmdbox The latter is a rewrite of the former by the same author. > CmdBox originally started as cmdtab and was used for more than two years > before Rob realized BusyBox was even a thing. The name was changed when it > became clear just how close to BusyBox CmdBox is in approach and purpose, even > if the design and implementation are completely different. https://github.com/rwxrob/cmdbox#does-this-have-anything-to-do-with-busybox --- autojoin/cmd.go | 10 +++++----- deletemsgs/cmd.go | 14 +++++++------- echo/cmd.go | 12 ++++++------ go.mod | 2 +- go.sum | 8 +++++--- main.go | 13 +++++++------ 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/autojoin/cmd.go b/autojoin/cmd.go index 4981769..7c8ed40 100644 --- a/autojoin/cmd.go +++ b/autojoin/cmd.go @@ -3,7 +3,7 @@ package autojoin import ( "fmt" - "github.com/rwxrob/cmdtab" + "github.com/rwxrob/cmdbox" "git.hnitbjorg.xyz/~edwargix/axon/shared" "maunium.net/go/mautrix" @@ -11,12 +11,12 @@ import ( ) func init() { - x := cmdtab.New("autojoin") - x.Summary = "wait for room invitations and automatically join" + cmd := cmdbox.Add("axon autojoin") + cmd.Summary = "wait for room invitations and automatically join" - x.Method = func(args []string) error { + cmd.Method = func(args []string) error { if len(args) != 0 { - return x.UsageError() + return cmd.UsageError() } return autojoin() } diff --git a/deletemsgs/cmd.go b/deletemsgs/cmd.go index 259e75d..4cc19dc 100644 --- a/deletemsgs/cmd.go +++ b/deletemsgs/cmd.go @@ -5,33 +5,33 @@ import ( "os" "git.hnitbjorg.xyz/~edwargix/axon/shared" - "github.com/rwxrob/cmdtab" + "github.com/rwxrob/cmdbox" "maunium.net/go/mautrix" "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/id" ) func init() { - x := cmdtab.New("deletemsgs") - x.Summary = `delete the messages with the given types that were sent by us (or + cmd := cmdbox.Add("deletemsgs") + cmd.Summary = `delete the messages with the given types that were sent by us (or everyone) to the given room` - x.Usage = `[-a] + + cmd.Usage = `[-a] + -a delete all messages of the given types in the room, not just those that were sent by us ` - x.Method = func(args []string) error { + cmd.Method = func(args []string) error { all := false if len(args) < 2 || args[0] == "-h" { - return x.UsageError() + return cmd.UsageError() } if args[0] == "-a" { all = true args = args[1:] } if len(args) < 2 { - return x.UsageError() + return cmd.UsageError() } roomID := id.RoomID(args[0]) types := args[1:] diff --git a/echo/cmd.go b/echo/cmd.go index a408aa8..25d4a81 100644 --- a/echo/cmd.go +++ b/echo/cmd.go @@ -4,20 +4,20 @@ import ( "fmt" "git.hnitbjorg.xyz/~edwargix/axon/shared" - "github.com/rwxrob/cmdtab" + "github.com/rwxrob/cmdbox" "maunium.net/go/mautrix" "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/id" ) func init() { - x := cmdtab.New("echo") - x.Summary = "print all events, optionally filtering for a specific room" - x.Usage = "[]" + cmd := cmdbox.Add("echo") + cmd.Summary = "print all events, optionally filtering for a specific room" + cmd.Usage = "[]" - x.Method = func(args []string) error { + cmd.Method = func(args []string) error { if len(args) > 1 || (len(args) > 0 && args[0] == "-h") { - return x.UsageError() + return cmd.UsageError() } var roomID *id.RoomID if len(args) == 1 { diff --git a/go.mod b/go.mod index 89717c2..7f25be3 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.16 require ( github.com/kyoh86/xdg v1.2.0 - github.com/rwxrob/cmdtab v0.10.2 + github.com/rwxrob/cmdbox v0.5.0 golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a golang.org/x/net v0.0.0-20210521195947-fe42d452be8f // indirect golang.org/x/sys v0.0.0-20210521203332-0cec03c779c1 // indirect diff --git a/go.sum b/go.sum index 847aead..cd48c71 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/rwxrob/cmdtab v0.10.2 h1:DElMFAqlJcfXTiZUSgU/c2AHAdRbxpOYQdYLvMpjF3k= -github.com/rwxrob/cmdtab v0.10.2/go.mod h1:AZ16dJkvySlkGy2PBZDcUcRdar+SLv7t1an8OOKkOag= +github.com/rwxrob/cmdbox v0.5.0 h1:5wbZo1l+0yiFsr9ppD5HcmXbSXIhLcmaCJqKXtCFJdU= +github.com/rwxrob/cmdbox v0.5.0/go.mod h1:OBRzTIUTlpGictLK7OuKJoF0SBJxA1/GdUwLDz0GcpA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -68,13 +68,15 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= maunium.net/go/maulogger/v2 v2.2.4/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A= maunium.net/go/mautrix v0.9.12 h1:iNsKOCyK/BqN6Q/7A1aLj1B0/lMbr81LIg+Lry1Vjuo= maunium.net/go/mautrix v0.9.12/go.mod h1:7IzKfWvpQtN+W2Lzxc0rLvIxFM3ryKX6Ys3S/ZoWbg8= diff --git a/main.go b/main.go index ecd1578..5b32d03 100644 --- a/main.go +++ b/main.go @@ -4,14 +4,15 @@ import ( _ "git.hnitbjorg.xyz/~edwargix/axon/autojoin" _ "git.hnitbjorg.xyz/~edwargix/axon/deletemsgs" _ "git.hnitbjorg.xyz/~edwargix/axon/echo" - "github.com/rwxrob/cmdtab" + "github.com/rwxrob/cmdbox" ) func main() { - x := cmdtab.New("axon", "autojoin", "deletemsgs", "echo") - x.Summary = "a set of simple utility programs for the Matrix Client-Server API" - x.Usage = "" - x.Version = "v0.0.0" + cmd := cmdbox.Add("axon", "autojoin", "deletemsgs", "echo") + cmd.Summary = "a set of simple utility programs for the Matrix Client-Server API" + cmd.Usage = "" + cmd.Version = "v0.0.0" + cmd.Add() - cmdtab.Execute("axon") + cmdbox.Execute("axon") } -- 2.38.4