Sha256: e023e476dac1b295dc7f970e12463fbcabd6eda51612d81e4e234f22100d7b1a

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Buildkite
  module Builder
    module Commands
      using Rainbow
      COMMANDS = {
        'files' => :Files,
        'preview' => :Preview,
      }.freeze

      autoload :Abstract, File.expand_path('commands/abstract', __dir__)
      COMMANDS.each do |command, klass|
        autoload klass, File.expand_path("commands/#{command}", __dir__)
      end

      def self.run
        if ARGV.empty? || ARGV.first == '--help'
          return print_help
        end

        command = ARGV.shift
        unless (command_class = COMMANDS[command])
          raise "Invalid command: #{command}"
        end

        const_get(command_class).execute
      end

      def self.print_help
        puts <<~HELP
          #{'SYNOPSIS'.bright}
          \t#{'buildkite-builder'.bright} COMMAND [OPTIONS] [PIPELINE]
  
          \t#{'To see available options for specific commands:'.color(:dimgray)}
          \t#{'buildkite-builder'.bright} COMMAND --help
  
          #{'COMMANDS'.bright}
        HELP
        COMMANDS.each do |command, klass|
          puts <<~HELP
            \t#{command.bright}
            \t#{const_get(klass).description.color(:dimgray)}\n
          HELP
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
buildkite-builder-1.0.0.beta.2 lib/buildkite/builder/commands.rb
buildkite-builder-1.0.0.beta.1 lib/buildkite/builder/commands.rb