#!/usr/bin/env ruby # ********** Copyright 2016 Viacom, Inc. Apache 2.0 ********** $:.unshift File.join(File.dirname(__FILE__), "..", "lib") #require "byebug" require "roku_builder" require "optparse" require "pathname" options = {} options[:config] = '~/.roku_config.json' options[:update_manifest] = false logger = Logger.new(STDOUT) logger.formatter = proc {|severity, datetime, _progname, msg| "[%s #%s] %5s: %s\n\r" % [datetime.strftime("%Y-%m-%d %H:%M:%S.%4N"), $$, severity, msg] } parser = OptionParser.new do |opts| opts.banner = "Usage: roku [options]" opts.on("-l", "--sideload", "Command: Sideload an app") do options[:sideload] = true end opts.on("-p", "--package", "Command: Package an app") do options[:package] = true end opts.on("-t", "--test", "Command: Test an app") do options[:test] = true end opts.on("-L", "--deeplink", "Depricated: Deeplink now just requires -o or --deeplink-options") do options[:deeplink_depricated] = true end opts.on("-o", "--deeplink-options OPTIONS", "Command: Deeplink into app. Define options as keypairs. (eg. a:b, c:d,e:f)") do |o| options[:deeplink] = o end opts.on("--configure", "Command: Copy base configuration file to the --config location. Default: '~/.roku_config.json'") do options[:configure] = true end opts.on("--validate", "Command: Validate configuration'") do options[:validate] = true end opts.on("-d", "--delete", "Command: Delete the currently sideloaded app") do options[:delete] = true end opts.on("-N", "--nav CMD", "Command: send the given command to the roku") do |n| options[:navigate] = n end opts.on("--navigate", "Command: Run interactive navigator") do options[:navigator] = true end opts.on("-S", "--screencapture", "Command: save a screencapture to the output file/folder") do options[:screencapture] = true end opts.on("-y", "--type TEXT", "Command: type the given text on the roku device") do |t| options[:text] = t end opts.on("-b", "--build", "Command: build a zip to be sideloaded") do options[:build] = true end opts.on("-k", "--key", "Command: change device key") do options[:key] = true end opts.on("--genkey", "Command: generate a new key") do options[:genkey] = true end opts.on("--print ATTRIBUTE", "Command: Print attribute for scripting") do |a| options[:print] = a end opts.on("--profile COMMAND", "Command: Run various profiler options") do |c| options[:profile] = c end opts.on("--do-stage", "Command: Run the stager. Used for scripting. Always run --do-unstage after") do options[:dostage] = true end opts.on("--do-unstage", "Command: Run the unstager. Used for scripting. Always run --do-script first") do options[:dounstage] = true end opts.on("--screen SCREEN", "Command: show a screen") do |s| options[:screen] = s end opts.on("--screens", "Command: show possible screens") do options[:screens] = true end opts.on("-m", "--monitor [TYPE]", "Command: run telnet to monitor roku log") do |m| options[:monitor] = m || "main" end opts.on("-u", "--update-manifest", "Command: update the manifest file") do options[:update] = true end opts.on("-A", "--app-list", "Command: List currently installed apps") do options[:applist] = true end opts.on("-r", "--ref REF", "Git referance to use for sideloading") do |r| options[:ref] = r end opts.on("-w", "--working", "Use working directory to sideload or test") do options[:working] = true end opts.on("-c", "--current", "Use current directory to sideload or test. Overrides any project config") do options[:current] = true end opts.on("-s", "--stage STAGE", "Set the stage to use. Default: 'production'") do |b| options[:stage] = b options[:set_stage] = true end opts.on("-M", "--manifest-update", "Update the manifest file while packaging") do options[:update_manifest] = true end opts.on("-i", "--inspect", "Print inspection information while packaging") do options[:inspect] = true end opts.on("-e", "--edit PARAMS", "Edit config params when configuring. (eg. a:b, c:d,e:f)") do |p| options[:edit_params] = p end opts.on("--config CONFIG", "Set a custom config file. Default: '~/.roku_config.json'") do |c| options[:config] = c end opts.on("-D", "--device ID", "Use a different device corresponding to the given ID") do |d| options[:device] = d options[:device_given] = true end opts.on("-P", "--project ID", "Use a different project") do |p| options[:project] = p end opts.on("-a", "--app ID", "Send App id for deeplinking") do |a| options[:app_id] = a end opts.on("-O", "--out PATH", "Output file/folder. If PATH ends in .pkg/.zip/.jpg, file is assumed, otherwise folder is assumed") do |o| options[:out] = o end opts.on("-I", "--in PATH", "Input file for sideloading") do |i| options[:in] = i end opts.on("-r", "--regexp REGEXP", "A regular expression used to filter monitor logs") do |r| options[:regexp] = r end opts.on("-x", "--exclude", "Apply exclude config to sideload") do options[:exclude] = true end opts.on("-V", "--verbose", "Print Info message") do options[:verbose] = true end opts.on("--debug", "Print Debug messages") do options[:debug] = true end opts.on("-h", "--help", "Show this message") do puts opts exit end opts.on("-v", "--version", "Show version") do puts RokuBuilder::VERSION exit end end begin parser.parse! RokuBuilder::Controller.run(options: options, logger: logger) rescue OptionParser::ParseError => e logger.fatal e.message end