Class: Ocran::Option
- Inherits:
-
Object
- Object
- Ocran::Option
- Defined in:
- lib/ocran/option.rb
Instance Method Summary collapse
- #add_all_core? ⇒ Boolean
- #add_all_encoding? ⇒ Boolean
- #argv ⇒ Object
- #auto_detect_dlls? ⇒ Boolean
- #bundle_identifier ⇒ Object
- #chdir_before? ⇒ Boolean
- #enable_compression? ⇒ Boolean
- #enable_debug_extract? ⇒ Boolean
- #enable_debug_mode? ⇒ Boolean
- #extra_dlls ⇒ Object
- #force_autoload? ⇒ Boolean
- #force_console? ⇒ Boolean
- #force_windows? ⇒ Boolean
- #gem_options ⇒ Object
- #gemfile ⇒ Object
- #icon_filename ⇒ Object
-
#initialize ⇒ Option
constructor
A new instance of Option.
- #inno_setup_script ⇒ Object
- #load_autoload? ⇒ Boolean
- #macosx_bundle ⇒ Object
- #output_dir ⇒ Object
- #output_executable ⇒ Object
- #output_override ⇒ Object
- #output_zip ⇒ Object
- #parse(argv) ⇒ Object
- #quiet? ⇒ Boolean
- #rubyopt ⇒ Object
- #run_script? ⇒ Boolean
- #script ⇒ Object
- #source_files ⇒ Object
- #usage ⇒ Object
- #use_inno_setup? ⇒ Boolean
- #verbose? ⇒ Boolean
- #warning? ⇒ Boolean
- #windowed? ⇒ Boolean
Constructor Details
#initialize ⇒ Option
Returns a new instance of Option.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ocran/option.rb', line 9 def initialize = { :add_all_core? => false, :add_all_encoding? => true, :argv => [], :auto_detect_dlls? => true, :bundle_identifier => nil, :macosx_bundle => nil, :macosx_bundle? => false, :chdir_before? => false, :enable_compression? => true, :enable_debug_extract? => false, :enable_debug_mode? => false, :extra_dlls => [], :force_console? => false, :force_windows? => false, :gem_options => [], :gemfile => nil, :icon_filename => nil, :inno_setup_script => nil, :load_autoload? => true, :output_dir => nil, :output_override => nil, :output_zip => nil, :quiet? => false, :rubyopt => nil, :run_script? => true, :script => nil, :source_files => [], :verbose? => false, :warning? => true, } end |
Instance Method Details
#add_all_core? ⇒ Boolean
256 |
# File 'lib/ocran/option.rb', line 256 def add_all_core? = [__method__] |
#add_all_encoding? ⇒ Boolean
258 |
# File 'lib/ocran/option.rb', line 258 def add_all_encoding? = [__method__] |
#argv ⇒ Object
260 |
# File 'lib/ocran/option.rb', line 260 def argv = [__method__] |
#auto_detect_dlls? ⇒ Boolean
266 |
# File 'lib/ocran/option.rb', line 266 def auto_detect_dlls? = [__method__] |
#bundle_identifier ⇒ Object
262 |
# File 'lib/ocran/option.rb', line 262 def bundle_identifier = [__method__] |
#chdir_before? ⇒ Boolean
268 |
# File 'lib/ocran/option.rb', line 268 def chdir_before? = [__method__] |
#enable_compression? ⇒ Boolean
270 |
# File 'lib/ocran/option.rb', line 270 def enable_compression? = [__method__] |
#enable_debug_extract? ⇒ Boolean
272 |
# File 'lib/ocran/option.rb', line 272 def enable_debug_extract? = [__method__] |
#enable_debug_mode? ⇒ Boolean
274 |
# File 'lib/ocran/option.rb', line 274 def enable_debug_mode? = [__method__] |
#extra_dlls ⇒ Object
276 |
# File 'lib/ocran/option.rb', line 276 def extra_dlls = [__method__] |
#force_autoload? ⇒ Boolean
278 |
# File 'lib/ocran/option.rb', line 278 def force_autoload? = [__method__] |
#force_console? ⇒ Boolean
280 |
# File 'lib/ocran/option.rb', line 280 def force_console? = [__method__] |
#force_windows? ⇒ Boolean
282 |
# File 'lib/ocran/option.rb', line 282 def force_windows? = [__method__] |
#gem_options ⇒ Object
284 |
# File 'lib/ocran/option.rb', line 284 def = [__method__] |
#gemfile ⇒ Object
286 |
# File 'lib/ocran/option.rb', line 286 def gemfile = [__method__] |
#icon_filename ⇒ Object
288 |
# File 'lib/ocran/option.rb', line 288 def icon_filename = [__method__] |
#inno_setup_script ⇒ Object
290 |
# File 'lib/ocran/option.rb', line 290 def inno_setup_script = [__method__] |
#load_autoload? ⇒ Boolean
292 |
# File 'lib/ocran/option.rb', line 292 def load_autoload? = [__method__] |
#macosx_bundle ⇒ Object
264 |
# File 'lib/ocran/option.rb', line 264 def macosx_bundle = [__method__] |
#output_dir ⇒ Object
294 |
# File 'lib/ocran/option.rb', line 294 def output_dir = [__method__] |
#output_executable ⇒ Object
296 |
# File 'lib/ocran/option.rb', line 296 def output_executable = [__method__] |
#output_override ⇒ Object
298 |
# File 'lib/ocran/option.rb', line 298 def output_override = [__method__] |
#output_zip ⇒ Object
300 |
# File 'lib/ocran/option.rb', line 300 def output_zip = [__method__] |
#parse(argv) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/ocran/option.rb', line 110 def parse(argv) while (arg = argv.shift) case arg when /\A--(no-)?lzma\z/ [:enable_compression?] = !$1 when "--no-dep-run" [:run_script?] = false when "--add-all-core" [:add_all_core?] = true when "--output" path = argv.shift [:output_override] = Pathname.new(path). if path when "--output-dir" path = argv.shift [:output_dir] = Pathname.new(path). if path when "--output-zip" path = argv.shift [:output_zip] = Pathname.new(path). if path when "--macosx-bundle" [:macosx_bundle?] = true when "--bundle-id" [:bundle_identifier] = argv.shift when "--dll" path = argv.shift [:extra_dlls] << path if path when "--quiet" [:quiet?] = true when "--verbose" [:verbose?] = true when "--windows" [:force_windows?] = true when "--console" [:force_console?] = true when "--no-autoload" [:load_autoload?] = false when "--chdir-first" [:chdir_before?] = true when "--icon" path = argv.shift raise "Icon file #{path} not found" unless path && File.exist?(path) [:icon_filename] = Pathname.new(path). when "--rubyopt" [:rubyopt] = argv.shift when "--gemfile" path = argv.shift raise "Gemfile #{path} not found" unless path && File.exist?(path) [:gemfile] = Pathname.new(path). when "--innosetup" path = argv.shift raise "Inno Script #{path} not found" unless path && File.exist?(path) [:inno_setup_script] = Pathname.new(path). when "--no-autodll" [:auto_detect_dlls?] = false when "--version" require_relative "version" puts "Ocran #{VERSION}" raise SystemExit when "--no-warnings" [:warning?] = false when "--debug" [:enable_debug_mode?] = true when "--debug-extract" [:enable_debug_extract?] = true when "--" [:argv] = argv.dup argv.clear break when /\A--(no-)?enc\z/ [:add_all_encoding?] = !$1 when /\A--(no-)?gem-(\w+)(?:=(.*))?$/ negate, group, list = $1, $2, $3 [:gem_options] << [negate, group.to_sym, list&.split(",")] if group when "--help", "-h", /\A--./ puts usage raise SystemExit else = Dir.glob(arg) if .empty? raise "#{arg} not found!" unless File.exist?(arg) = [arg] end .each do |f| if File.directory?(f) raise "#{f} is empty!" if Dir.empty?(f) # If a directory is passed, we want all files under that directory [:source_files] += Pathname.new(f).find.reject(&:directory?).map(&:expand_path) else [:source_files] << Pathname.new(f). end end end end raise "No script file specified" if source_files.empty? [:script] = source_files.first [:force_autoload?] = run_script? && load_autoload? [:output_executable] = if output_override output_override else executable = script # If debug mode is enabled, append "-debug" to the filename executable = executable.append_to_filename("-debug") if enable_debug_mode? # Build output files are created in the current directory ext = Gem.win_platform? ? ".exe" : "" executable.basename.sub_ext(ext). end if [:macosx_bundle?] bundle_base = output_override || script.basename [:macosx_bundle] = Pathname(bundle_base).sub_ext(".app"). end [:use_inno_setup?] = !!inno_setup_script [:verbose?] &&= !quiet? [:windowed?] = (script.extname?(".rbw") || force_windows?) && !force_console? if inno_setup_script if enable_debug_extract? raise "The --debug-extract option conflicts with use of Inno Setup" end if enable_compression? raise "LZMA compression must be disabled (--no-lzma) when using Inno Setup" end unless chdir_before? raise "Chdir-first mode must be enabled (--chdir-first) when using Inno Setup" end end if output_dir && output_zip raise "--output-dir and --output-zip cannot be used together" end if macosx_bundle && (output_dir || output_zip || inno_setup_script) raise "--macosx-bundle cannot be combined with --output-dir, --output-zip, or --innosetup" end end |
#quiet? ⇒ Boolean
302 |
# File 'lib/ocran/option.rb', line 302 def quiet? = [__method__] |
#rubyopt ⇒ Object
304 |
# File 'lib/ocran/option.rb', line 304 def rubyopt = [__method__] |
#run_script? ⇒ Boolean
306 |
# File 'lib/ocran/option.rb', line 306 def run_script? = [__method__] |
#script ⇒ Object
308 |
# File 'lib/ocran/option.rb', line 308 def script = [__method__] |
#source_files ⇒ Object
310 |
# File 'lib/ocran/option.rb', line 310 def source_files = [__method__] |
#usage ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ocran/option.rb', line 43 def usage "ocran [options] script.rb\n\nOcran options:\n\n--help, -h Display this information.\n--quiet Suppress output while building executable.\n--verbose Show extra output while building executable.\n--version Display version number and exit.\n\nPackaging options:\n\n--dll dllname Include additional DLLs from the Ruby bindir.\n--add-all-core Add all core ruby libraries to the executable.\n--gemfile <file> Add all gems and dependencies listed in a Bundler Gemfile.\n--no-enc Exclude encoding support files\n\nGem content detection modes:\n\n--gem-minimal[=gem1,..] Include only loaded scripts\n--gem-guess=[gem1,...] Include loaded scripts & best guess (DEFAULT)\n--gem-all[=gem1,..] Include all scripts & files\n--gem-full[=gem1,..] Include EVERYTHING\n--gem-spec[=gem1,..] Include files in gemspec (Does not work with Rubygems 1.7+)\n\n minimal: loaded scripts\n guess: loaded scripts and other files\n all: loaded scripts, other scripts, other files (except extras)\n full: Everything found in the gem directory\n\n--[no-]gem-scripts[=..] Other script files than those loaded\n--[no-]gem-files[=..] Other files (e.g. data files)\n--[no-]gem-extras[=..] Extra files (README, etc.)\n\n scripts: .rb/.rbw files\n extras: C/C++ sources, object files, test, spec, README\n files: all other files\n\nAuto-detection options:\n\n--no-dep-run Don't run script.rb to check for dependencies.\n--no-autoload Don't load/include script.rb's autoloads.\n--no-autodll Disable detection of runtime DLL dependencies.\n\nOutput options:\n\n--output <file> Name the exe to generate. Defaults to ./<scriptname>.exe.\n--output-dir <dir> Output all files to a directory with a launch script instead of an exe.\n--output-zip <file> Output a zip archive containing all files and a launch script.\n--macosx-bundle Build a macOS .app bundle. Use --output to name it (default: <scriptname>.app).\n--bundle-id <id> Bundle identifier for the macOS app bundle (default: com.example.<appname>).\n--no-lzma Disable LZMA compression of the executable.\n--innosetup <file> Use given Inno Setup script (.iss) to create an installer.\n\nExecutable options:\n\n--windows Force Windows application (rubyw.exe)\n--console Force console application (ruby.exe)\n--chdir-first When exe starts, change working directory to app dir.\n--icon <ico> Replace icon with a custom one.\n--rubyopt <str> Set the RUBYOPT environment variable when running the executable\n--debug Executable will be verbose.\n--debug-extract Executable will unpack to local dir and not delete after.\n" end |
#use_inno_setup? ⇒ Boolean
312 |
# File 'lib/ocran/option.rb', line 312 def use_inno_setup? = [__method__] |
#verbose? ⇒ Boolean
314 |
# File 'lib/ocran/option.rb', line 314 def verbose? = [__method__] |
#warning? ⇒ Boolean
316 |
# File 'lib/ocran/option.rb', line 316 def warning? = [__method__] |
#windowed? ⇒ Boolean
318 319 320 321 |
# File 'lib/ocran/option.rb', line 318 def windowed? return false unless Gem.win_platform? [:windowed?] end |