Class: Space2underscore::Cli

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

Constant Summary collapse

CREATE_FLAGS =
%w[-c --create].freeze
RAW_FLAGS =
%w[-r --raw].freeze
FLAGS =
[CREATE_FLAGS, RAW_FLAGS].flatten.freeze
ERROR_MSG =
'Option is invalid format. It is only avaliable for `-c --create -d --downcase`'
OptionParseError =
Class.new(ArgumentError)

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



14
15
16
17
18
19
# File 'lib/space2underscore/cli.rb', line 14

def initialize(argv)
  @argv = argv
  @underscore_include_branch = Underscore.new(branch).convert
  @executer = Executor.instance
  @printer  = Printer.instance
end

Instance Method Details

#startObject



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

def start
  return $stdout.puts Usage.new.content if @argv.empty?

  if with_all_flags?
    @executer.run_with_raw(@underscore_include_branch)
  elsif create_flags_without_raw_flags?
    @executer.run_with_downcase(@underscore_include_branch)
  elsif raw_flags_without_create_flags?
    @printer.run_with_raw(@underscore_include_branch)
  elsif without_any_flags?
    @printer.run_with_downcase(@underscore_include_branch)
  else
    raise OptionParseError, ERROR_MSG
  end
end