-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
5590e3e
commit cd74985
Showing
7 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters