Sha256: 28138a2420f413301a3edc675bd37c42ce8b829709ef93fef967e167a5e7c468

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'thor'

module Caseconv
  class Cli < Thor

    CASE_METHOD_NAME_MAP = {
      'down' => :downcase,
      'up' => :upcase,
      'snake' => :underscore,
      'camel' => :camelize_dfl,
      'Camel' => :camelize,
      'kebab' => :kebab
    }

    desc '', 'convert text to specified cases, available cases: down, up, snake, camel(with first letter be lower case), Camel, kebab'
    option :case, type: :string, aliases: ['-c'], required: true, desc: 'Specify which case converts to, available values: down, up, snake, camel(with first letter be lower case), Camel, kebab'
    def convert(file_name=nil)
      unless case_type = CASE_METHOD_NAME_MAP[options[:case]]
        STDERR.puts "Not supported case: #{options[:case]}"
      end
      if file_name
        File.open(file_name, 'r') do |file|
          Caseconv::App.new.convert_file(file, case_type).each do |line|
            puts line
          end
        end
      else
        Caseconv::App.new.convert_file(STDIN, case_type).each do |line|
          puts line
        end
      end
    end

    default_command :convert
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
caseconv-0.1.0 lib/caseconv/cli.rb