]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/cli/cli.ts
Introduce CLI command
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / cli / cli.ts
1 import { exec } from 'child_process'
2 import { AbstractCommand } from '../shared'
3
4 class CLICommand extends AbstractCommand {
5
6 static exec (command: string) {
7 return new Promise<string>((res, rej) => {
8 exec(command, (err, stdout, _stderr) => {
9 if (err) return rej(err)
10
11 return res(stdout)
12 })
13 })
14 }
15
16 getEnv () {
17 return `NODE_ENV=test NODE_APP_INSTANCE=${this.server.internalServerNumber}`
18 }
19
20 async execWithEnv (command: string) {
21 return CLICommand.exec(`${this.getEnv()} ${command}`)
22 }
23 }
24
25 export {
26 CLICommand
27 }