forked from carimura/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logs.go
53 lines (47 loc) · 1.17 KB
/
logs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"context"
"fmt"
client "github.com/fnproject/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 e := err.(type) {
case *apicall.GetAppsAppCallsCallLogNotFound:
return fmt.Errorf("error: %v", e.Payload.Error.Message)
default:
return fmt.Errorf("unexpected error: %v", err)
}
}
fmt.Print(resp.Payload.Log.Log)
return nil
}