diff options
Diffstat (limited to 'server/tools/cli.ts')
-rw-r--r-- | server/tools/cli.ts | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/server/tools/cli.ts b/server/tools/cli.ts index 7036ae3ec..671b56ed0 100644 --- a/server/tools/cli.ts +++ b/server/tools/cli.ts | |||
@@ -73,14 +73,13 @@ function getRemoteObjectOrDie ( | |||
73 | ): { url: string, username: string, password: string } { | 73 | ): { url: string, username: string, password: string } { |
74 | const options = program.opts() | 74 | const options = program.opts() |
75 | 75 | ||
76 | const manualOptionMode = options.url || options.username || options.password | 76 | function exitIfNoOptions (options: string[], errorPrefix: string = '') { |
77 | |||
78 | // Check parameters validity | ||
79 | if (manualOptionMode || settings.remotes.length === 0 || Object.keys(netrc.machines).length === 0) { | ||
80 | let exit = false | 77 | let exit = false |
81 | 78 | ||
82 | for (const key of [ 'url', 'username', 'password' ]) { | 79 | for (const key of options) { |
83 | if (!options[key]) { | 80 | if (!options[key]) { |
81 | if (exit === false && errorPrefix) console.error(errorPrefix) | ||
82 | |||
84 | console.error(`--${key} field is required`) | 83 | console.error(`--${key} field is required`) |
85 | exit = true | 84 | exit = true |
86 | } | 85 | } |
@@ -89,26 +88,36 @@ function getRemoteObjectOrDie ( | |||
89 | if (exit) process.exit(-1) | 88 | if (exit) process.exit(-1) |
90 | } | 89 | } |
91 | 90 | ||
92 | if (!manualOptionMode) { | 91 | // If username or password are specified, both are mandatory |
93 | let url: string = options.url | 92 | if (options.username || options.password) { |
94 | let username: string = options.username | 93 | exitIfNoOptions([ 'username', 'password' ]) |
95 | let password: string = options.password | 94 | } |
96 | 95 | ||
97 | if (!url && settings.default !== -1) url = settings.remotes[settings.default] | 96 | // If no available machines, url, username and password args are mandatory |
97 | if (Object.keys(netrc.machines).length === 0) { | ||
98 | exitIfNoOptions([ 'url', 'username', 'password' ], 'No account found in netrc') | ||
99 | } | ||
98 | 100 | ||
99 | const machine = netrc.machines[url] | 101 | if (settings.remotes.length === 0 || settings.default === -1) { |
102 | exitIfNoOptions([ 'url' ], 'No default instance found') | ||
103 | } | ||
100 | 104 | ||
101 | if (!username && machine) username = machine.login | 105 | let url: string = options.url |
102 | if (!password && machine) password = machine.password | 106 | let username: string = options.username |
107 | let password: string = options.password | ||
103 | 108 | ||
104 | return { url, username, password } | 109 | if (!url && settings.default !== -1) url = settings.remotes[settings.default] |
105 | } | ||
106 | 110 | ||
107 | return { | 111 | const machine = netrc.machines[url] |
108 | url: options.url, | 112 | if ((!username || !password) && !machine) { |
109 | username: options.username, | 113 | console.error('Cannot find existing configuration for %s.', url) |
110 | password: options.password | 114 | process.exit(-1) |
111 | } | 115 | } |
116 | |||
117 | if (!username && machine) username = machine.login | ||
118 | if (!password && machine) password = machine.password | ||
119 | |||
120 | return { url, username, password } | ||
112 | } | 121 | } |
113 | 122 | ||
114 | function buildCommonVideoOptions (command: Command) { | 123 | function buildCommonVideoOptions (command: Command) { |