Class: Milc::Command
- Inherits:
-
Object
- Object
- Milc::Command
- Defined in:
- lib/milc/command.rb
Instance Attribute Summary collapse
-
#logic ⇒ Object
readonly
Returns the value of attribute logic.
Instance Method Summary collapse
-
#command_options ⇒ Object
overriden.
-
#initialize(logic) ⇒ Command
constructor
A new instance of Command.
- #load_options(options) ⇒ Object
- #run(args) ⇒ Object
- #setup(args) ⇒ Object
- #show_help_and_exit1 ⇒ Object
Constructor Details
#initialize(logic) ⇒ Command
Returns a new instance of Command.
10 11 12 |
# File 'lib/milc/command.rb', line 10 def initialize(logic) @logic = logic end |
Instance Attribute Details
#logic ⇒ Object (readonly)
Returns the value of attribute logic.
9 10 11 |
# File 'lib/milc/command.rb', line 9 def logic @logic end |
Instance Method Details
#command_options ⇒ Object
overriden
35 36 37 |
# File 'lib/milc/command.rb', line 35 def "nVc:" # n と V と c: は必須 end |
#load_options(options) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/milc/command.rb', line 45 def () if ["c"] yaml_path = ["c"] logic.config = YAML.load_file_with_erb(yaml_path) logic.load_config else show_help_and_exit1 end logic.() end |
#run(args) ⇒ Object
14 15 16 17 18 |
# File 'lib/milc/command.rb', line 14 def run(args) setup(args) logic.process # exit 0 end |
#setup(args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/milc/command.rb', line 20 def setup(args) # ARGV.getopts については以下を参照 # http://d.hatena.ne.jp/zariganitosh/20140819/ruby_optparser_true_power # http://docs.ruby-lang.org/ja/2.1.0/method/OptionParser=3a=3aArguable/i/getopts.html args.extend(OptionParser::Arguable) unless args.is_a?(OptionParser::Arguable) = args.getopts() show_help_and_exit1 unless args.empty? Milc.dry_run = !!["n"] Milc.verbose = !!["V"] () end |
#show_help_and_exit1 ⇒ Object
39 40 41 42 43 |
# File 'lib/milc/command.rb', line 39 def show_help_and_exit1 ## シェルスクリプトのUsage $stderr.puts logic. exit 1 end |