Class: RubyNext::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-next/commands/base.rb

Direct Known Subclasses

CoreExt, Nextify

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_runObject (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_parserObject



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

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/ruby-next/commands/base.rb', line 21

def parse!(*)
  raise NotImplementedError
end

#runObject

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/ruby-next/commands/base.rb', line 25

def run
  raise NotImplementedError
end