Sha256: 264ff9897a8578f649b7f538ac5352c50df3900dda10e11b3e5c7a0fec1a9836

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

module TrelloCli
  module CLI
    class Run
      def run
        target = ARGV.shift
        cmd    = ARGV.shift || 'help'

        case target
        when *targets
          target_object = CLI::Commands.const_get(target.capitalize).new

          cmd = 'help' unless target_object.actions.include?(cmd.to_sym)

          begin
            target_object.send cmd
          rescue OptionParser::InvalidOption, Trello::Error => e
            puts e.message
            exit 1
          end
        when '-v'
          puts TrelloCli::VERSION
        else
          puts "Unkown target: '#{target}'." unless target == '-h'
          puts "trello [#{targets.join('|')}] [command] OPTIONS"
          puts "Append -h for help on specific target."
        end
      end

      private

      def targets
        klasses = TrelloCli::CLI.constants.reject do |c|
          ( c == :Run ) || ( c == :Commands )
        end
        klasses.map { |k| k.to_s.downcase }
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trello_cli-0.0.3 lib/trello_cli/cli/run.rb