aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/cli.ts
diff options
context:
space:
mode:
authorFrank de Lange <github-f@unternet.org>2019-08-26 11:35:28 +0200
committerChocobozzz <me@florianbigard.com>2019-08-26 11:35:28 +0200
commitbda3b70537549d3b4f22a56f8fd020e88f19f2a5 (patch)
treee52c88ce2da6fa2555e75f56f36d720fc890ddac /server/tools/cli.ts
parentf3ea7ecee11359d09b62804f95366710d295015d (diff)
downloadPeerTube-bda3b70537549d3b4f22a56f8fd020e88f19f2a5.tar.gz
PeerTube-bda3b70537549d3b4f22a56f8fd020e88f19f2a5.tar.zst
PeerTube-bda3b70537549d3b4f22a56f8fd020e88f19f2a5.zip
peertube-import-videos.ts: add --tmpdir, --first, --last and --verbose [level] parameters (#2045)
* peertube-import-videos.ts: add --tmpdir <tmpdir> parameter, used to designate working directory for downloading and converting imported videos * peertube-import-videos.ts: add --first and --last parameters to limit processing of the returned playlist to the first/last N elements * peertube-import-videos.ts: add --verbose [verbosity] parameter, set this from 0 (only errors are reported) to 4 (for trace debugging), default is 2 (info). When --verbose is used without the optional parameter the logging level is set to 3 (debug). At level 1 (warn) it will only report on successfully uploaded videos (and/or errors), use this when running peertube-import-videos in a cron job to mirror a channel. * package.json: remove dependency on loglevel cli.ts: add getLogger(loglevel), to be used in CLI tools, add --verbose to set log level peertube-import-videos: use getLogger (from cli) instead of loglevel, add error_exit (log error and exit), move --verbose to cli.ts, etc. * cli.ts: remove superfluous reference to default logging level * peertube-import-videos: exit_error -> exitError
Diffstat (limited to 'server/tools/cli.ts')
-rw-r--r--server/tools/cli.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/server/tools/cli.ts b/server/tools/cli.ts
index 8599a270f..58e2445ac 100644
--- a/server/tools/cli.ts
+++ b/server/tools/cli.ts
@@ -5,6 +5,7 @@ import { root } from '../../shared/extra-utils/miscs/miscs'
5import { getVideoChannel } from '../../shared/extra-utils/videos/video-channels' 5import { getVideoChannel } from '../../shared/extra-utils/videos/video-channels'
6import { Command } from 'commander' 6import { Command } from 'commander'
7import { VideoChannel, VideoPrivacy } from '../../shared/models/videos' 7import { VideoChannel, VideoPrivacy } from '../../shared/models/videos'
8import { createLogger, format, transports } from 'winston'
8 9
9let configName = 'PeerTube/CLI' 10let configName = 'PeerTube/CLI'
10if (isTestInstance()) configName += `-${getAppNumber()}` 11if (isTestInstance()) configName += `-${getAppNumber()}`
@@ -119,6 +120,7 @@ function buildCommonVideoOptions (command: Command) {
119 .option('-m, --comments-enabled', 'Enable comments') 120 .option('-m, --comments-enabled', 'Enable comments')
120 .option('-s, --support <support>', 'Video support text') 121 .option('-s, --support <support>', 'Video support text')
121 .option('-w, --wait-transcoding', 'Wait transcoding before publishing the video') 122 .option('-w, --wait-transcoding', 'Wait transcoding before publishing the video')
123 .option('-v, --verbose <verbose>', 'Verbosity, from 0/\'error\' to 4/\'debug\'', 'info')
122} 124}
123 125
124async function buildVideoAttributesFromCommander (url: string, command: Command, defaultAttributes: any = {}) { 126async function buildVideoAttributesFromCommander (url: string, command: Command, defaultAttributes: any = {}) {
@@ -175,11 +177,42 @@ function getServerCredentials (program: any) {
175 }) 177 })
176} 178}
177 179
180function getLogger (logLevel = 'info') {
181 const logLevels = {
182 0: 0,
183 error: 0,
184 1: 1,
185 warn: 1,
186 2: 2,
187 info: 2,
188 3: 3,
189 verbose: 3,
190 4: 4,
191 debug: 4
192 }
193
194 const logger = createLogger({
195 levels: logLevels,
196 format: format.combine(
197 format.splat(),
198 format.simple()
199 ),
200 transports: [
201 new (transports.Console)({
202 level: logLevel
203 })
204 ]
205 })
206
207 return logger
208}
209
178// --------------------------------------------------------------------------- 210// ---------------------------------------------------------------------------
179 211
180export { 212export {
181 version, 213 version,
182 config, 214 config,
215 getLogger,
183 getSettings, 216 getSettings,
184 getNetrc, 217 getNetrc,
185 getRemoteObjectOrDie, 218 getRemoteObjectOrDie,