Add '--version' to command line

pull/366/head
Omar Roth 6 years ago
parent c5001f3620
commit ca07d75405

@ -172,15 +172,12 @@ Usage: invidious [arguments]
--ssl-key-file FILE SSL key file --ssl-key-file FILE SSL key file
--ssl-cert-file FILE SSL certificate file --ssl-cert-file FILE SSL certificate file
-h, --help Shows this help -h, --help Shows this help
-t THREADS, --crawl-threads=THREADS
Number of threads for crawling YouTube (default: 0)
-c THREADS, --channel-threads=THREADS -c THREADS, --channel-threads=THREADS
Number of threads for refreshing channels (default: 1) Number of threads for refreshing channels (default: 1)
-f THREADS, --feed-threads=THREADS -f THREADS, --feed-threads=THREADS
Number of threads for refreshing feeds (default: 1) 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) -o OUTPUT, --output=OUTPUT Redirect output (default: STDOUT)
-v, --version Print version
``` ```
Or for development: Or for development:
@ -188,6 +185,7 @@ Or for development:
```bash ```bash
$ curl -fsSLo- https://raw.githubusercontent.com/samueleaton/sentry/master/install.cr | crystal eval $ curl -fsSLo- https://raw.githubusercontent.com/samueleaton/sentry/master/install.cr | crystal eval
$ ./sentry $ ./sentry
🤖 Your SentryBot is vigilant. beep-boop...
``` ```
## Documentation ## Documentation

@ -31,35 +31,6 @@ require "./invidious/*"
CONFIG = Config.from_yaml(File.read("config/config.yml")) CONFIG = Config.from_yaml(File.read("config/config.yml"))
HMAC_KEY = CONFIG.hmac_key || Random::Secure.hex(32) 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( PG_URL = URI.new(
scheme: "postgres", scheme: "postgres",
user: CONFIG.db[:user], 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_COMMIT = {{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit`.strip}" }}
CURRENT_VERSION = {{ "#{`git describe --tags --abbrev=0`.strip}" }} CURRENT_VERSION = {{ "#{`git describe --tags --abbrev=0`.strip}" }}
SOFTWARE = {
"name" => "invidious",
"version" => "#{CURRENT_VERSION}-#{CURRENT_COMMIT}",
"branch" => "#{CURRENT_BRANCH}",
}
LOCALES = { LOCALES = {
"ar" => load_locale("ar"), "ar" => load_locale("ar"),
"de" => load_locale("de"), "de" => load_locale("de"),
@ -95,6 +72,39 @@ LOCALES = {
"ru" => load_locale("ru"), "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_channels(PG_DB, logger, config.channel_threads, config.full_refresh)
refresh_feeds(PG_DB, logger, config.feed_threads) refresh_feeds(PG_DB, logger, config.feed_threads)
@ -108,12 +118,8 @@ if config.statistics_enabled
spawn do spawn do
loop do loop do
statistics = { statistics = {
"version" => "2.0", "version" => "2.0",
"software" => { "software" => SOFTWARE,
"name" => "invidious",
"version" => "#{CURRENT_VERSION}-#{CURRENT_COMMIT}",
"branch" => "#{CURRENT_BRANCH}",
},
"openRegistrations" => config.registration_enabled, "openRegistrations" => config.registration_enabled,
"usage" => { "usage" => {
"users" => { "users" => {

Loading…
Cancel
Save