Skip to content

Commit

Permalink
Add meroxa functions log (#258)
Browse files Browse the repository at this point in the history
* Add `meroxa functions log`

Add `meroxa functions log`. This is part of
#244.

* Update cmd/meroxa/root/functions/logs.go

Co-authored-by: Diana Doherty <[email protected]>

* Update cmd/meroxa/root/functions/logs.go

Co-authored-by: Diana Doherty <[email protected]>

* More uuid names

Co-authored-by: Diana Doherty <[email protected]>
  • Loading branch information
owenthereal and dianadoherty authored Feb 14, 2022
1 parent 5590e3e commit cd74985
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/meroxa/root/functions/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ func (*Functions) SubCommands() []*cobra.Command {
builder.BuildCobraCommand(&List{}),
builder.BuildCobraCommand(&Describe{}),
builder.BuildCobraCommand(&Remove{}),
builder.BuildCobraCommand(&Logs{}),
}
}
80 changes: 80 additions & 0 deletions cmd/meroxa/root/functions/logs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package functions

import (
"bytes"
"context"
"errors"
"net/http"

"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/log"
"github.com/meroxa/meroxa-go/pkg/meroxa"
)

var (
_ builder.CommandWithDocs = (*Logs)(nil)
_ builder.CommandWithArgs = (*Logs)(nil)
_ builder.CommandWithClient = (*Logs)(nil)
_ builder.CommandWithLogger = (*Logs)(nil)
_ builder.CommandWithExecute = (*Logs)(nil)
)

type functionLogsClient interface {
GetFunctionLogs(ctx context.Context, nameOrUUID string) (*http.Response, error)
}

type Logs struct {
client functionLogsClient
logger log.Logger

args struct {
NameOrUUID string
}
}

func (l *Logs) Usage() string {
return "logs NAME"
}

func (l *Logs) Docs() builder.Docs {
return builder.Docs{
Short: "Print logs for a function",
}
}

func (l *Logs) Execute(ctx context.Context) error {
resp, err := l.client.GetFunctionLogs(ctx, l.args.NameOrUUID)

if err != nil {
return err
}
defer resp.Body.Close()

buf := new(bytes.Buffer)
_, err = buf.ReadFrom(resp.Body)

if err != nil {
return err
}

l.logger.Info(ctx, buf.String())

return nil
}

func (l *Logs) Logger(logger log.Logger) {
l.logger = logger
}

func (l *Logs) Client(client meroxa.Client) {
l.client = client
}

func (l *Logs) ParseArgs(args []string) error {
if len(args) < 1 {
return errors.New("requires function name or uuid")
}

l.args.NameOrUUID = args[0]
return nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/manifoldco/promptui v0.8.0
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-runewidth v0.0.10 // indirect
github.com/meroxa/meroxa-go v0.0.0-20220208195203-71ddc3133fab
github.com/meroxa/meroxa-go v0.0.0-20220214221023-2da2e3a247a7
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4
github.com/rivo/uniseg v0.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRR
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
github.com/meroxa/meroxa-go v0.0.0-20220208195203-71ddc3133fab h1:EzZzmvjyU+U/8ecHt0QmKbJQs4293wms3EeapctnBME=
github.com/meroxa/meroxa-go v0.0.0-20220208195203-71ddc3133fab/go.mod h1:HDFszURCM1cOpKE699o5Hs0T2tEIXqY+vFcsur3RiwY=
github.com/meroxa/meroxa-go v0.0.0-20220214221023-2da2e3a247a7 h1:o8QhC5o0bb6cUQN0NdYBT8AkitftZWsBZRF1Y9kXtgI=
github.com/meroxa/meroxa-go v0.0.0-20220214221023-2da2e3a247a7/go.mod h1:HDFszURCM1cOpKE699o5Hs0T2tEIXqY+vFcsur3RiwY=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
Expand Down
20 changes: 19 additions & 1 deletion vendor/github.com/meroxa/meroxa-go/pkg/meroxa/log.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/meroxa/meroxa-go/pkg/meroxa/meroxa.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ github.com/mattn/go-runewidth
# github.com/mattn/go-shellwords v1.0.12
## explicit; go 1.13
github.com/mattn/go-shellwords
# github.com/meroxa/meroxa-go v0.0.0-20220208195203-71ddc3133fab
# github.com/meroxa/meroxa-go v0.0.0-20220214221023-2da2e3a247a7
## explicit; go 1.17
github.com/meroxa/meroxa-go/pkg/meroxa
github.com/meroxa/meroxa-go/pkg/mock
Expand Down

0 comments on commit cd74985

Please sign in to comment.