mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Rename to GitHub (#3)
* circle * Rename to github and fn->cli * Rename to github and fn->cli
This commit is contained in:
95
cli/calls.go
Normal file
95
cli/calls.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
fnclient "github.com/funcy/functions_go/client"
|
||||
apicall "github.com/funcy/functions_go/client/call"
|
||||
"github.com/funcy/functions_go/models"
|
||||
"github.com/urfave/cli"
|
||||
client "github.com/fnproject/fn/cli/client"
|
||||
)
|
||||
|
||||
type callsCmd struct {
|
||||
client *fnclient.Functions
|
||||
}
|
||||
|
||||
func calls() cli.Command {
|
||||
c := callsCmd{client: client.APIClient()}
|
||||
|
||||
return cli.Command{
|
||||
Name: "calls",
|
||||
Usage: "manage function calls",
|
||||
Subcommands: []cli.Command{
|
||||
{
|
||||
Name: "get",
|
||||
Aliases: []string{"g"},
|
||||
Usage: "get function call info",
|
||||
ArgsUsage: "<call-id>",
|
||||
Action: c.get,
|
||||
},
|
||||
{
|
||||
Name: "list",
|
||||
Aliases: []string{"l"},
|
||||
Usage: "list all calls for specific route",
|
||||
ArgsUsage: "<app> <route>",
|
||||
Action: c.list,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func printCalls(calls []*models.Call) {
|
||||
for _, call := range calls {
|
||||
fmt.Println(fmt.Sprintf(
|
||||
"ID: %v\n"+
|
||||
"App: %v\n"+
|
||||
"Route: %v\n"+
|
||||
"Created At: %v\n"+
|
||||
"Started At: %v\n"+
|
||||
"Completed At: %v\n"+
|
||||
"Status: %v\n",
|
||||
call.ID, call.AppName, call.Path, call.CreatedAt,
|
||||
call.StartedAt, call.CompletedAt, call.Status))
|
||||
}
|
||||
}
|
||||
|
||||
func (call *callsCmd) get(ctx *cli.Context) error {
|
||||
callID := ctx.Args().Get(0)
|
||||
params := apicall.GetCallsCallParams{
|
||||
Call: callID,
|
||||
Context: context.Background(),
|
||||
}
|
||||
resp, err := call.client.Call.GetCallsCall(¶ms)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case *apicall.GetCallsCallNotFound:
|
||||
return fmt.Errorf("error: %v", err.(*apicall.GetCallsCallNotFound).Payload.Error.Message)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
|
||||
}
|
||||
printCalls([]*models.Call{resp.Payload.Call})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (call *callsCmd) list(ctx *cli.Context) error {
|
||||
app, route := ctx.Args().Get(0), ctx.Args().Get(1)
|
||||
params := apicall.GetAppsAppCallsRouteParams{
|
||||
App: app,
|
||||
Route: route,
|
||||
Context: context.Background(),
|
||||
}
|
||||
resp, err := call.client.Call.GetAppsAppCallsRoute(¶ms)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case *apicall.GetCallsCallNotFound:
|
||||
return fmt.Errorf("error: %v", err.(*apicall.GetCallsCallNotFound).Payload.Error.Message)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
|
||||
}
|
||||
printCalls(resp.Payload.Calls)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user