Module: GitBak::Executable

Defined in:
lib/gitbak/exec.rb

Overview

command-line executable

Constant Summary collapse

INFO =

description

'gitbak - bitbucket/github/gist backup'
USAGE =

command-line usage

'gitbak [<option(s)>]'

Class Method Summary collapse

Class Method Details

.configure(file) ⇒ Object

parse configuration file; die on failure



69
70
71
72
73
# File 'lib/gitbak/exec.rb', line 69

def self.configure(file)
  GitBak::Misc.die! "configuration file (#{file}) not found" \
    unless GitBak::Misc.exists? file
  GitBak.configure file
end

.main(args = nil) ⇒ Object

run!



76
77
78
79
80
# File 'lib/gitbak/exec.rb', line 76

def self.main(args = nil)
  options = parse_options(args || ARGV)
  cfg     = configure options[:cfgfile]
  GitBak.main options[:verbose], options[:noact], cfg
end

.parse_options(args) ⇒ Object

parse command line options; die on failure



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gitbak/exec.rb', line 36

def self.parse_options(args)                                # {{{1
  args_   = args.dup
  options = { cfgfile: "#{Dir.home}/.gitbak", verbose: false,
              noact: false }
  op = OptionParser.new do |opts|
    opts.banner = USAGE
    opts.on('-c', '--config-file FILE',
            'Configuration file') do |x|
      options[:cfgfile] = x
    end
    opts.on('-v', '--[no-]verbose', 'Run verbosely') do |x|
      options[:verbose] = x
    end
    opts.on('-n', '--no-act', 'List w/o mirroring') do |x|
      options[:noact] = !x
    end
    opts.on_tail('-h', '--help', 'Show this message') do
      puts INFO, '', opts; exit
    end
    opts.on_tail('--version', 'Show version') do
      puts "gitbak v#{GitBak::VERSION}"; exit
    end
  end
  begin
    op.parse! args_
  rescue OptionParser::ParseError => e
    GitBak::Misc.die! "#{e}\n\n#{op}"
  end
  GitBak::Misc.die! "usage: #{USAGE}" unless args_.length == 0
  options
end