Sha256: 38565719c59c181a7f2e804aaf24478ee0a25a9ae64cbd50338f68cf5c0d7728

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Roti
  class Cli
    HELP_OPTIONS = ['-h', '--help'].freeze
    VERSION_OPTIONS = ['-v', '--version'].freeze
    DECODE_OPTIONS = ['-d', '--decode'].freeze

    class << self
      def start
        case ARGV[0]
        when *HELP_OPTIONS
          help
        when *VERSION_OPTIONS
          version
        when *DECODE_OPTIONS
          decode(ARGV[1])
        else
          encode(ARGV[0])
        end
      end

      private

      def help
        puts 'Usage: roti [OPTION]...'
        puts 'Options:'
        puts "  #{DECODE_OPTIONS.join(', ')}"
        puts "  #{HELP_OPTIONS.join(', ')}"
        puts 'Examples:'
        puts '  roti hello'
        puts '  roti -d igopt'
      end

      def version
        puts "roti v#{Roti::VERSION}"
      end

      def encode(string)
        return help if string.nil?

        puts Roti.encode(string)
      end

      def decode(string)
        return help if string.nil?

        puts Roti.decode(string)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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