From 4346f98ef2b089dfc35a18bb7f6630c90190fc1d Mon Sep 17 00:00:00 2001 From: Kai Jellinghaus Date: Thu, 24 Nov 2022 13:51:37 +0100 Subject: [PATCH] Add --silent & print result --- cli/flow.ts | 17 ++++++++++++++--- cli/script.ts | 24 ++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/cli/flow.ts b/cli/flow.ts index a66cdf5ebc..fe72189d27 100644 --- a/cli/flow.ts +++ b/cli/flow.ts @@ -110,6 +110,7 @@ async function run( opts: GlobalOptions & { input: Record; inputFrom: string | undefined; + silent: boolean; }, path: string ) { @@ -135,8 +136,10 @@ async function run( const module = jobInfo.flow_status!.modules[i]; if (module.job) { - console.log("====== Job " + (i + 1) + " ======"); - await track_job(workspace, module.job); + if (!opts.silent) { + console.log("====== Job " + (i + 1) + " ======"); + await track_job(workspace, module.job); + } } else { console.log(module.type); await new Promise((resolve, _) => @@ -147,7 +150,11 @@ async function run( i++; } - console.log(colors.green.underline.bold("Flow ran to completion")); + if (!opts.silent) { + console.log(colors.green.underline.bold("Flow ran to completion")); + } + const jobInfo = await JobService.getCompletedJob({ workspace, id }); + console.log(jobInfo.result ?? {}); } const command = new Command() @@ -167,6 +174,10 @@ const command = new Command() "--inputFrom ", "Read a JSON input object from a file. This will be merged with --input.* arguments." ) + .option( + "-s --silent", + "Do not ouput anything other then the final output. Useful for scripting." + ) .action(run as any); export default command; diff --git a/cli/script.ts b/cli/script.ts index 9d03e9be99..bffee509cf 100644 --- a/cli/script.ts +++ b/cli/script.ts @@ -10,6 +10,7 @@ import { } from "https://deno.land/x/windmill@v1.50.0/windmill-api/index.ts"; import { Table } from "https://deno.land/x/cliffy@v0.25.4/table/table.ts"; import { green } from "https://deno.land/std@0.161.0/fmt/colors.ts"; +import { resolve } from "https://deno.land/std@0.141.0/path/win32.ts"; type ScriptFile = { parent_hash?: string; @@ -177,6 +178,7 @@ async function run( opts: GlobalOptions & { input: Record; inputFrom: string | undefined; + silent: boolean; }, path: string ) { @@ -186,13 +188,27 @@ async function run( ? JSON.parse(await Deno.readTextFile(opts.inputFrom)) : {}; const input = { ...(opts.input ?? {}), ...inputFileContents }; - let id = await JobService.runScriptByPath({ + const id = await JobService.runScriptByPath({ workspace, path, requestBody: input, }); - track_job(workspace, id); + if (!opts.silent) { + await track_job(workspace, id); + } + + while (true) { + try { + const result = + (await JobService.getCompletedJob({ workspace, id })).result ?? {}; + console.log(result); + + break; + } catch { + new Promise((resolve, _) => setTimeout(() => resolve(undefined), 100)); + } + } } export async function track_job(workspace: string, id: string) { @@ -303,6 +319,10 @@ const command = new Command() "--inputFrom ", "Read a JSON input object from a file. This will be merged with --input.* arguments." ) + .option( + "-s --silent", + "Do not ouput anything other then the final output. Useful for scripting." + ) .action(run as any); export default command;