diff --git a/README.md b/README.md index 82e9038..0a7beff 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,13 @@ specific options are available exclusively as CLI options. ```text Usage: telegram-history-dump.rb [options] - -c, --config=cfgfile.yaml Path to configuration file + -c, --config=cfg.yaml Path to YAML configuration file -k, --kill-tg Kill telegram-cli after backup -h, --help Show help + -d, --dir=DIR Subdirectory for output files + (relative to backup_dir in YAML config) + -l, --limit=LIMIT Maximum number of messages to backup + for each target (overrides YAML config) ``` ## Notes diff --git a/lib/cli_parser.rb b/lib/cli_parser.rb index f78438e..eaf39da 100644 --- a/lib/cli_parser.rb +++ b/lib/cli_parser.rb @@ -4,30 +4,34 @@ class CliParser def self.parse(options) - args = Options.new() + args = Options.new opt_parser = OptionParser.new do |opts| - opts.banner = "Usage: telegram-history-dump.rb [options]" + opts.banner = 'Usage: telegram-history-dump.rb [options]' - opts.on("-c", "--config=cfgfile.yaml", - "Path to configuration file") do |str| - args.cfgfile = str + opts.on('-cCFG', '--config=cfg.yaml', String, + 'Path to YAML configuration file') do |cfgfile| + args.cfgfile = cfgfile end - opts.on("-k", "--kill-tg", "Kill telegram-cli after backup") do |bool| - args.kill_tg = bool + opts.on('-k', '--kill-tg', 'Kill telegram-cli after backup') do |kill_tg| + args.kill_tg = kill_tg end - opts.on("-h", "--help", "Show help") do + opts.on('-h', '--help', 'Show help') do puts opts exit end - opts.on("-dDIR", "--dir=DIR", String, "Subdirectory for logs") do |userdir| + opts.on('-dDIR', '--dir=DIR', String, + 'Subdirectory for output files', + '(relative to backup_dir in YAML config)') 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| + opts.on('-lLIMIT', '--limit=LIMIT', Integer, + 'Maximum number of messages to backup', + 'for each target (overrides YAML config)') do |backlog_limit| args.backlog_limit = backlog_limit end @@ -37,5 +41,3 @@ def self.parse(options) return args end end - - diff --git a/telegram-history-dump.rb b/telegram-history-dump.rb index 3f2d659..6311f1b 100755 --- a/telegram-history-dump.rb +++ b/telegram-history-dump.rb @@ -194,20 +194,16 @@ def save_progress ) $log = Logger.new(STDOUT) -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 +unless cli_opts.userdir.nil? || cli_opts.userdir.empty? + $config['backup_dir'] = File.join($config['backup_dir'], cli_opts.userdir) 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 +unless cli_opts.backlog_limit.nil? || cli_opts.backlog_limit < 0 + $config['backlog_limit'] = cli_opts.backlog_limit end +FileUtils.mkdir_p(get_backup_dir) + $dumper = JsonDumper.new $progress = {} $progress_snapshot = {}