Skip to content

Commit

Permalink
refactor: rebase
Browse files Browse the repository at this point in the history
Signed-off-by: 1998-felix <[email protected]>
  • Loading branch information
felixgateru committed Apr 29, 2024
1 parent 3940013 commit a8a74bd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 224 deletions.
53 changes: 11 additions & 42 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,21 @@ import (
"syscall"

coap "github.com/absmach/coap-cli/coap"
"github.com/plgd-dev/go-coap/v2/message"
coapmsg "github.com/plgd-dev/go-coap/v2/message"
"github.com/plgd-dev/go-coap/v2/message/codes"
"github.com/plgd-dev/go-coap/v2/udp/message/pool"
coapmsg "github.com/plgd-dev/go-coap/v3/message"
"github.com/plgd-dev/go-coap/v3/message/codes"
"github.com/plgd-dev/go-coap/v3/message/pool"
"github.com/spf13/cobra"
)

const (
get = "GET"
put = "PUT"
post = "POST"
delete = "DELETE"
var (
host string
port string
contentFormat int
auth string
observe bool
data string
)

const (
helpCmd = `Use "coap-cli --help" for help.`
helpMsg = `
Usage: coap-cli <method> <URL> [options]
mathod: get, put, post or delete
-o observe option - only valid with GET request (default: false)
-auth auth option sent as URI Query (default: "")
-h host (default: "localhost")
-p port (default: "5683")
-d data to be sent in POST or PUT (default: "")
-cf content format (default: 50 - JSON format))
Examples:
coap-cli get channels/0bb5ba61-a66e-4972-bab6-26f19962678f/messages/subtopic -auth 1e1017e6-dee7-45b4-8a13-00e6afeb66eb -o
coap-cli post channels/0bb5ba61-a66e-4972-bab6-26f19962678f/messages/subtopic -auth 1e1017e6-dee7-45b4-8a13-00e6afeb66eb -d "hello world"
coap-cli post channels/0bb5ba61-a66e-4972-bab6-26f19962678f/messages/subtopic -auth 1e1017e6-dee7-45b4-8a13-00e6afeb66eb -d "hello world" -h 0.0.0.0 -p 1234
`
)

func parseCode(code string) (codes.Code, error) {
switch code {
case get:
return codes.GET, nil
case put:
return codes.PUT, nil
case post:
return codes.POST, nil
case delete:
return codes.DELETE, nil
}
return 0, errors.New("Message can be GET, POST, PUT or DELETE")
}

func printMsg(m *pool.Message) {
if m != nil {
log.Printf("\nMESSAGE:\n %v", m)
Expand Down
17 changes: 12 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@ module github.com/absmach/coap-cli

go 1.22

require github.com/plgd-dev/go-coap/v2 v2.6.0
require (
github.com/plgd-dev/go-coap/v3 v3.3.3
github.com/spf13/cobra v1.8.0
)

require (
github.com/dsnet/golib/memfile v1.0.0 // indirect
github.com/pion/dtls/v2 v2.2.10 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/pion/dtls/v2 v2.2.8-0.20240201071732-2597464081c8 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/transport/v2 v2.2.4 // indirect
github.com/plgd-dev/kit/v2 v2.0.0-20211006190727-057b33161b90 // indirect
github.com/pion/transport/v3 v3.0.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.19.0 // indirect
)
Loading

0 comments on commit a8a74bd

Please sign in to comment.