1 const config = require('application-config')('PeerTube/CLI')
2 const netrc = require('netrc-parser').default
4 const version = require('../../../package.json').version
11 function getSettings () {
12 return new Promise<Settings>((res, rej) => {
13 const defaultSettings = {
18 config.read((err, data) => {
19 if (err) return rej(err)
21 return res(Object.keys(data).length === 0 ? defaultSettings : data)
26 async function getNetrc () {
32 function writeSettings (settings) {
33 return new Promise((res, rej) => {
34 config.write(settings, function (err) {
35 if (err) return rej(err)
42 function getRemoteObjectOrDie (program: any, settings: Settings) {
43 if (!program['url'] || !program['username'] || !program['password']) {
44 // No remote and we don't have program parameters: throw
45 if (settings.remotes.length === 0) {
46 if (!program[ 'url' ]) console.error('--url field is required.')
47 if (!program[ 'username' ]) console.error('--username field is required.')
48 if (!program[ 'password' ]) console.error('--password field is required.')
50 return process.exit(-1)
53 let url: string = program['url']
54 let username: string = program['username']
55 let password: string = program['password']
58 url = settings.default !== -1
59 ? settings.remotes[settings.default]
63 if (!username) username = netrc.machines[url].login
64 if (!password) password = netrc.machines[url].password
66 return { url, username, password }
70 url: program[ 'url' ],
71 username: program[ 'username' ],
72 password: program[ 'password' ]
76 // ---------------------------------------------------------------------------