Module: Wordsmith::CLI
- Defined in:
- lib/wordsmith/cli.rb
Instance Method Summary collapse
- #clean(info) ⇒ Object
- #error(e) ⇒ Object
- #help ⇒ Object
-
#l(info, size) ⇒ Object
DISPLAY HELPER FUNCTIONS #.
- #parse_options ⇒ Object
- #r(info, size) ⇒ Object
- #run ⇒ Object
Instance Method Details
#clean(info) ⇒ Object
74 75 76 |
# File 'lib/wordsmith/cli.rb', line 74 def clean(info) info.to_s.gsub("\n", ' ') end |
#error(e) ⇒ Object
25 26 27 |
# File 'lib/wordsmith/cli.rb', line 25 def error(e) puts 'Error: ' + e.to_s end |
#help ⇒ Object
29 30 31 |
# File 'lib/wordsmith/cli.rb', line 29 def help puts print_actions end |
#l(info, size) ⇒ Object
DISPLAY HELPER FUNCTIONS #
66 67 68 |
# File 'lib/wordsmith/cli.rb', line 66 def l(info, size) clean(info)[0, size].ljust(size) end |
#parse_options ⇒ Object
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 |
# File 'lib/wordsmith/cli.rb', line 33 def @options = {} do |opts| opts. = "Usage: #{$0} [options] [subcommand [options]]" opts.description = "wordsmith helps you write books collectively with Git" opts.separator "" opts.separator "Global options are:" opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| @options[:verbose] = v end end command :init, :new, :n do |opts| opts. = "Usage: wordsmith new (directory)" opts.description = "initialize a new book layout" end command :generate, :g do |opts| opts. = "Usage: wordsmith generate [options]" opts.description = "generate digital formats" end command :publish do |opts| opts. = "Usage: wordsmith publish" opts.description = "publish your book to github project page" end @subcommand = opt_parse @args = ARGV end |
#r(info, size) ⇒ Object
70 71 72 |
# File 'lib/wordsmith/cli.rb', line 70 def r(info, size) clean(info)[0, size].rjust(size) end |
#run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/wordsmith/cli.rb', line 12 def run if @subcommand && self.respond_to?(@subcommand) begin self.send @subcommand, @args rescue Object => e error e end else help end end |