Merge pull request #182 from fnproject/cli-logs

Logs API support for CLI
This commit is contained in:
Reed Allman
2017-08-02 14:57:40 -07:00
committed by GitHub
2 changed files with 55 additions and 0 deletions

53
cli/logs.go Normal file
View 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(&params)
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
}

View File

@@ -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()...)