mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Merge pull request #182 from fnproject/cli-logs
Logs API support for CLI
This commit is contained in:
53
cli/logs.go
Normal file
53
cli/logs.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
client "github.com/fnproject/fn/cli/client"
|
||||||
|
fnclient "github.com/funcy/functions_go/client"
|
||||||
|
apicall "github.com/funcy/functions_go/client/operations"
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
type logsCmd struct {
|
||||||
|
client *fnclient.Functions
|
||||||
|
}
|
||||||
|
|
||||||
|
func logs() cli.Command {
|
||||||
|
c := logsCmd{client: client.APIClient()}
|
||||||
|
|
||||||
|
return cli.Command{
|
||||||
|
Name: "logs",
|
||||||
|
Usage: "manage function calls for apps",
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "get",
|
||||||
|
Aliases: []string{"g"},
|
||||||
|
Usage: "get function call log info per app",
|
||||||
|
ArgsUsage: "<app> <call-id>",
|
||||||
|
Action: c.get,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (log *logsCmd) get(ctx *cli.Context) error {
|
||||||
|
app, callID := ctx.Args().Get(0), ctx.Args().Get(1)
|
||||||
|
params := apicall.GetAppsAppCallsCallLogParams{
|
||||||
|
Call: callID,
|
||||||
|
App: app,
|
||||||
|
Context: context.Background(),
|
||||||
|
}
|
||||||
|
resp, err := log.client.Operations.GetAppsAppCallsCallLog(¶ms)
|
||||||
|
if err != nil {
|
||||||
|
switch err.(type) {
|
||||||
|
case *apicall.GetAppsAppCallsCallLogNotFound:
|
||||||
|
return fmt.Errorf("error: %v", err.(*apicall.GetAppsAppCallsCallLogNotFound).Payload.Error.Message)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("unexpected error: %v", err)
|
||||||
|
|
||||||
|
}
|
||||||
|
fmt.Print(resp.Payload.Log.Log)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ var aliases = map[string]cli.Command{
|
|||||||
"run": run(),
|
"run": run(),
|
||||||
"call": call(),
|
"call": call(),
|
||||||
"calls": calls(),
|
"calls": calls(),
|
||||||
|
"logs": logs(),
|
||||||
}
|
}
|
||||||
|
|
||||||
func aliasesFn() []cli.Command {
|
func aliasesFn() []cli.Command {
|
||||||
@@ -79,6 +80,7 @@ GLOBAL OPTIONS:
|
|||||||
lambda(),
|
lambda(),
|
||||||
version(),
|
version(),
|
||||||
calls(),
|
calls(),
|
||||||
|
logs(),
|
||||||
testfn(),
|
testfn(),
|
||||||
}
|
}
|
||||||
app.Commands = append(app.Commands, aliasesFn()...)
|
app.Commands = append(app.Commands, aliasesFn()...)
|
||||||
|
|||||||
Reference in New Issue
Block a user