diff options
author | Chocobozzz <me@florianbigard.com> | 2019-06-13 11:09:38 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-06-13 11:09:38 +0200 |
commit | 1a12f66d631d28a5a58ebbcd274426f2e6e5d203 (patch) | |
tree | edaf546dfc8bcdb55d271111618e65569aa68cc0 /server/tools/peertube-auth.ts | |
parent | 4913295f9db1a7b814129d90b159a418cb32bb75 (diff) | |
download | PeerTube-1a12f66d631d28a5a58ebbcd274426f2e6e5d203.tar.gz PeerTube-1a12f66d631d28a5a58ebbcd274426f2e6e5d203.tar.zst PeerTube-1a12f66d631d28a5a58ebbcd274426f2e6e5d203.zip |
Add more CLI tests
Diffstat (limited to 'server/tools/peertube-auth.ts')
-rw-r--r-- | server/tools/peertube-auth.ts | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/server/tools/peertube-auth.ts b/server/tools/peertube-auth.ts index e53283fbe..ff5ffb60e 100644 --- a/server/tools/peertube-auth.ts +++ b/server/tools/peertube-auth.ts | |||
@@ -9,7 +9,11 @@ const Table = require('cli-table') | |||
9 | async function delInstance (url: string) { | 9 | async function delInstance (url: string) { |
10 | const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ]) | 10 | const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ]) |
11 | 11 | ||
12 | settings.remotes.splice(settings.remotes.indexOf(url)) | 12 | const index = settings.remotes.indexOf(url) |
13 | settings.remotes.splice(index) | ||
14 | |||
15 | if (settings.default === index) settings.default = -1 | ||
16 | |||
13 | await writeSettings(settings) | 17 | await writeSettings(settings) |
14 | 18 | ||
15 | delete netrc.machines[url] | 19 | delete netrc.machines[url] |
@@ -17,12 +21,17 @@ async function delInstance (url: string) { | |||
17 | await netrc.save() | 21 | await netrc.save() |
18 | } | 22 | } |
19 | 23 | ||
20 | async function setInstance (url: string, username: string, password: string) { | 24 | async function setInstance (url: string, username: string, password: string, isDefault: boolean) { |
21 | const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ]) | 25 | const [ settings, netrc ] = await Promise.all([ getSettings(), getNetrc() ]) |
22 | 26 | ||
23 | if (settings.remotes.indexOf(url) === -1) { | 27 | if (settings.remotes.indexOf(url) === -1) { |
24 | settings.remotes.push(url) | 28 | settings.remotes.push(url) |
25 | } | 29 | } |
30 | |||
31 | if (isDefault || settings.remotes.length === 1) { | ||
32 | settings.default = settings.remotes.length - 1 | ||
33 | } | ||
34 | |||
26 | await writeSettings(settings) | 35 | await writeSettings(settings) |
27 | 36 | ||
28 | netrc.machines[url] = { login: username, password } | 37 | netrc.machines[url] = { login: username, password } |
@@ -66,7 +75,7 @@ program | |||
66 | } | 75 | } |
67 | } | 76 | } |
68 | }, async (_, result) => { | 77 | }, async (_, result) => { |
69 | await setInstance(result.url, result.username, result.password) | 78 | await setInstance(result.url, result.username, result.password, program['default']) |
70 | 79 | ||
71 | process.exit(0) | 80 | process.exit(0) |
72 | }) | 81 | }) |