Sha256: e74c29c6cb3181f868eeccfe322e38d5361a85c3317d71375e249054debcd528

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

# ********** Copyright Viacom, Inc. Apache 2.0 **********

module RokuBuilder

  # Helper for extending for scripting
  class Scripter
    extend Plugin

    def self.commands
      {print: {source: true, stage: true}}
    end

    def self.parse_options(parser:, options:)
      parser.separator("Commands:")
      parser.on("--print ATTRIBUTE", "Print attribute for scripting") do |a|
        options[:print] = a.to_sym
      end
    end

    def initialize(config:)
      @config = config
    end

    def print(options:)
      attributes = [
        :title, :build_version, :app_version, :root_dir, :app_name
      ]

      unless attributes.include? options[:print]
        raise ExecutionError, "Unknown attribute: #{options[:print]}"
      end

      manifest = Manifest.new(config: @config)

      case options[:print]
      when :root_dir
        printf "%s", @config.project[:directory]
      when :app_name
        printf "%s", @config.project[:app_name]
      when :title
        printf "%s", manifest.title
      when :build_version
        printf "%s", manifest.build_version
      when :app_version
        major = manifest.major_version
        minor = manifest.minor_version
        printf "%s.%s", major, minor
      end
    end
  end

  RokuBuilder.register_plugin(Scripter)
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
roku_builder-4.2.1 lib/roku_builder/plugins/scripter.rb
roku_builder-4.2.0 lib/roku_builder/plugins/scripter.rb
roku_builder-4.1.0 lib/roku_builder/plugins/scripter.rb
roku_builder-4.0.1 lib/roku_builder/plugins/scripter.rb
roku_builder-4.0.0 lib/roku_builder/plugins/scripter.rb