diff --git a/lib/cli_parser.rb b/lib/cli_parser.rb index 9534846..f78438e 100644 --- a/lib/cli_parser.rb +++ b/lib/cli_parser.rb @@ -1,6 +1,6 @@ require 'optparse' -Options = Struct.new(:cfgfile, :kill_tg) +Options = Struct.new(:cfgfile, :kill_tg, :userdir, :backlog_limit) class CliParser def self.parse(options) @@ -22,6 +22,15 @@ def self.parse(options) puts opts exit end + + opts.on("-dDIR", "--dir=DIR", String, "Subdirectory for logs") do |userdir| + args.userdir = userdir + end + + opts.on("-lLIMIT", "--limit=LIMIT", Integer, "Maximum number of messages to backup for each target (0 means unlimited)") do |backlog_limit| + args.backlog_limit = backlog_limit + end + end opt_parser.parse!(options) diff --git a/telegram-history-dump.rb b/telegram-history-dump.rb index 9008b94..3f2d659 100755 --- a/telegram-history-dump.rb +++ b/telegram-history-dump.rb @@ -196,6 +196,18 @@ def save_progress FileUtils.mkdir_p(get_backup_dir) +if !cli_opts[:userdir].nil? + if !cli_opts.userdir.empty? || !cli_opts.userdir.nil? + $config['backup_dir'] = File.join($config['backup_dir'],cli_opts.userdir) + end +end + +if !cli_opts[:backlog_limit].nil? + if !cli_opts.backlog_limit.empty? || !cli_opts.backlog_limit.nil? + $config['backlog_limit'] = cli_opts.backlog_limit + end +end + $dumper = JsonDumper.new $progress = {} $progress_snapshot = {}