]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/cli/cli.ts
Introduce CLI command
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / cli / cli.ts
index c62e170bb323ee436efac0dace62f2936411080a..1bf100869017c19b9bf8cc398f622d8f425603ed 100644 (file)
@@ -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
 }