Sha256: fa0e8f7277c4149d8dc0d03301c3e14f27064b25d1006f74b7b1c174f9b2de00
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 KB
Contents
module Space2underscore class Cli CREATE_FLAGS = %w[-c --create].freeze RAW_FLAGS = %w[-r --raw].freeze FLAGS = [CREATE_FLAGS, RAW_FLAGS].flatten.freeze OptionParseError = Class.new(ArgumentError) def initialize(argv) @argv = argv @underscore_include_branch = Underscore.new(branch).convert end def start $stdout.puts Usage.new.content && exit if @argv.empty? case when included?(CREATE_FLAGS) && included?(RAW_FLAGS) Executor.new(@underscore_include_branch).run_with_raw when included?(CREATE_FLAGS) && not_included?(RAW_FLAGS) Executor.new(@underscore_include_branch).run_with_downcase when not_included?(CREATE_FLAGS) && included?(RAW_FLAGS) Printer.instance.run_with_raw(@underscore_include_branch) when not_included?(CREATE_FLAGS) && not_included?(RAW_FLAGS) Printer.instance.run_with_downcase(@underscore_include_branch) else raise OptionParseError, 'Option is invalid format. It is only avaliable for `-c --create -d --downcase`' end end private def branch @argv.reject { |arg| FLAGS.include?(arg) } end def included?(flags) @argv.any? { |arg| flags.include?(arg) } end def not_included?(flags) !included?(flags) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
space2underscore-0.5.2 | lib/space2underscore/cli.rb |