From dea9c061d864c25f23b382f173e395af84471e2c Mon Sep 17 00:00:00 2001 From: sugardave Date: Thu, 1 Sep 2022 09:36:55 -0500 Subject: [PATCH] Feature/eng 103 implement a bls function updatecommand (#28) Co-authored-by: Derek Anderson Co-authored-by: Derek Anderson --- src/commands/function/deploy.ts | 2 ++ src/commands/function/index.ts | 1 + src/commands/function/interfaces.ts | 6 ++++ src/commands/function/update.ts | 3 ++ src/index.ts | 51 +++++++++++++++++++++-------- 5 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 src/commands/function/update.ts diff --git a/src/commands/function/deploy.ts b/src/commands/function/deploy.ts index 8f137d7..c1fe939 100644 --- a/src/commands/function/deploy.ts +++ b/src/commands/function/deploy.ts @@ -3,12 +3,14 @@ import { getToken } from "../../store/db"; import axios from "axios"; import { IDeploymentOptions } from "./interfaces"; import { run as runPublish } from "./publish"; +import { getConsoleServer } from "../../lib/utils"; const deploymentOptions: IDeploymentOptions = { functionId: "", functionName: "", userFunctionId: "", }; +const consoleServer = getConsoleServer(); const server = "https://console.bls.dev"; const token = getToken(); diff --git a/src/commands/function/index.ts b/src/commands/function/index.ts index 2f82e89..beac345 100644 --- a/src/commands/function/index.ts +++ b/src/commands/function/index.ts @@ -4,3 +4,4 @@ export { run as runInit } from "./init"; export { run as runInvoke } from "./invoke"; export { run as runList } from "./list"; export { run as runPublish } from "./publish"; +export { run as runUpdate } from "./update"; diff --git a/src/commands/function/interfaces.ts b/src/commands/function/interfaces.ts index 52ac53c..5748084 100644 --- a/src/commands/function/interfaces.ts +++ b/src/commands/function/interfaces.ts @@ -3,6 +3,12 @@ export interface IBlsFunction { functionId: string; name: string; } +export interface IBlsFunctionRequiredOptions { + init: string[]; + deploy: string[]; + publish: string[]; + update: string[]; +} // WASM interrfaces export interface IWasmMethod { diff --git a/src/commands/function/update.ts b/src/commands/function/update.ts new file mode 100644 index 0000000..2a7748e --- /dev/null +++ b/src/commands/function/update.ts @@ -0,0 +1,3 @@ +import { run as runPublish } from "./publish"; + +export const run = (options: any) => runPublish(options); diff --git a/src/index.ts b/src/index.ts index fefa3f5..d1d4333 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,9 @@ import { runInvoke, runList, runPublish, + runUpdate, } from "./commands/function"; +import { IBlsFunctionRequiredOptions } from "./commands/function/interfaces"; import { run as runLogin } from "./commands/login"; import { run as runInfo } from "./commands/info"; @@ -107,33 +109,26 @@ args "function", "Interact with Functions [init, invoke, delete, deploy, list]", (name: string, sub: string[], options) => { - interface RequiredOptions { - init: string[]; - deploy: string[]; - publish: string[]; - } - const requiredOptions: RequiredOptions = { + const requiredOptions: IBlsFunctionRequiredOptions = { init: ["name"], deploy: ["name"], publish: ["name"], + update: ["name"], }; - const index: keyof RequiredOptions = "init"; didRun = true; if (!sub[0] || sub[0] === "help") { printHelp([ [ "init\t", - "initialize a new function with blockless starter template", + "Initialize a new function with blockless starter template.", ], - ["deploy\t", "deploy a function on Blockless"], + ["deploy\t", "Deploy a function on Blockless."], [ "list\t", "Retrieve a list of funtions deployed at Blockless Console.", ], - [ - "invoke\t", - "Invokes the a function at the current (cwd) directory.", - ], + ["invoke\t", "Invokes the function at the current (cwd) directory."], + ["update\t", "Update an existing function on Blockless."], ]); return; } @@ -235,6 +230,36 @@ args } runPublish(options); break; + case "update": + for (const option of requiredOptions[sub[0]]) { + if (!(option in options)) { + console.log( + Chalk.red(`Missing required option ${Chalk.yellow(option)}\n`) + ); + printHelp( + [["update", "Update an existing function on Blockless"]], + [ + ["--name", "The name of the function to update (required)"], + [ + "--path", + "The location of the function' to update (required)", + ], + + [ + "--rebuild", + "Build the package before updating it (optional; defaults to undefined)", + ], + [ + "--debug", + "Specifying the 'debug' option will build the debug version, otherwise the release version will be built (optional; defaults to undefined; only applicable if using the '--rebuild' option)", + ], + ] + ); + return; + } + } + runUpdate(options); + break; case "invoke": runInvoke(options); break;