aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/cli.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-20 16:24:49 +0200
committerGitHub <noreply@github.com>2018-09-20 16:24:49 +0200
commitdc27668fceb1d0270c391c93c3bbc95d12e83218 (patch)
treece6621597505f9518cfdf0981977d097c63f9fad /server/tools/cli.ts
parent6247b2057b792cea155a1abd9788c363ae7d2cc2 (diff)
parent0491173a61aed66205c017e0d7e0503ea316c144 (diff)
downloadPeerTube-dc27668fceb1d0270c391c93c3bbc95d12e83218.tar.gz
PeerTube-dc27668fceb1d0270c391c93c3bbc95d12e83218.tar.zst
PeerTube-dc27668fceb1d0270c391c93c3bbc95d12e83218.zip
Merge pull request #941 from rigelk/cli-wrapper
adding cli wrapper
Diffstat (limited to 'server/tools/cli.ts')
-rw-r--r--server/tools/cli.ts63
1 files changed, 63 insertions, 0 deletions
diff --git a/server/tools/cli.ts b/server/tools/cli.ts
new file mode 100644
index 000000000..9a170d4da
--- /dev/null
+++ b/server/tools/cli.ts
@@ -0,0 +1,63 @@
1const config = require('application-config')('PeerTube/CLI')
2const netrc = require('netrc-parser').default
3
4const version = () => {
5 const tag = require('child_process')
6 .execSync('[[ ! -d .git ]] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true', { stdio: [0,1,2] })
7 if (tag) return tag
8
9 const version = require('child_process')
10 .execSync('[[ ! -d .git ]] || git rev-parse --short HEAD').toString().trim()
11 if (version) return version
12
13 return require('../../../package.json').version
14}
15
16let settings = {
17 remotes: [],
18 default: 0
19}
20
21interface Settings {
22 remotes: any[],
23 default: number
24}
25
26async function getSettings () {
27 return new Promise<Settings>((res, rej) => {
28 let settings = {
29 remotes: [],
30 default: 0
31 } as Settings
32 config.read((err, data) => {
33 if (err) {
34 return rej(err)
35 }
36 return res(data || settings)
37 })
38 })
39}
40
41async function writeSettings (settings) {
42 return new Promise((res, rej) => {
43 config.write(settings, function (err) {
44 if (err) {
45 return rej(err)
46 }
47 return res()
48 })
49 })
50}
51
52netrc.loadSync()
53
54// ---------------------------------------------------------------------------
55
56export {
57 version,
58 config,
59 settings,
60 getSettings,
61 writeSettings,
62 netrc
63}