aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/cli
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-05 16:37:50 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:16 +0200
commit329619b3453479f76c049816b7403b86e9d45cb5 (patch)
treee522940946402a4284d356f2cde8e0dcbe29b289 /shared/extra-utils/cli
parenta6a79eae0d8564099b6957e76d7a18528d9ef124 (diff)
downloadPeerTube-329619b3453479f76c049816b7403b86e9d45cb5.tar.gz
PeerTube-329619b3453479f76c049816b7403b86e9d45cb5.tar.zst
PeerTube-329619b3453479f76c049816b7403b86e9d45cb5.zip
Introduce CLI command
Diffstat (limited to 'shared/extra-utils/cli')
-rw-r--r--shared/extra-utils/cli/cli.ts33
-rw-r--r--shared/extra-utils/cli/index.ts1
2 files changed, 19 insertions, 15 deletions
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 @@
1import { exec } from 'child_process' 1import { exec } from 'child_process'
2import { AbstractCommand } from '../shared'
2 3
3import { ServerInfo } from '../server/servers' 4class CLICommand extends AbstractCommand {
4 5
5function getEnvCli (server?: ServerInfo) { 6 static exec (command: string) {
6 return `NODE_ENV=test NODE_APP_INSTANCE=${server.internalServerNumber}` 7 return new Promise<string>((res, rej) => {
7} 8 exec(command, (err, stdout, _stderr) => {
8 9 if (err) return rej(err)
9async function execCLI (command: string) {
10 return new Promise<string>((res, rej) => {
11 exec(command, (err, stdout, stderr) => {
12 if (err) return rej(err)
13 10
14 return res(stdout) 11 return res(stdout)
12 })
15 }) 13 })
16 }) 14 }
17}
18 15
19// --------------------------------------------------------------------------- 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}
20 24
21export { 25export {
22 execCLI, 26 CLICommand
23 getEnvCli
24} 27}
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'