aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/cli.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2018-09-13 14:27:44 +0200
committerRigel Kent <sendmemail@rigelk.eu>2018-09-14 11:08:55 +0200
commit8704acf49efc770d73bf07c10468ed8c74d28a83 (patch)
treeffd46289fcf9a13ac4412b167e9f71dfb35753c5 /server/tools/cli.ts
parent1d9d9cfdcf3983e3fd89026bc4b5633a8abf5752 (diff)
downloadPeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.tar.gz
PeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.tar.zst
PeerTube-8704acf49efc770d73bf07c10468ed8c74d28a83.zip
one cli to unite them all
Ash nazg thrakatulûk agh burzum-ishi krimpatul - refactor import-videos to use the youtubeDL helper - add very basic tests for the cli
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}