From 38d11fb9d5cda97d3927c9aab4c271c4173dc5be Mon Sep 17 00:00:00 2001 From: Aschen Date: Fri, 30 Oct 2020 16:20:57 +0100 Subject: [PATCH 1/4] Add Quine example --- README.md | 17 +++++++++++++++++ src/commands/sdk/execute.ts | 5 ++++- src/common.ts | 19 ++++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fb800e04..8b88b1a9 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ The CLI that helps you manage your Kuzzle instances. * [Usage](#usage) * [Commands](#commands) * [Where does this weird name come from?](#where-does-this-weird-name-come-from) +* [Have fun with quine](#have-fun-with-quine) :warning: This project is currently in beta and breaking changes may occur until the 1.0.0 @@ -1358,3 +1359,19 @@ _See code: [src/commands/vault/test.ts](src/commands/vault/test.ts)_ # Where does this weird name come from? We liked the idea that this CLI is like a launchpad for the Kuzzle rocket. The place where you launch and pilot your Kuzzle instance. The place where the European Space Agency launches their rockets is in the country near the city of [Kourou](https://www.wikiwand.com/en/Kourou), in French Guiana, so we liked the idea that the Kuzzle rockets would take off from there. + +# Have fun with quine + +[Quine](https://en.wikipedia.org/wiki/Quine_(computing)) are programs able to print their own source code. + +```bash +$ kourou sdk:execute --code '( + function quine() { + const sq = String.fromCharCode(39); + const lp = String.fromCharCode(40); + const rp = String.fromCharCode(41); + + console.log("kourou sdk:execute --code " + sq + lp + quine.toString() + rp + lp + rp + ";" + sq) + } +)()' +``` \ No newline at end of file diff --git a/src/commands/sdk/execute.ts b/src/commands/sdk/execute.ts index 67534eb8..ddb01306 100644 --- a/src/commands/sdk/execute.ts +++ b/src/commands/sdk/execute.ts @@ -52,6 +52,9 @@ Other 'keep-alive': flags.boolean({ description: 'Keep the connection running (websocket only)' }), + 'print-raw': flags.boolean({ + description: 'Print only the script result to stdout' + }), ...kuzzleFlags, }; @@ -120,7 +123,7 @@ ${variables} this.logOk('Successfully executed SDK code') if (result !== undefined) { - this.log(JSON.stringify(result, null, 2)) + console.log(JSON.stringify(result, null, 2)) } } diff --git a/src/common.ts b/src/common.ts index 6cf358cb..91aa743a 100644 --- a/src/common.ts +++ b/src/common.ts @@ -37,30 +37,47 @@ export abstract class Kommand extends Command { } public log(message?: string): void { + if (this.flags['print-raw']) { + return; + } + super.log(` ${message}`) } public logOk(message: string): void { + if (this.flags['print-raw']) { + return; + } + this.log(chalk.green(`[✔] ${message}`)) } public logInfo(message: string): void { + if (this.flags['print-raw']) { + return; + } + this.log(chalk.yellow(`[ℹ] ${message}`)) } public logKo(message?: string): void { + if (this.flags['print-raw']) { + return; + } + this.exitCode = 1 this.log(chalk.red(`[X] ${message}`)) } async run() { - this.printCommand() const kommand = (this.constructor as unknown) as any const result = this.parse(kommand) this.args = result.args this.flags = result.flags + this.printCommand() + if (kommand.readStdin) { this.stdin = this.fromStdin() From 43c0b3ba18b68dc80e0f68281c54888cea659fdc Mon Sep 17 00:00:00 2001 From: Aschen Date: Fri, 30 Oct 2020 16:27:07 +0100 Subject: [PATCH 2/4] lint --- README.md | 7 ++++--- src/commands/sdk/execute.ts | 1 + src/common.ts | 10 +++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8b88b1a9..32581c92 100644 --- a/README.md +++ b/README.md @@ -939,6 +939,7 @@ OPTIONS --keep-alive Keep the connection running (websocket only) --password=password Kuzzle user password --port=port [default: 7512] Kuzzle server port + --print-raw Print only the script result to stdout --protocol=protocol [default: ws] Kuzzle protocol (http or ws) --ssl Use SSL to connect to Kuzzle --username=username [default: anonymous] Kuzzle username (local strategy) @@ -1365,13 +1366,13 @@ We liked the idea that this CLI is like a launchpad for the Kuzzle rocket. The p [Quine](https://en.wikipedia.org/wiki/Quine_(computing)) are programs able to print their own source code. ```bash -$ kourou sdk:execute --code '( +$ kourou-dev sdk:execute --print-raw --code '( function quine() { const sq = String.fromCharCode(39); const lp = String.fromCharCode(40); const rp = String.fromCharCode(41); - console.log("kourou sdk:execute --code " + sq + lp + quine.toString() + rp + lp + rp + ";" + sq) + console.log("kourou-dev sdk:execute --print-raw --code " + sq + lp + quine.toString() + rp + lp + rp + ";" + sq) } )()' -``` \ No newline at end of file +``` diff --git a/src/commands/sdk/execute.ts b/src/commands/sdk/execute.ts index ddb01306..6fac1cb9 100644 --- a/src/commands/sdk/execute.ts +++ b/src/commands/sdk/execute.ts @@ -123,6 +123,7 @@ ${variables} this.logOk('Successfully executed SDK code') if (result !== undefined) { + // eslint-disable-next-line no-console console.log(JSON.stringify(result, null, 2)) } } diff --git a/src/common.ts b/src/common.ts index 91aa743a..c22be966 100644 --- a/src/common.ts +++ b/src/common.ts @@ -38,7 +38,7 @@ export abstract class Kommand extends Command { public log(message?: string): void { if (this.flags['print-raw']) { - return; + return } super.log(` ${message}`) @@ -46,7 +46,7 @@ export abstract class Kommand extends Command { public logOk(message: string): void { if (this.flags['print-raw']) { - return; + return } this.log(chalk.green(`[✔] ${message}`)) @@ -54,7 +54,7 @@ export abstract class Kommand extends Command { public logInfo(message: string): void { if (this.flags['print-raw']) { - return; + return } this.log(chalk.yellow(`[ℹ] ${message}`)) @@ -62,7 +62,7 @@ export abstract class Kommand extends Command { public logKo(message?: string): void { if (this.flags['print-raw']) { - return; + return } this.exitCode = 1 @@ -158,6 +158,6 @@ export abstract class Kommand extends Command { } // eslint-disable-next-line no-eval - return eval(`var o = ${input}; o`) + return eval(`var o = ${input} o`) } } From d5b3e47c0db109d42c2323365f62d962519fdf78 Mon Sep 17 00:00:00 2001 From: Aschen Date: Fri, 30 Oct 2020 16:27:42 +0100 Subject: [PATCH 3/4] lint --- src/common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.ts b/src/common.ts index c22be966..20b79bc8 100644 --- a/src/common.ts +++ b/src/common.ts @@ -158,6 +158,6 @@ export abstract class Kommand extends Command { } // eslint-disable-next-line no-eval - return eval(`var o = ${input} o`) + return eval(`var o = ${input}; o`) } } From 424b1064b6cfe922288fe8c8ab5234805cc44a2c Mon Sep 17 00:00:00 2001 From: Aschen Date: Mon, 2 Nov 2020 15:02:57 +0100 Subject: [PATCH 4/4] nit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 32581c92..17160af3 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The CLI that helps you manage your Kuzzle instances. * [Usage](#usage) * [Commands](#commands) * [Where does this weird name come from?](#where-does-this-weird-name-come-from) -* [Have fun with quine](#have-fun-with-quine) +* [Have fun with a quine](#have-fun-with-a-quine) :warning: This project is currently in beta and breaking changes may occur until the 1.0.0 @@ -1361,7 +1361,7 @@ _See code: [src/commands/vault/test.ts](src/commands/vault/test.ts)_ We liked the idea that this CLI is like a launchpad for the Kuzzle rocket. The place where you launch and pilot your Kuzzle instance. The place where the European Space Agency launches their rockets is in the country near the city of [Kourou](https://www.wikiwand.com/en/Kourou), in French Guiana, so we liked the idea that the Kuzzle rockets would take off from there. -# Have fun with quine +# Have fun with a quine [Quine](https://en.wikipedia.org/wiki/Quine_(computing)) are programs able to print their own source code.