Skip to content

Commit

Permalink
Restructure/restyle cli options related code, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdstaaij committed May 22, 2016
1 parent 231e222 commit 7de3128
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions lib/cli_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -37,5 +41,3 @@ def self.parse(options)
return args
end
end


16 changes: 6 additions & 10 deletions telegram-history-dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit 7de3128

Please sign in to comment.