From ca07d754052197384cd166463900669592a10b2f Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 6 Apr 2019 08:28:53 -0500 Subject: [PATCH] Add '--version' to command line --- README.md | 6 ++-- src/invidious.cr | 76 ++++++++++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 0d02fe32..70f2c500 100644 --- a/README.md +++ b/README.md @@ -172,15 +172,12 @@ Usage: invidious [arguments] --ssl-key-file FILE SSL key file --ssl-cert-file FILE SSL certificate file -h, --help Shows this help - -t THREADS, --crawl-threads=THREADS - Number of threads for crawling YouTube (default: 0) -c THREADS, --channel-threads=THREADS Number of threads for refreshing channels (default: 1) -f THREADS, --feed-threads=THREADS Number of threads for refreshing feeds (default: 1) - -v THREADS, --video-threads=THREADS - Number of threads for refreshing videos (default: 0) -o OUTPUT, --output=OUTPUT Redirect output (default: STDOUT) + -v, --version Print version ``` Or for development: @@ -188,6 +185,7 @@ Or for development: ```bash $ curl -fsSLo- https://raw.githubusercontent.com/samueleaton/sentry/master/install.cr | crystal eval $ ./sentry +🤖 Your SentryBot is vigilant. beep-boop... ``` ## Documentation diff --git a/src/invidious.cr b/src/invidious.cr index 53edf843..9aa27205 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -31,35 +31,6 @@ require "./invidious/*" CONFIG = Config.from_yaml(File.read("config/config.yml")) HMAC_KEY = CONFIG.hmac_key || Random::Secure.hex(32) -config = CONFIG -logger = Invidious::LogHandler.new - -Kemal.config.extra_options do |parser| - parser.banner = "Usage: invidious [arguments]" - parser.on("-c THREADS", "--channel-threads=THREADS", "Number of threads for refreshing channels (default: #{config.channel_threads})") do |number| - begin - config.channel_threads = number.to_i - rescue ex - puts "THREADS must be integer" - exit - end - end - parser.on("-f THREADS", "--feed-threads=THREADS", "Number of threads for refreshing feeds (default: #{config.feed_threads})") do |number| - begin - config.feed_threads = number.to_i - rescue ex - puts "THREADS must be integer" - exit - end - end - parser.on("-o OUTPUT", "--output=OUTPUT", "Redirect output (default: STDOUT)") do |output| - FileUtils.mkdir_p(File.dirname(output)) - logger = Invidious::LogHandler.new(File.open(output, mode: "a")) - end -end - -Kemal::CLI.new ARGV - PG_URL = URI.new( scheme: "postgres", user: CONFIG.db[:user], @@ -81,6 +52,12 @@ CURRENT_BRANCH = {{ "#{`git branch | sed -n '/\* /s///p'`.strip}" }} CURRENT_COMMIT = {{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit`.strip}" }} CURRENT_VERSION = {{ "#{`git describe --tags --abbrev=0`.strip}" }} +SOFTWARE = { + "name" => "invidious", + "version" => "#{CURRENT_VERSION}-#{CURRENT_COMMIT}", + "branch" => "#{CURRENT_BRANCH}", +} + LOCALES = { "ar" => load_locale("ar"), "de" => load_locale("de"), @@ -95,6 +72,39 @@ LOCALES = { "ru" => load_locale("ru"), } +config = CONFIG +logger = Invidious::LogHandler.new + +Kemal.config.extra_options do |parser| + parser.banner = "Usage: invidious [arguments]" + parser.on("-c THREADS", "--channel-threads=THREADS", "Number of threads for refreshing channels (default: #{config.channel_threads})") do |number| + begin + config.channel_threads = number.to_i + rescue ex + puts "THREADS must be integer" + exit + end + end + parser.on("-f THREADS", "--feed-threads=THREADS", "Number of threads for refreshing feeds (default: #{config.feed_threads})") do |number| + begin + config.feed_threads = number.to_i + rescue ex + puts "THREADS must be integer" + exit + end + end + parser.on("-o OUTPUT", "--output=OUTPUT", "Redirect output (default: STDOUT)") do |output| + FileUtils.mkdir_p(File.dirname(output)) + logger = Invidious::LogHandler.new(File.open(output, mode: "a")) + end + parser.on("-v", "--version", "Print version") do |output| + puts SOFTWARE.to_pretty_json + exit + end +end + +Kemal::CLI.new ARGV + refresh_channels(PG_DB, logger, config.channel_threads, config.full_refresh) refresh_feeds(PG_DB, logger, config.feed_threads) @@ -108,12 +118,8 @@ if config.statistics_enabled spawn do loop do statistics = { - "version" => "2.0", - "software" => { - "name" => "invidious", - "version" => "#{CURRENT_VERSION}-#{CURRENT_COMMIT}", - "branch" => "#{CURRENT_BRANCH}", - }, + "version" => "2.0", + "software" => SOFTWARE, "openRegistrations" => config.registration_enabled, "usage" => { "users" => {