From bec08dc9ba437f338b4c6ec471ef4695e5b4aeb5 Mon Sep 17 00:00:00 2001 From: Daniel Lamando Date: Tue, 29 Dec 2020 16:17:14 +0100 Subject: [PATCH] kubectl-raw: Only log stuff if --verbose is given --- transports/via-kubectl-raw.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/transports/via-kubectl-raw.ts b/transports/via-kubectl-raw.ts index d18131e..f53e11b 100644 --- a/transports/via-kubectl-raw.ts +++ b/transports/via-kubectl-raw.ts @@ -4,6 +4,8 @@ import { readableStreamFromReaderCloser, } from "../stream-transformers.ts"; +const isVerbose = Deno.args.includes('--verbose'); + /** * A RestClient for easily running on a developer's local machine. * Your existing kubectl is called to do all the actual authentication and network stuff. @@ -31,7 +33,7 @@ export class KubectlRawRestClient implements RestClient { }) { const hasReqBody = opts.bodyJson !== undefined || !!opts.bodyRaw || !!opts.bodyStream; - console.error('$ kubectl', args.join(' '), hasReqBody ? '< input' : ''); + isVerbose && console.error('$ kubectl', args.join(' '), hasReqBody ? '< input' : ''); const p = Deno.run({ cmd: ["kubectl", ...args], @@ -43,12 +45,12 @@ export class KubectlRawRestClient implements RestClient { if (opts.abortSignal) { const abortHandler = () => { - console.error('processing kubectl abort'); + isVerbose && console.error('processing kubectl abort'); p.stdout.close(); }; opts.abortSignal.addEventListener("abort", abortHandler); status.finally(() => { - console.error('cleaning up abort handler'); + isVerbose && console.error('cleaning up abort handler'); opts.abortSignal?.removeEventListener("abort", abortHandler); }); } @@ -68,7 +70,7 @@ export class KubectlRawRestClient implements RestClient { await p.stdin.write(opts.bodyRaw); p.stdin.close(); } else { - console.error(JSON.stringify(opts.bodyJson)) + isVerbose && console.error(JSON.stringify(opts.bodyJson)) await p.stdin.write(new TextEncoder().encode(JSON.stringify(opts.bodyJson))); p.stdin.close(); } @@ -98,7 +100,7 @@ export class KubectlRawRestClient implements RestClient { } const hasReqBody = opts.bodyJson !== undefined || !!opts.bodyRaw || !!opts.bodyStream; - // console.error(opts.method, path, hasReqBody ? '(w/ body)' : ''); + isVerbose && console.error(opts.method, path, hasReqBody ? '(w/ body)' : ''); let rawArgs = [command, ...(hasReqBody ? ['-f', '-'] : []), "--raw", path];