Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Quine example #77

Merged
merged 5 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<!-- tocstop -->

:warning: This project is currently in beta and breaking changes may occur until the 1.0.0
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
)()'
```
6 changes: 5 additions & 1 deletion src/commands/sdk/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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))
}
}

Expand Down
19 changes: 18 additions & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down