From 917dc0b23716a18ab2639ea429346eb086813479 Mon Sep 17 00:00:00 2001 From: Rolljee Date: Fri, 23 Oct 2020 15:19:11 +0200 Subject: [PATCH 1/2] Close #71 --- .vscode/settings.json | 7 +++++-- README.md | 18 +++++++++--------- features/Elasticsearch.feature | 16 ++++++++++++++-- features/step_definitions/cli-steps.js | 2 ++ package-lock.json | 6 +++--- package.json | 3 ++- src/commands/es/{ => indices}/get.ts | 2 +- src/commands/es/{ => indices}/insert.ts | 2 +- .../es/{list-index.ts => indices/list.ts} | 2 +- 9 files changed, 38 insertions(+), 20 deletions(-) rename src/commands/es/{ => indices}/get.ts (96%) rename src/commands/es/{ => indices}/insert.ts (96%) rename src/commands/es/{list-index.ts => indices/list.ts} (96%) diff --git a/.vscode/settings.json b/.vscode/settings.json index cadd55e9..b8ab154b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,9 @@ "vetur.format.defaultFormatter.ts": "prettier", "vetur.format.defaultFormatter.js": "prettier-eslint", "vetur.format.enable": false, - "editor.defaultFormatter": "esbenp.prettier-vscode", - "typescript.tsdk": "node_modules/typescript/lib" + "editor.defaultFormatter": "vscode.typescript-language-features", + "typescript.tsdk": "node_modules/typescript/lib", + "[feature]": { + "editor.defaultFormatter": "alexkrechik.cucumberautocomplete" + } } diff --git a/README.md b/README.md index 2654453a..10bfc8e5 100644 --- a/README.md +++ b/README.md @@ -131,9 +131,9 @@ Then any argument will be passed as-is to the `sdk:query` method. * [`kourou collection:import PATH`](#kourou-collectionimport-path) * [`kourou config:diff FIRST SECOND`](#kourou-configdiff-first-second) * [`kourou document:search INDEX COLLECTION [QUERY]`](#kourou-documentsearch-index-collection-query) -* [`kourou es:get INDEX ID`](#kourou-esget-index-id) -* [`kourou es:insert INDEX`](#kourou-esinsert-index) -* [`kourou es:list-index`](#kourou-eslist-index) +* [`kourou es:indices:get INDEX ID`](#kourou-esindicesget-index-id) +* [`kourou es:indices:insert INDEX`](#kourou-esindicesinsert-index) +* [`kourou es:indices:list`](#kourou-esindiceslist) * [`kourou file:decrypt FILE`](#kourou-filedecrypt-file) * [`kourou file:encrypt FILE`](#kourou-fileencrypt-file) * [`kourou file:test FILE`](#kourou-filetest-file) @@ -453,13 +453,13 @@ EXAMPLES _See code: [src/commands/document/search.ts](src/commands/document/search.ts)_ -## `kourou es:get INDEX ID` +## `kourou es:indices:get INDEX ID` Gets a document from ES ``` USAGE - $ kourou es:get INDEX ID + $ kourou es:indices:get INDEX ID ARGUMENTS INDEX ES Index name @@ -473,13 +473,13 @@ OPTIONS _See code: [src/commands/es/get.ts](src/commands/es/get.ts)_ -## `kourou es:insert INDEX` +## `kourou es:indices:insert INDEX` Inserts a document directly into ES (will replace if exists) ``` USAGE - $ kourou es:insert INDEX + $ kourou es:indices:insert INDEX ARGUMENTS INDEX ES Index name @@ -494,13 +494,13 @@ OPTIONS _See code: [src/commands/es/insert.ts](src/commands/es/insert.ts)_ -## `kourou es:list-index` +## `kourou es:indices:list-index` Lists available ES indexes ``` USAGE - $ kourou es:list-index + $ kourou es:indices:list-index OPTIONS -g, --grep=grep Match output with pattern diff --git a/features/Elasticsearch.feature b/features/Elasticsearch.feature index dfa0ac7d..dc60070a 100644 --- a/features/Elasticsearch.feature +++ b/features/Elasticsearch.feature @@ -6,7 +6,7 @@ Feature: Elasticsearch commands And I create the following document: | _id | "chuon-chuon-kim" | | body | {} | - When I run the command "es:get" with args: + When I run the command "es:indices:get" with args: | "&nyc-open-data.yellow-taxi" | | "chuon-chuon-kim" | Then I should match stdout with "chuon-chuon-kim" @@ -14,7 +14,19 @@ Feature: Elasticsearch commands @mappings Scenario: List ES indexes Given a collection "nyc-open-data":"green-taxi" - When I run the command "es:list-index" with flags: + When I run the command "es:indices:list" with flags: | --grep | "nyc-open-data" | Then I should match stdout with "yellow-taxi" And I should match stdout with "green-taxi" + + @mappings + Scenario: Insert ES document + Given a collection "nyc-open-data":"green-taxi" + When I run the command "es:indices:insert" with: + | arg | &nyc-open-data.yellow-taxi | | + | flag | --id | kindred | + | flag | --body | {} | + When I run the command "es:indices:get" with args: + | "&nyc-open-data.yellow-taxi" | + | "kindred" | + Then I should match stdout with "kindred" diff --git a/features/step_definitions/cli-steps.js b/features/step_definitions/cli-steps.js index b5c6d0b6..6560d71d 100644 --- a/features/step_definitions/cli-steps.js +++ b/features/step_definitions/cli-steps.js @@ -1,6 +1,7 @@ const fs = require('fs') const _ = require('lodash') +const should = require('should') const { Then } = require('cucumber') // this need to build the lib with "npm run build" first @@ -83,6 +84,7 @@ Then('I run the command {string} with args:', async function (command, dataTable const args = [] for (const row of dataTable.rawTable) { + console.log(row) args.push(JSON.parse(row[0])) } diff --git a/package-lock.json b/package-lock.json index 5764b574..42a54338 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2983,9 +2983,9 @@ } }, "lodash": { - "version": "4.17.15", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" + "version": "4.17.20", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", + "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" }, "lodash._reinterpolate": { "version": "3.0.0", diff --git a/package.json b/package.json index c5dae588..bbb780f9 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "kuzzle-sdk": "^7.4.0", "kuzzle-vault": "^2.0.0", "listr": "^0.14.3", + "lodash": "^4.17.20", "ndjson": "^1.5.0", "node-emoji": "^1.10.0", "strip-json-comments": "^3.1.0", @@ -125,4 +126,4 @@ "test:functional:cucumber": "./node_modules/.bin/cucumber-js" }, "types": "lib/index.d.ts" -} \ No newline at end of file +} diff --git a/src/commands/es/get.ts b/src/commands/es/indices/get.ts similarity index 96% rename from src/commands/es/get.ts rename to src/commands/es/indices/get.ts index b04747a5..221a35bf 100644 --- a/src/commands/es/get.ts +++ b/src/commands/es/indices/get.ts @@ -1,7 +1,7 @@ import { flags } from '@oclif/command' import { Client } from '@elastic/elasticsearch' -import { Kommand } from '../../common' +import { Kommand } from '../../../common' export default class EsGet extends Kommand { static initSdk = false diff --git a/src/commands/es/insert.ts b/src/commands/es/indices/insert.ts similarity index 96% rename from src/commands/es/insert.ts rename to src/commands/es/indices/insert.ts index 3b960c24..5c1c63c9 100644 --- a/src/commands/es/insert.ts +++ b/src/commands/es/indices/insert.ts @@ -1,7 +1,7 @@ import { flags } from '@oclif/command' import { Client } from '@elastic/elasticsearch' -import { Kommand } from '../../common' +import { Kommand } from '../../../common' export default class EsInsert extends Kommand { static initSdk = false diff --git a/src/commands/es/list-index.ts b/src/commands/es/indices/list.ts similarity index 96% rename from src/commands/es/list-index.ts rename to src/commands/es/indices/list.ts index d4dcde2e..546a1b00 100644 --- a/src/commands/es/list-index.ts +++ b/src/commands/es/indices/list.ts @@ -1,7 +1,7 @@ import { flags } from '@oclif/command' import { Client } from '@elastic/elasticsearch' -import { Kommand } from '../../common' +import { Kommand } from '../../../common' export default class EsListIndex extends Kommand { static initSdk = false From 083946d5895885cbf01e04e3ebf91eba1272205b Mon Sep 17 00:00:00 2001 From: Rolljee Date: Fri, 23 Oct 2020 15:21:56 +0200 Subject: [PATCH 2/2] Change es:indices:list to es:indices:cat to match the ES api --- README.md | 12 ++++++------ features/Elasticsearch.feature | 4 ++-- features/step_definitions/cli-steps.js | 1 - src/commands/es/indices/{list.ts => cat.ts} | 0 4 files changed, 8 insertions(+), 9 deletions(-) rename src/commands/es/indices/{list.ts => cat.ts} (100%) diff --git a/README.md b/README.md index 10bfc8e5..05c25a6b 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Then any argument will be passed as-is to the `sdk:query` method. * [`kourou document:search INDEX COLLECTION [QUERY]`](#kourou-documentsearch-index-collection-query) * [`kourou es:indices:get INDEX ID`](#kourou-esindicesget-index-id) * [`kourou es:indices:insert INDEX`](#kourou-esindicesinsert-index) -* [`kourou es:indices:list`](#kourou-esindiceslist) +* [`kourou es:indices:cat`](#kourou-esindicescat) * [`kourou file:decrypt FILE`](#kourou-filedecrypt-file) * [`kourou file:encrypt FILE`](#kourou-fileencrypt-file) * [`kourou file:test FILE`](#kourou-filetest-file) @@ -471,7 +471,7 @@ OPTIONS --help show CLI help ``` -_See code: [src/commands/es/get.ts](src/commands/es/get.ts)_ +_See code: [src/commands/es/indices/get.ts](src/commands/es/indices/get.ts)_ ## `kourou es:indices:insert INDEX` @@ -492,15 +492,15 @@ OPTIONS --id=id Document ID ``` -_See code: [src/commands/es/insert.ts](src/commands/es/insert.ts)_ +_See code: [src/commands/es/indices/insert.ts](src/commands/es/indices/insert.ts)_ -## `kourou es:indices:list-index` +## `kourou es:indices:cat` Lists available ES indexes ``` USAGE - $ kourou es:indices:list-index + $ kourou es:indices:cat OPTIONS -g, --grep=grep Match output with pattern @@ -509,7 +509,7 @@ OPTIONS --help show CLI help ``` -_See code: [src/commands/es/list-index.ts](src/commands/es/list-index.ts)_ +_See code: [src/commands/es/indices/cat.ts](src/commands/es/indices/cat.ts)_ ## `kourou file:decrypt FILE` diff --git a/features/Elasticsearch.feature b/features/Elasticsearch.feature index dc60070a..e3483e59 100644 --- a/features/Elasticsearch.feature +++ b/features/Elasticsearch.feature @@ -12,9 +12,9 @@ Feature: Elasticsearch commands Then I should match stdout with "chuon-chuon-kim" @mappings - Scenario: List ES indexes + Scenario: Cat ES indexes Given a collection "nyc-open-data":"green-taxi" - When I run the command "es:indices:list" with flags: + When I run the command "es:indices:cat" with flags: | --grep | "nyc-open-data" | Then I should match stdout with "yellow-taxi" And I should match stdout with "green-taxi" diff --git a/features/step_definitions/cli-steps.js b/features/step_definitions/cli-steps.js index 6560d71d..08b3f288 100644 --- a/features/step_definitions/cli-steps.js +++ b/features/step_definitions/cli-steps.js @@ -84,7 +84,6 @@ Then('I run the command {string} with args:', async function (command, dataTable const args = [] for (const row of dataTable.rawTable) { - console.log(row) args.push(JSON.parse(row[0])) } diff --git a/src/commands/es/indices/list.ts b/src/commands/es/indices/cat.ts similarity index 100% rename from src/commands/es/indices/list.ts rename to src/commands/es/indices/cat.ts