Sha256: 443688d420da7ca8352981b34fd836398c0252ce7592c51f2373c99572cbbf0e

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

module Owners
  class CLI < Thor
    include Timeout

    class_option :debug,
      aliases: %w(-d),
      desc: "Output additional subscription debugging info",
      type: :boolean

    class_option :file,
      aliases: %w(-f),
      desc: "The name of the OWNERS file",
      type: :string

    desc "for [FILES...]", "List owners for a set of files"
    def for(*files)
      files = stdin_files unless files.any?

      Owners.file = options[:file] if options[:file]
      Owners.for(*files).each do |owner|
        output(owner)
      end
    end

    desc "for_diff REF [BASE_REF]", "List owners for a set of git changes"
    def for_diff(ref, base_ref = "master")
      Owners.file = options[:file] if options[:file]
      Owners.for_diff(ref, base_ref).each do |owner|
        output(owner)
      end
    end

    desc "missing_for [FILES...]", "List files that don't have owners"
    def missing_for(*files)
      files = stdin_files unless files.any?

      Owners.file = options[:file] if options[:file]
      Owners.missing_for(*files).each do |owner|
        output(owner)
      end
    end

    no_commands do
      def output(owner)
        say owner

        if options[:debug]
          say owner.type, :yellow

          owner.subscriptions.each do |path, subscriptions|
            subscriptions.each do |sub|
              say "  #{path}", :red
              say "  #{sub.file}:#{sub.line} => #{sub.filter}", :blue
            end

            say
          end
        end
      end

      def stdin_files
        timeout(1) { $stdin.read.split("\n") }
      rescue Timeout::Error
        []
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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