Sha256: 9007b47cabfc93338ebdc6ba7af88aa954b7eb97c221c96562583756b59f5123

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

# encoding: utf-8

module GithubCLI
  class Command < Thor
    include Thor::Actions

    API_CLASSES = %w(
      c_l_i
      repo download key fork hook watch collab
      issue label milestone
      tag tree blob reference commit
      pull
      email
      event
    )

    HELP_COMMAND = 'help'

    class Comm < Struct.new(:namespace, :name, :desc, :usage); end

    def self.output_formats
      {
        'csv' => nil,
        'json' => nil,
        'pretty' => nil,
        'table' => nil
      }
    end

    map "ls" => :list,
        "all" => :list,
        "del" => :delete

    class_option :format, :type => :string, :aliases => '-f',
                 :default => 'table',
                 :banner => output_formats.keys.join('|'),
                 :desc => "Format of the output"
    class_option :pager, :type => :boolean, :aliases => '-p',
                 :default => true,
                 :desc => "Determines if the output is paged."

    def self.banner(task, namespace=true, subcommand=true)
      "#{basename} #{task.formatted_usage(self, true, subcommand)}"
    end


    def self.all
      commands = []
      Base.subclasses.each do |klass|
        namespace = extract_namespace(klass)
        next unless is_api_command?(namespace)
        namespace = "" if namespace.index API_CLASSES.first

        klass.tasks.each do |task|
          next if task.last.name.index HELP_COMMAND
          commands << Comm.new(namespace,
                               task.last.name,
                               task.last.description,
                               task.last.usage)
        end
      end
      commands
    end

    def self.is_api_command?(klass)
      return false unless API_CLASSES.include?(klass.to_s)
      return true
    end

    def self.extract_namespace(klass)
      klass.namespace.split(':').last
    end

  end # Command
end # GithubCLI

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
github_cli-0.3.1 lib/github_cli/command.rb