From 329619b3453479f76c049816b7403b86e9d45cb5 Mon Sep 17 00:00:00 2001
From: Chocobozzz <me@florianbigard.com>
Date: Mon, 5 Jul 2021 16:37:50 +0200
Subject: Introduce CLI command

---
 shared/extra-utils/cli/cli.ts   | 33 ++++++++++++++++++---------------
 shared/extra-utils/cli/index.ts |  1 +
 2 files changed, 19 insertions(+), 15 deletions(-)
 create mode 100644 shared/extra-utils/cli/index.ts

(limited to 'shared/extra-utils/cli')

diff --git a/shared/extra-utils/cli/cli.ts b/shared/extra-utils/cli/cli.ts
index c62e170bb..1bf100869 100644
--- a/shared/extra-utils/cli/cli.ts
+++ b/shared/extra-utils/cli/cli.ts
@@ -1,24 +1,27 @@
 import { exec } from 'child_process'
+import { AbstractCommand } from '../shared'
 
-import { ServerInfo } from '../server/servers'
+class CLICommand extends AbstractCommand {
 
-function getEnvCli (server?: ServerInfo) {
-  return `NODE_ENV=test NODE_APP_INSTANCE=${server.internalServerNumber}`
-}
-
-async function execCLI (command: string) {
-  return new Promise<string>((res, rej) => {
-    exec(command, (err, stdout, stderr) => {
-      if (err) return rej(err)
+  static exec (command: string) {
+    return new Promise<string>((res, rej) => {
+      exec(command, (err, stdout, _stderr) => {
+        if (err) return rej(err)
 
-      return res(stdout)
+        return res(stdout)
+      })
     })
-  })
-}
+  }
 
-// ---------------------------------------------------------------------------
+  getEnv () {
+    return `NODE_ENV=test NODE_APP_INSTANCE=${this.server.internalServerNumber}`
+  }
+
+  async execWithEnv (command: string) {
+    return CLICommand.exec(`${this.getEnv()} ${command}`)
+  }
+}
 
 export {
-  execCLI,
-  getEnvCli
+  CLICommand
 }
diff --git a/shared/extra-utils/cli/index.ts b/shared/extra-utils/cli/index.ts
new file mode 100644
index 000000000..8a3f31e2f
--- /dev/null
+++ b/shared/extra-utils/cli/index.ts
@@ -0,0 +1 @@
+export * from './cli'
-- 
cgit v1.2.3