mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Improve CLI core
This commit is contained in:
49
cli/apps.go
49
cli/apps.go
@@ -102,17 +102,17 @@ func (a *appsCmd) list(c *cli.Context) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
// fmt.Println("err type:", reflect.TypeOf(err))
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apiapps.GetAppsAppNotFound:
|
||||
return fmt.Errorf("error: %v", err.(*apiapps.GetAppsAppNotFound).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %v", e.Payload.Error.Message)
|
||||
case *apiapps.GetAppsAppDefault:
|
||||
return fmt.Errorf("unexpected error: %v", err.(*apiapps.GetAppsAppDefault).Payload.Error.Message)
|
||||
return fmt.Errorf("unexpected error: %v", e.Payload.Error.Message)
|
||||
case *apiapps.GetAppsDefault:
|
||||
// this is the one getting called, not sure what the one above is?
|
||||
return fmt.Errorf("unexpected error: %v", err.(*apiapps.GetAppsDefault).Payload.Error.Message)
|
||||
return fmt.Errorf("unexpected error: %v", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if len(resp.Payload.Apps) == 0 {
|
||||
@@ -139,15 +139,16 @@ func (a *appsCmd) create(c *cli.Context) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apiapps.PostAppsBadRequest:
|
||||
return fmt.Errorf("error: %v", err.(*apiapps.PostAppsBadRequest).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %v", e.Payload.Error.Message)
|
||||
case *apiapps.PostAppsConflict:
|
||||
return fmt.Errorf("error: %v", err.(*apiapps.PostAppsConflict).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %v", e.Payload.Error.Message)
|
||||
case *apiapps.PostAppsDefault:
|
||||
return fmt.Errorf("unexpected error: %v", err.(*apiapps.PostAppsDefault).Payload.Error.Message)
|
||||
return fmt.Errorf("unexpected error: %v", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("Successfully created app: ", resp.Payload.App.Name)
|
||||
@@ -215,15 +216,16 @@ func (a *appsCmd) patchApp(appName string, app *models.App) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apiapps.PatchAppsAppBadRequest:
|
||||
return errors.New(err.(*apiapps.PatchAppsAppBadRequest).Payload.Error.Message)
|
||||
return errors.New(e.Payload.Error.Message)
|
||||
case *apiapps.PatchAppsAppNotFound:
|
||||
return errors.New(err.(*apiapps.PatchAppsAppNotFound).Payload.Error.Message)
|
||||
return errors.New(e.Payload.Error.Message)
|
||||
case *apiapps.PatchAppsAppDefault:
|
||||
return errors.New(err.(*apiapps.PatchAppsAppDefault).Payload.Error.Message)
|
||||
return errors.New(e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -243,13 +245,14 @@ func (a *appsCmd) inspect(c *cli.Context) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apiapps.GetAppsAppNotFound:
|
||||
return fmt.Errorf("error: %v", err.(*apiapps.GetAppsAppNotFound).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %v", e.Payload.Error.Message)
|
||||
case *apiapps.GetAppsAppDefault:
|
||||
return fmt.Errorf("unexpected error: %v", err.(*apiapps.GetAppsAppDefault).Payload.Error.Message)
|
||||
return fmt.Errorf("unexpected error: %v", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
@@ -294,11 +297,11 @@ func (a *appsCmd) delete(c *cli.Context) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apiapps.DeleteAppsAppNotFound:
|
||||
return errors.New(err.(*apiapps.DeleteAppsAppNotFound).Payload.Error.Message)
|
||||
return errors.New(e.Payload.Error.Message)
|
||||
case *apiapps.DeleteAppsAppDefault:
|
||||
return errors.New(err.(*apiapps.DeleteAppsAppDefault).Payload.Error.Message)
|
||||
return errors.New(e.Payload.Error.Message)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
16
cli/calls.go
16
cli/calls.go
@@ -64,12 +64,12 @@ func (call *callsCmd) get(ctx *cli.Context) error {
|
||||
}
|
||||
resp, err := call.client.Call.GetAppsAppCallsCall(¶ms)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apicall.GetAppsAppCallsCallNotFound:
|
||||
return fmt.Errorf("error: %v", err.(*apicall.GetAppsAppCallsCallNotFound).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %v", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
|
||||
}
|
||||
printCalls([]*models.Call{resp.Payload.Call})
|
||||
return nil
|
||||
@@ -87,12 +87,12 @@ func (call *callsCmd) list(ctx *cli.Context) error {
|
||||
}
|
||||
resp, err := call.client.Call.GetAppsAppCalls(¶ms)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apicall.GetCallsCallNotFound:
|
||||
return fmt.Errorf("error: %v", err.(*apicall.GetCallsCallNotFound).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %v", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
|
||||
}
|
||||
printCalls(resp.Payload.Calls)
|
||||
return nil
|
||||
|
||||
@@ -166,7 +166,7 @@ func (p *deploycmd) route(c *cli.Context, ff *funcfile) error {
|
||||
|
||||
routesCmd := routesCmd{client: client.APIClient()}
|
||||
rt := &models.Route{}
|
||||
if err := routeWithFuncFile(c, ff, rt); err != nil {
|
||||
if err := routeWithFuncFile(ff, rt); err != nil {
|
||||
return fmt.Errorf("error getting route with funcfile: %s", err)
|
||||
}
|
||||
return routesCmd.putRoute(c, p.appName, ff.Path, rt)
|
||||
|
||||
@@ -47,13 +47,14 @@ type funcfile struct {
|
||||
Tests []fftest `yaml:"tests,omitempty" json:"tests,omitempty"`
|
||||
|
||||
// route specific
|
||||
Type string `yaml:"type,omitempty" json:"type,omitempty"`
|
||||
Memory uint64 `yaml:"memory,omitempty" json:"memory,omitempty"`
|
||||
Format string `yaml:"format,omitempty" json:"format,omitempty"`
|
||||
Timeout *int32 `yaml:"timeout,omitempty" json:"timeout,omitempty"`
|
||||
Path string `yaml:"path,omitempty" json:"path,omitempty"`
|
||||
Config map[string]string `yaml:"config,omitempty" json:"config,omitempty"`
|
||||
Headers map[string][]string `yaml:"headers,omitempty" json:"headers,omitempty"`
|
||||
Type string `yaml:"type,omitempty" json:"type,omitempty"`
|
||||
Memory uint64 `yaml:"memory,omitempty" json:"memory,omitempty"`
|
||||
Format string `yaml:"format,omitempty" json:"format,omitempty"`
|
||||
Timeout *int32 `yaml:"timeout,omitempty" json:"timeout,omitempty"`
|
||||
Path string `yaml:"path,omitempty" json:"path,omitempty"`
|
||||
Config map[string]string `yaml:"config,omitempty" json:"config,omitempty"`
|
||||
Headers map[string][]string `yaml:"headers,omitempty" json:"headers,omitempty"`
|
||||
IDLETimeout *int32 `yaml:"idle_timeout,omitempty" json:"idle_timeout,omitempty"`
|
||||
}
|
||||
|
||||
func (ff *funcfile) ImageName() string {
|
||||
|
||||
@@ -41,12 +41,12 @@ func (log *logsCmd) get(ctx *cli.Context) error {
|
||||
}
|
||||
resp, err := log.client.Operations.GetAppsAppCallsCallLog(¶ms)
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apicall.GetAppsAppCallsCallLogNotFound:
|
||||
return fmt.Errorf("error: %v", err.(*apicall.GetAppsAppCallsCallLogNotFound).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %v", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
|
||||
}
|
||||
fmt.Print(resp.Payload.Log.Log)
|
||||
return nil
|
||||
|
||||
@@ -181,13 +181,14 @@ func (a *routesCmd) list(c *cli.Context) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apiroutes.GetAppsAppRoutesNotFound:
|
||||
return fmt.Errorf("error: %s", err.(*apiroutes.GetAppsAppRoutesNotFound).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %s", e.Payload.Error.Message)
|
||||
case *apiroutes.GetAppsAppRoutesDefault:
|
||||
return fmt.Errorf("unexpected error: %s", err.(*apiroutes.GetAppsAppRoutesDefault).Payload.Error.Message)
|
||||
return fmt.Errorf("unexpected error: %s", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
||||
@@ -260,7 +261,7 @@ func routeWithFlags(c *cli.Context, rt *fnmodels.Route) {
|
||||
}
|
||||
}
|
||||
|
||||
func routeWithFuncFile(c *cli.Context, ff *funcfile, rt *fnmodels.Route) error {
|
||||
func routeWithFuncFile(ff *funcfile, rt *fnmodels.Route) error {
|
||||
var err error
|
||||
if ff == nil {
|
||||
ff, err = loadFuncfile()
|
||||
@@ -286,7 +287,15 @@ func routeWithFuncFile(c *cli.Context, ff *funcfile, rt *fnmodels.Route) error {
|
||||
if ff.Memory != 0 {
|
||||
rt.Memory = ff.Memory
|
||||
}
|
||||
// TODO idle_timeout? headers? config? why is a func file not a yaml unmarshal of a route?
|
||||
if rt.IDLETimeout != nil {
|
||||
rt.IDLETimeout = ff.IDLETimeout
|
||||
}
|
||||
if len(rt.Headers) != 0 {
|
||||
rt.Headers = ff.Headers
|
||||
}
|
||||
if len(rt.Config) != 0 {
|
||||
rt.Config = ff.Config
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -299,7 +308,7 @@ func (a *routesCmd) create(c *cli.Context) error {
|
||||
rt.Path = route
|
||||
rt.Image = c.Args().Get(2)
|
||||
|
||||
if err := routeWithFuncFile(c, nil, rt); err != nil {
|
||||
if err := routeWithFuncFile(nil, rt); err != nil {
|
||||
return fmt.Errorf("error getting route info: %s", err)
|
||||
}
|
||||
|
||||
@@ -328,15 +337,16 @@ func (a *routesCmd) postRoute(c *cli.Context, appName string, rt *fnmodels.Route
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apiroutes.PostAppsAppRoutesBadRequest:
|
||||
return fmt.Errorf("error: %s", err.(*apiroutes.PostAppsAppRoutesBadRequest).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %s", e.Payload.Error.Message)
|
||||
case *apiroutes.PostAppsAppRoutesConflict:
|
||||
return fmt.Errorf("error: %s", err.(*apiroutes.PostAppsAppRoutesConflict).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %s", e.Payload.Error.Message)
|
||||
case *apiroutes.PostAppsAppRoutesDefault:
|
||||
return fmt.Errorf("unexpected error: %s", err.(*apiroutes.PostAppsAppRoutesDefault).Payload.Error.Message)
|
||||
return fmt.Errorf("unexpected error: %s", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
|
||||
fmt.Println(resp.Payload.Route.Path, "created with", resp.Payload.Route.Image)
|
||||
@@ -352,15 +362,16 @@ func (a *routesCmd) patchRoute(c *cli.Context, appName, routePath string, r *fnm
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apiroutes.PatchAppsAppRoutesRouteBadRequest:
|
||||
return fmt.Errorf("error: %s", err.(*apiroutes.PatchAppsAppRoutesRouteBadRequest).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %s", e.Payload.Error.Message)
|
||||
case *apiroutes.PatchAppsAppRoutesRouteNotFound:
|
||||
return fmt.Errorf("error: %s", err.(*apiroutes.PatchAppsAppRoutesRouteNotFound).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %s", e.Payload.Error.Message)
|
||||
case *apiroutes.PatchAppsAppRoutesRouteDefault:
|
||||
return fmt.Errorf("unexpected error: %s", err.(*apiroutes.PatchAppsAppRoutesRouteDefault).Payload.Error.Message)
|
||||
return fmt.Errorf("unexpected error: %s", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -374,13 +385,14 @@ func (a *routesCmd) putRoute(c *cli.Context, appName, routePath string, r *fnmod
|
||||
Body: &fnmodels.RouteWrapper{Route: r},
|
||||
})
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apiroutes.PutAppsAppRoutesRouteBadRequest:
|
||||
return fmt.Errorf("error: %s", err.(*apiroutes.PutAppsAppRoutesRouteBadRequest).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %s", e.Payload.Error.Message)
|
||||
case *apiroutes.PutAppsAppRoutesRouteDefault:
|
||||
return fmt.Errorf("unexpected error: %s", err.(*apiroutes.PutAppsAppRoutesRouteDefault).Payload.Error.Message)
|
||||
return fmt.Errorf("unexpected error: %s", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -392,7 +404,7 @@ func (a *routesCmd) update(c *cli.Context) error {
|
||||
rt := &fnmodels.Route{}
|
||||
|
||||
if !c.Bool("ignore-fn-file") {
|
||||
if err := routeWithFuncFile(c, nil, rt); err != nil {
|
||||
if err := routeWithFuncFile(nil, rt); err != nil {
|
||||
return fmt.Errorf("error updating route: %s", err)
|
||||
}
|
||||
}
|
||||
@@ -461,13 +473,14 @@ func (a *routesCmd) inspect(c *cli.Context) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apiroutes.GetAppsAppRoutesRouteNotFound:
|
||||
return fmt.Errorf("error: %s", err.(*apiroutes.GetAppsAppRoutesRouteNotFound).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %s", e.Payload.Error.Message)
|
||||
case *apiroutes.GetAppsAppRoutesRouteDefault:
|
||||
return fmt.Errorf("unexpected error: %s", err.(*apiroutes.GetAppsAppRoutesRouteDefault).Payload.Error.Message)
|
||||
return fmt.Errorf("unexpected error: %s", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
@@ -508,13 +521,14 @@ func (a *routesCmd) delete(c *cli.Context) error {
|
||||
Route: route,
|
||||
})
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
switch e := err.(type) {
|
||||
case *apiroutes.DeleteAppsAppRoutesRouteNotFound:
|
||||
return fmt.Errorf("error: %s", err.(*apiroutes.DeleteAppsAppRoutesRouteNotFound).Payload.Error.Message)
|
||||
return fmt.Errorf("error: %s", e.Payload.Error.Message)
|
||||
case *apiroutes.DeleteAppsAppRoutesRouteDefault:
|
||||
return fmt.Errorf("unexpected error: %s", err.(*apiroutes.DeleteAppsAppRoutesRouteDefault).Payload.Error.Message)
|
||||
return fmt.Errorf("unexpected error: %s", e.Payload.Error.Message)
|
||||
default:
|
||||
return fmt.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
return fmt.Errorf("unexpected error: %s", err)
|
||||
}
|
||||
|
||||
fmt.Println(appName, route, "deleted")
|
||||
|
||||
Reference in New Issue
Block a user