Module: GitScribe::CLI

Included in:
GitScribe
Defined in:
lib/git-scribe/cli.rb

Instance Method Summary collapse

Instance Method Details

#clean(info) ⇒ Object



77
78
79
# File 'lib/git-scribe/cli.rb', line 77

def clean(info)
  info.to_s.gsub("\n", ' ')
end

#error(e) ⇒ Object



25
26
27
# File 'lib/git-scribe/cli.rb', line 25

def error(e)
  puts 'Error: ' + e.to_s
end

#helpObject



29
30
31
# File 'lib/git-scribe/cli.rb', line 29

def help
  puts print_actions
end

#l(info, size) ⇒ Object

DISPLAY HELPER FUNCTIONS #



69
70
71
# File 'lib/git-scribe/cli.rb', line 69

def l(info, size)
  clean(info)[0, size].ljust(size)
end

#parse_optionsObject



33
34
35
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
# File 'lib/git-scribe/cli.rb', line 33

def parse_options
  @options = {}
  global_options do |opts|
    opts.banner = "Usage: #{$0} [options] [subcommand [options]]"
    opts.description = "git-scribe helps you write books with the power of Git"
    opts.separator ""
    opts.separator "Global options are:"
    opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
      @options[:verbose] = v
    end
  end

  command :init do |opts|
    opts.banner = "Usage: git scribe init (directory)"
    opts.description = "initialize a new book layout"
    opts.on("-l", "--lang", "choose a default language (en)") do |v|
      @options[:lang] = lang || 'en'
    end
  end

  command :gen do |opts|
    opts.banner = "Usage: git scribe gen [options]"
    opts.description = "generate digital formats"
  end

  command :check do |opts|
    opts.banner = "Usage: git scribe check"
    opts.description = "checks for system requirements for doc generation"
  end

  @subcommand = opt_parse
  @args = ARGV
end

#r(info, size) ⇒ Object



73
74
75
# File 'lib/git-scribe/cli.rb', line 73

def r(info, size)
  clean(info)[0, size].rjust(size)
end

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/git-scribe/cli.rb', line 12

def run
  parse_options
  if @subcommand && self.respond_to?(@subcommand)
    begin
      self.send @subcommand, @args
    rescue Object => e
      error e
    end
  else
    help
  end
end