Class: Glimmer::Launcher
- Inherits:
-
Object
- Object
- Glimmer::Launcher
- Defined in:
- lib/glimmer/launcher.rb
Overview
Launcher of glimmer applications and main entry point for the ‘glimmer` command.
Constant Summary collapse
- TEXT_USAGE =
TODO update the verbiage below for Glimmer DSL for LibUI
<<~MULTI_LINE_STRING Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development Cross-Platform Native GUI Library) - Ruby Gem: glimmer-dsl-libui v#{File.read(File.('../../../VERSION', __FILE__))} Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-ruby-option]...] (application.rb or task[task_args]) Runs Glimmer applications and tasks. When applications are specified, they are run using Ruby, automatically preloading the glimmer-dsl-libui Ruby gem. Optionally, extra Glimmer options, Ruby options, and/or environment variables may be passed in. Glimmer options: - "--bundler=GROUP" : Activates gems in Bundler default group in Gemfile - "--pd=BOOLEAN" : Requires puts_debuggerer to enable pd method - "--quiet=BOOLEAN" : Does not announce file path of Glimmer application being launched - "--debug" : Displays extra debugging information and enables debug logging - "--log-level=VALUE" : Sets Glimmer's Ruby logger level ("ERROR" / "WARN" / "INFO" / "DEBUG"; default is none) Tasks are run via rake. Some tasks take arguments in square brackets (surround with double-quotes if using Zsh). Available tasks are below (if you do not see any, please add `require 'glimmer/rake_task'` to Rakefile and rerun or run rake -T): MULTI_LINE_STRING
- GLIMMER_LIB_GEM =
'glimmer-dsl-libui'
- GLIMMER_LIB_LOCAL =
File.(File.join('lib', "#{GLIMMER_LIB_GEM}.rb"))
- GLIMMER_OPTIONS =
%w[--log-level --quiet --bundler --pd]
- GLIMMER_OPTION_ENV_VAR_MAPPING =
{ '--log-level' => 'GLIMMER_LOGGER_LEVEL' , '--bundler' => 'GLIMMER_BUNDLER_SETUP' , '--pd' => 'PD' , }
- REGEX_RAKE_TASK_WITH_ARGS =
/^([^\[]+)\[?([^\]]*)\]?$/
Instance Attribute Summary collapse
-
#application_paths ⇒ Object
readonly
Returns the value of attribute application_paths.
-
#env_vars ⇒ Object
readonly
Returns the value of attribute env_vars.
-
#glimmer_options ⇒ Object
readonly
Returns the value of attribute glimmer_options.
-
#ruby_options ⇒ Object
readonly
Returns the value of attribute ruby_options.
Class Method Summary collapse
- .dev_mode? ⇒ Boolean
- .glimmer_lib ⇒ Object
- .glimmer_option_env_vars(glimmer_options) ⇒ Object
- .is_arm64? ⇒ Boolean
- .launch(application, ruby_options: [], env_vars: {}, glimmer_options: {}) ⇒ Object
- .load_env_vars(env_vars) ⇒ Object
Instance Method Summary collapse
-
#initialize(raw_options) ⇒ Launcher
constructor
A new instance of Launcher.
- #launch ⇒ Object
Constructor Details
#initialize(raw_options) ⇒ Launcher
Returns a new instance of Launcher.
134 135 136 137 138 139 140 141 |
# File 'lib/glimmer/launcher.rb', line 134 def initialize() << '--quiet' if !caller.join("\n").include?('/bin/glimmer:') && !.join.include?('--quiet=') << '--log-level=DEBUG' if .join.include?('--debug') && !.join.include?('--log-level=') @application_path = extract_application_path() @env_vars = extract_env_vars() @glimmer_options = () @ruby_options = end |
Instance Attribute Details
#application_paths ⇒ Object (readonly)
Returns the value of attribute application_paths.
129 130 131 |
# File 'lib/glimmer/launcher.rb', line 129 def application_paths @application_paths end |
#env_vars ⇒ Object (readonly)
Returns the value of attribute env_vars.
130 131 132 |
# File 'lib/glimmer/launcher.rb', line 130 def env_vars @env_vars end |
#glimmer_options ⇒ Object (readonly)
Returns the value of attribute glimmer_options.
131 132 133 |
# File 'lib/glimmer/launcher.rb', line 131 def @glimmer_options end |
#ruby_options ⇒ Object (readonly)
Returns the value of attribute ruby_options.
132 133 134 |
# File 'lib/glimmer/launcher.rb', line 132 def @ruby_options end |
Class Method Details
.dev_mode? ⇒ Boolean
84 85 86 |
# File 'lib/glimmer/launcher.rb', line 84 def dev_mode? glimmer_lib == GLIMMER_LIB_LOCAL end |
.glimmer_lib ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/glimmer/launcher.rb', line 73 def glimmer_lib unless @glimmer_lib @glimmer_lib = GLIMMER_LIB_GEM if File.exist?(GLIMMER_LIB_LOCAL) @glimmer_lib = GLIMMER_LIB_LOCAL puts "[DEVELOPMENT MODE] (detected #{@glimmer_lib})" end end @glimmer_lib end |
.glimmer_option_env_vars(glimmer_options) ⇒ Object
88 89 90 91 92 |
# File 'lib/glimmer/launcher.rb', line 88 def glimmer_option_env_vars() GLIMMER_OPTION_ENV_VAR_MAPPING.reduce({}) do |hash, pair| [pair.first] ? hash.merge(GLIMMER_OPTION_ENV_VAR_MAPPING[pair.first] => [pair.first]) : hash end end |
.is_arm64? ⇒ Boolean
68 69 70 71 |
# File 'lib/glimmer/launcher.rb', line 68 def is_arm64? host_cpu = OS.host_cpu.downcase host_cpu.include?('aarch64') || host_cpu.include?('arm') end |
.launch(application, ruby_options: [], env_vars: {}, glimmer_options: {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/glimmer/launcher.rb', line 100 def launch(application, ruby_options: [], env_vars: {}, glimmer_options: {}) = .join(' ') + ' ' if .any? env_vars = env_vars.merge(glimmer_option_env_vars()) load_env_vars(env_vars) the_glimmer_lib = glimmer_lib require 'puts_debuggerer' if (ENV['PD'] || ENV['pd']).to_s.downcase == 'true' || the_glimmer_lib == GLIMMER_LIB_LOCAL is_rake_task = !application.end_with?('.rb') rake_tasks = [] if is_rake_task load File.('./Rakefile') if File.exist?(File.('./Rakefile')) && caller.join("\n").include?('/bin/glimmer:') require_relative 'rake_task' rake_tasks = Rake.application.tasks.map(&:to_s).map {|t| t.sub('glimmer:', '')} potential_rake_task_parts = application.match(REGEX_RAKE_TASK_WITH_ARGS) application = potential_rake_task_parts[1] rake_task_args = potential_rake_task_parts[2].split(',') end if rake_tasks.include?(application) rake_task = "glimmer:#{application}" puts "Running Glimmer rake task: #{rake_task}" if .to_s.include?('--debug') Rake::Task[rake_task].invoke(*rake_task_args) else puts "Launching Glimmer Application: #{application}" if .to_s.include?('--debug') || ['--quiet'].to_s.downcase != 'true' require the_glimmer_lib load File.(application) end end |
.load_env_vars(env_vars) ⇒ Object
94 95 96 97 98 |
# File 'lib/glimmer/launcher.rb', line 94 def load_env_vars(env_vars) env_vars.each do |key, value| ENV[key] = value end end |
Instance Method Details
#launch ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/glimmer/launcher.rb', line 143 def launch if @application_path.nil? display_usage else launch_application end end |