diff --git a/README.md b/README.md index b4779825..361bc625 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 a quine](#have-fun-with-a-quine) :warning: This project is currently in beta and breaking changes may occur until the 1.0.0 @@ -1021,6 +1022,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) @@ -1441,3 +1443,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 a quine + +[Quine](https://en.wikipedia.org/wiki/Quine_(computing)) are programs able to print their own source code. + +```bash +$ 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-dev sdk:execute --print-raw --code " + sq + lp + quine.toString() + rp + lp + rp + ";" + sq) + } +)()' +``` diff --git a/src/commands/sdk/execute.ts b/src/commands/sdk/execute.ts index 67534eb8..6fac1cb9 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,8 @@ ${variables} this.logOk('Successfully executed SDK code') if (result !== undefined) { - this.log(JSON.stringify(result, null, 2)) + // eslint-disable-next-line no-console + console.log(JSON.stringify(result, null, 2)) } } diff --git a/src/common.ts b/src/common.ts index 5628fcce..1b166bb1 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()