Sha256: 1d89aaee6e2eee6cd4061fc304f740bcf14e2a06ec3a8ef6912ca5ffd8c69dfc

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8

module GithubCLI
  class Command < Thor

    API_CLASSES = %w( c_l_i repo issue label tree blob )

    HELP_COMMAND = 'help'

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

    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

3 entries across 3 versions & 1 rubygems

Version Path
github_cli-0.1.2 lib/github_cli/command.rb
github_cli-0.1.1 lib/github_cli/command.rb
github_cli-0.1.0 lib/github_cli/command.rb