Class: Shomen::CLI::Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/shomen/cli/abstract.rb

Overview

Command line interface base class.

Direct Known Subclasses

RDocCommand, TomDocCommand, YARDCommand

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(*arg) ⇒ Object



16
17
18
# File 'lib/shomen/cli/abstract.rb', line 16

def self.run(*arg)
  new.run(*argv)
end

Instance Method Details

#option_debug(parser, options) ⇒ Object



75
76
77
78
79
# File 'lib/shomen/cli/abstract.rb', line 75

def option_debug(parser, options)
  parser.on_tail('-D', '--debug', 'run with $DEBUG set to true') do
    $DEBUG = true
  end
end

#option_force(parser, options) ⇒ Object



68
69
70
71
72
# File 'lib/shomen/cli/abstract.rb', line 68

def option_force(parser, options)
  parser.on('-f', '--force') do
    options[:force] = true
  end
end

#option_format(parser, options) ⇒ Object



54
55
56
57
58
# File 'lib/shomen/cli/abstract.rb', line 54

def option_format(parser, options)
  parser.on('-f', '--format NAME') do |format|
    options[:format] = format
  end
end

#option_help(parser, options) ⇒ Object



89
90
91
92
93
94
# File 'lib/shomen/cli/abstract.rb', line 89

def option_help(parser, options)
  parser.on_tail('--help') do
    puts opt
    exit 0
  end
end

#option_source(parser, options) ⇒ Object



61
62
63
64
65
# File 'lib/shomen/cli/abstract.rb', line 61

def option_source(parser, options)
  parser.on('-s', '--[no-]source', 'include full source in script documentation') do |bool|
    Shomen.source = bool
  end
end

#option_warn(parser, options) ⇒ Object



82
83
84
85
86
# File 'lib/shomen/cli/abstract.rb', line 82

def option_warn(parser, options)
  parser.on_tail('-W', '--warn', 'run with $VERBOSE set to true') do
    $VERBOSE = true
  end
end

#parse(argv, *choices) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/shomen/cli/abstract.rb', line 21

def parse(argv, *choices)
  options = (Hash === choices.last ? choices.pop : {})
  parser  = OptionParser.new

  choices.each do |choice|
    send("option_#{choice}", parser, options)
  end
  option_debug(parser, options)
  option_warn(parser, options)
  option_help(parser, options)

  parser.parse!(argv)

  return options
end

#root?Boolean

Returns:

  • (Boolean)


97
98
99
100
101
102
103
104
# File 'lib/shomen/cli/abstract.rb', line 97

def root?
  root = false
  root = true if File.exist?('.ruby')
  root = true if File.exist?('.yardoc')
  root = true if File.exist?('.git')
  root = true if File.exist?('.hg')
  root
end