aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/cli.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/cli.ts')
-rw-r--r--server/tools/cli.ts52
1 files changed, 28 insertions, 24 deletions
diff --git a/server/tools/cli.ts b/server/tools/cli.ts
index d5416fc38..cc89fe46e 100644
--- a/server/tools/cli.ts
+++ b/server/tools/cli.ts
@@ -69,23 +69,25 @@ function deleteSettings () {
69} 69}
70 70
71function getRemoteObjectOrDie ( 71function getRemoteObjectOrDie (
72 program: any, 72 program: CommanderStatic,
73 settings: Settings, 73 settings: Settings,
74 netrc: Netrc 74 netrc: Netrc
75): { url: string, username: string, password: string } { 75): { url: string, username: string, password: string } {
76 if (!program['url'] || !program['username'] || !program['password']) { 76 const options = program.opts()
77
78 if (!options.url || !options.username || !options.password) {
77 // No remote and we don't have program parameters: quit 79 // No remote and we don't have program parameters: quit
78 if (settings.remotes.length === 0 || Object.keys(netrc.machines).length === 0) { 80 if (settings.remotes.length === 0 || Object.keys(netrc.machines).length === 0) {
79 if (!program['url']) console.error('--url field is required.') 81 if (!options.url) console.error('--url field is required.')
80 if (!program['username']) console.error('--username field is required.') 82 if (!options.username) console.error('--username field is required.')
81 if (!program['password']) console.error('--password field is required.') 83 if (!options.password) console.error('--password field is required.')
82 84
83 return process.exit(-1) 85 return process.exit(-1)
84 } 86 }
85 87
86 let url: string = program['url'] 88 let url: string = options.url
87 let username: string = program['username'] 89 let username: string = options.username
88 let password: string = program['password'] 90 let password: string = options.password
89 91
90 if (!url && settings.default !== -1) url = settings.remotes[settings.default] 92 if (!url && settings.default !== -1) url = settings.remotes[settings.default]
91 93
@@ -98,9 +100,9 @@ function getRemoteObjectOrDie (
98 } 100 }
99 101
100 return { 102 return {
101 url: program['url'], 103 url: options.url,
102 username: program['username'], 104 username: options.username,
103 password: program['password'] 105 password: options.password
104 } 106 }
105} 107}
106 108
@@ -127,6 +129,8 @@ function buildCommonVideoOptions (command: CommanderStatic) {
127} 129}
128 130
129async function buildVideoAttributesFromCommander (url: string, command: CommanderStatic, defaultAttributes: any = {}) { 131async function buildVideoAttributesFromCommander (url: string, command: CommanderStatic, defaultAttributes: any = {}) {
132 const options = command.opts()
133
130 const defaultBooleanAttributes = { 134 const defaultBooleanAttributes = {
131 nsfw: false, 135 nsfw: false,
132 commentsEnabled: true, 136 commentsEnabled: true,
@@ -137,8 +141,8 @@ async function buildVideoAttributesFromCommander (url: string, command: Commande
137 const booleanAttributes: { [id in keyof typeof defaultBooleanAttributes]: boolean } | {} = {} 141 const booleanAttributes: { [id in keyof typeof defaultBooleanAttributes]: boolean } | {} = {}
138 142
139 for (const key of Object.keys(defaultBooleanAttributes)) { 143 for (const key of Object.keys(defaultBooleanAttributes)) {
140 if (command[key] !== undefined) { 144 if (options[key] !== undefined) {
141 booleanAttributes[key] = command[key] 145 booleanAttributes[key] = options[key]
142 } else if (defaultAttributes[key] !== undefined) { 146 } else if (defaultAttributes[key] !== undefined) {
143 booleanAttributes[key] = defaultAttributes[key] 147 booleanAttributes[key] = defaultAttributes[key]
144 } else { 148 } else {
@@ -147,20 +151,20 @@ async function buildVideoAttributesFromCommander (url: string, command: Commande
147 } 151 }
148 152
149 const videoAttributes = { 153 const videoAttributes = {
150 name: command['videoName'] || defaultAttributes.name, 154 name: options.videoName || defaultAttributes.name,
151 category: command['category'] || defaultAttributes.category || undefined, 155 category: options.category || defaultAttributes.category || undefined,
152 licence: command['licence'] || defaultAttributes.licence || undefined, 156 licence: options.licence || defaultAttributes.licence || undefined,
153 language: command['language'] || defaultAttributes.language || undefined, 157 language: options.language || defaultAttributes.language || undefined,
154 privacy: command['privacy'] || defaultAttributes.privacy || VideoPrivacy.PUBLIC, 158 privacy: options.privacy || defaultAttributes.privacy || VideoPrivacy.PUBLIC,
155 support: command['support'] || defaultAttributes.support || undefined, 159 support: options.support || defaultAttributes.support || undefined,
156 description: command['videoDescription'] || defaultAttributes.description || undefined, 160 description: options.videoDescription || defaultAttributes.description || undefined,
157 tags: command['tags'] || defaultAttributes.tags || undefined 161 tags: options.tags || defaultAttributes.tags || undefined
158 } 162 }
159 163
160 Object.assign(videoAttributes, booleanAttributes) 164 Object.assign(videoAttributes, booleanAttributes)
161 165
162 if (command['channelName']) { 166 if (options.channelName) {
163 const res = await getVideoChannel(url, command['channelName']) 167 const res = await getVideoChannel(url, options.channelName)
164 const videoChannel: VideoChannel = res.body 168 const videoChannel: VideoChannel = res.body
165 169
166 Object.assign(videoAttributes, { channelId: videoChannel.id }) 170 Object.assign(videoAttributes, { channelId: videoChannel.id })
@@ -173,7 +177,7 @@ async function buildVideoAttributesFromCommander (url: string, command: Commande
173 return videoAttributes 177 return videoAttributes
174} 178}
175 179
176function getServerCredentials (program: any) { 180function getServerCredentials (program: CommanderStatic) {
177 return Promise.all([ getSettings(), getNetrc() ]) 181 return Promise.all([ getSettings(), getNetrc() ])
178 .then(([ settings, netrc ]) => { 182 .then(([ settings, netrc ]) => {
179 return getRemoteObjectOrDie(program, settings, netrc) 183 return getRemoteObjectOrDie(program, settings, netrc)