63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/google/subcommands"
|
|
)
|
|
|
|
type handlerDeleteCmd struct{}
|
|
|
|
func (handlerDeleteCmd) SetFlags(fs *flag.FlagSet) {}
|
|
func (handlerDeleteCmd) Name() string { return "delete" }
|
|
func (handlerDeleteCmd) Synopsis() string { return "delete a handler" }
|
|
func (handlerDeleteCmd) Usage() string {
|
|
return `wasmcloud delete <handler-name>
|
|
|
|
$ wasmcloud delete filename.wasm
|
|
|
|
Deletes a handler on wasmcloud. Please run this with care. No data loss will
|
|
happen, but support will need to be contacted if you want to un-delete a
|
|
handler.
|
|
|
|
See the following command for a list of your deleted handlers:
|
|
|
|
$ wasmcloud list -show-deleted
|
|
`
|
|
}
|
|
|
|
func (h handlerDeleteCmd) Execute(ctx context.Context, fs *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
|
|
if fs.NArg() != 1 {
|
|
fmt.Println("usage: wasmcloud delete <handler-name>")
|
|
return subcommands.ExitUsageError
|
|
}
|
|
|
|
hname := fs.Arg(0)
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, *apiServer+"/api/handler/delete?name="+hname, nil)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
withAPI(req)
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
if resp.StatusCode != http.StatusNoContent {
|
|
io.Copy(os.Stdout, resp.Body)
|
|
return subcommands.ExitFailure
|
|
}
|
|
|
|
fmt.Println("deleted handler", hname)
|
|
|
|
return subcommands.ExitSuccess
|
|
}
|