Class: RubyNext::Commands::Base
- Inherits:
-
Object
- Object
- RubyNext::Commands::Base
- Defined in:
- lib/ruby-next/commands/base.rb
Instance Attribute Summary collapse
-
#dry_run ⇒ Object
(also: #dry_run?)
readonly
Returns the value of attribute dry_run.
Class Method Summary collapse
Instance Method Summary collapse
- #base_parser ⇒ Object
-
#initialize(args) ⇒ Base
constructor
A new instance of Base.
- #log(msg) ⇒ Object
- #parse! ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ Base
Returns a new instance of Base.
17 18 19 |
# File 'lib/ruby-next/commands/base.rb', line 17 def initialize(args) parse! args end |
Instance Attribute Details
#dry_run ⇒ Object (readonly) Also known as: dry_run?
Returns the value of attribute dry_run.
14 15 16 |
# File 'lib/ruby-next/commands/base.rb', line 14 def dry_run @dry_run end |
Class Method Details
.run(args) ⇒ Object
9 10 11 |
# File 'lib/ruby-next/commands/base.rb', line 9 def run(args) new(args).run end |
Instance Method Details
#base_parser ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby-next/commands/base.rb', line 39 def base_parser OptionParser.new do |opts| yield opts opts.on("-V", "Turn on verbose mode") do CLI.verbose = true end opts.on("--dry-run", "Print verbose output without generating files") do CLI.dry_run = true CLI.verbose = true end end end |
#log(msg) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby-next/commands/base.rb', line 29 def log(msg) return unless CLI.verbose? if CLI.dry_run? $stdout.puts "[DRY RUN] #{msg}" else $stdout.puts msg end end |
#parse! ⇒ Object
21 22 23 |
# File 'lib/ruby-next/commands/base.rb', line 21 def parse!(*) raise NotImplementedError end |
#run ⇒ Object
25 26 27 |
# File 'lib/ruby-next/commands/base.rb', line 25 def run raise NotImplementedError end |