From 8b1fbe805b9374ed1116e6275ec9560b0e65d7ce Mon Sep 17 00:00:00 2001 From: Phoebe Lartisant Date: Thu, 25 Jul 2024 12:02:43 +0200 Subject: [PATCH] add cli edit command --- cmd/cli/main.go | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/cmd/cli/main.go b/cmd/cli/main.go index aa67bb6..b4923d0 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -15,9 +15,9 @@ import ( func main() { app := &cli.App{ - Name: "Massa's Great DeWEB CLI", + Name: "DeWeb CLI", Usage: "CLI app for deploying websites", - UsageText: "U_ia pload, delete & edit DeWeb site from the terminal", + UsageText: "Upload, delete & edit DeWeb site from the terminal", Version: config.Version, Action: func(cCtx *cli.Context) error { cli.ShowAppHelp(cCtx) @@ -54,6 +54,49 @@ func main() { return nil }, }, + { + Name: "edit", + Aliases: []string{"e"}, + Usage: "Edit website bytecode", + ArgsUsage: " ", + Action: func(cCtx *cli.Context) error { + + if cCtx.Args().Get(0) == "" { + return fmt.Errorf("wallet nickname is required") + } + + nickname := cCtx.Args().Get(0) + + config := pkgConfig.DefaultConfig(nickname, "https://buildnet.massa.net/api/v2") + + if cCtx.Args().Get(1) == "" { + return fmt.Errorf("sc is required") + } + + address := cCtx.Args().Get(1) + + if cCtx.Args().Get(2) == "" { + return fmt.Errorf("website zip path is required") + } + + zipPath := cCtx.Args().Get(2) + + bytecode, err := processFileForUpload(zipPath) + + if err != nil { + logger.Fatalf("failed to process file for upload: %v", err) + } + + err = uploadChunks(bytecode, address, config) + if err != nil { + logger.Fatalf("failed to upload chunks: %v", err) + } + + logger.Infof("Website bytecode updated successfully at address: %s", address) + + return nil + }, + }, }, }