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
-
.configure(file) ⇒ Object
parse configuration file; die on failure.
-
.main(args = nil) ⇒ Object
run!.
-
.parse_options(args) ⇒ Object
parse command line options; die on failure.
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) = (args || ARGV) cfg = configure [:cfgfile] GitBak.main [:verbose], [: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.(args) # {{{1 args_ = args.dup = { cfgfile: "#{Dir.home}/.gitbak", verbose: false, noact: false } op = OptionParser.new do |opts| opts. = USAGE opts.on('-c', '--config-file FILE', 'Configuration file') do |x| [:cfgfile] = x end opts.on('-v', '--[no-]verbose', 'Run verbosely') do |x| [:verbose] = x end opts.on('-n', '--no-act', 'List w/o mirroring') do |x| [: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 end |