launchy 2.5.2 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +22 -0
  3. data/Manifest.txt +4 -21
  4. data/README.md +0 -36
  5. data/exe/launchy +5 -0
  6. data/launchy.gemspec +33 -0
  7. data/lib/launchy/application.rb +38 -20
  8. data/lib/launchy/applications/browser.rb +70 -63
  9. data/lib/launchy/argv.rb +11 -6
  10. data/lib/launchy/cli.rb +29 -34
  11. data/lib/launchy/descendant_tracker.rb +14 -12
  12. data/lib/launchy/detect/host_os.rb +21 -18
  13. data/lib/launchy/detect/host_os_family.rb +94 -53
  14. data/lib/launchy/detect/nix_desktop_environment.rb +74 -69
  15. data/lib/launchy/detect.rb +7 -5
  16. data/lib/launchy/error.rb +2 -0
  17. data/lib/launchy/os_family.rb +2 -0
  18. data/lib/launchy/runner.rb +55 -0
  19. data/lib/launchy/version.rb +7 -5
  20. data/lib/launchy.rb +76 -68
  21. metadata +19 -79
  22. data/Rakefile +0 -27
  23. data/bin/launchy +0 -4
  24. data/lib/launchy/deprecated.rb +0 -52
  25. data/lib/launchy/detect/ruby_engine.rb +0 -78
  26. data/lib/launchy/detect/runner.rb +0 -152
  27. data/spec/application_spec.rb +0 -43
  28. data/spec/applications/browser_spec.rb +0 -73
  29. data/spec/cli_spec.rb +0 -75
  30. data/spec/detect/host_os_family_spec.rb +0 -42
  31. data/spec/detect/host_os_spec.rb +0 -19
  32. data/spec/detect/nix_desktop_environment_spec.rb +0 -27
  33. data/spec/detect/ruby_engine_spec.rb +0 -37
  34. data/spec/detect/runner_spec.rb +0 -103
  35. data/spec/launchy_spec.rb +0 -119
  36. data/spec/mock_application.rb +0 -9
  37. data/spec/spec_helper.rb +0 -11
  38. data/spec/tattle-host-os.yaml +0 -427
  39. data/spec/version_spec.rb +0 -11
  40. data/tasks/default.rake +0 -242
  41. data/tasks/this.rb +0 -208
  42. /data/{LICENSE → LICENSE.txt} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04d9c66ec0c8dcc2892bc46267fe37f7f1c82d14dad78d62c8adbd869a0d8a0f
4
- data.tar.gz: ecf5f8096d6f3ef2a4d9118b18086eba83ed62f50362c1964938faba8d53d624
3
+ metadata.gz: 147fa0dafa116ae097364aab290ffdb2f508ff44b87019dc266aeaccf1963ab7
4
+ data.tar.gz: aad595ea32b9a1b1027c0650fd23b1a19865dda3f60c76890e6b0bb1be9e6c0d
5
5
  SHA512:
6
- metadata.gz: 4abd13c2b9c600a9e2a50d07a2a8bfbe6ae21de1972063520669f558b5b7f3eca6dc5e4a2de63d1a19c6dcdeb43a53bddc22da210556a2a6c64ba263afed92ec
7
- data.tar.gz: 53feae60f4355edcddaa16497c5606f35eaccabd81d21f35d91ac3188314affd43f722970fe4c31249a89fbfadf7afc74579ee7d97f4740f1d339b0007a577e5
6
+ metadata.gz: b8193061c42405778b539067521999e9ff2776c0317ba8fae47ce300d901e55473abccad60486b93952e101a32c15a8d462205880c1ceaf7a1a6fe04833b6404
7
+ data.tar.gz: 57b74c3a254e4437b04b4baa367abb384e733bef508f8f746a22c13997ce13b063208fe6c5c9b16bb8e6963aad2d59367d1aea1188e3326c7aaac69f1e53cae9
data/HISTORY.md CHANGED
@@ -1,4 +1,26 @@
1
1
  # Launchy Changelog
2
+ ## Version 3.1.1 - 2025-02-21
3
+ * Fix the quoted parameter for windows launching - <https://github.com/copiousfreetime/launchy/issues/164>
4
+
5
+ ## Version 3.1.0 - 2025-01-23
6
+ * Fix the argv array when passing to ChildProcess on windows - <https://github.com/copiousfreetime/launchy/issues/159>
7
+ * Update the ruby test matrix for 3.4
8
+ * Update the ruby test matrix to drop 3.0
9
+
10
+ ## Version 3.0.1 - 2024-05-03
11
+ * Added rubocop and fix all the warnings
12
+ * Fix rubygem changelog_uri - Spone
13
+ * Update the semaphore flow
14
+ * Update the ruby test matrix
15
+ * Change to Gemfile for development
16
+
17
+ ## Version 3.0.0 - 2024-03-03
18
+ * Remove unused `deprecated.rb` file - <https://github.com/copiousfreetime/launchy/issues/148>
19
+ * Update supported ruby version to be 3.x
20
+ * use the `:application` parameter - <https://github.com/copiousfreetime/launchy/issues/121>
21
+ * adjust the semaphore configuration to allow better caching
22
+ * replace the homegrown process runner with [`childprocess`](https://rubygems.org/gems/childprocess)
23
+
2
24
  ## Version 2.5.2 - 2022-12-27
3
25
  * Update Addressable - <https://github.com/copiousfreetime/launchy/pull/145> - JamieKDonnelly
4
26
  * Fix deprecated usage of `Object#=~` - <https://github.com/copiousfreetime/launchy/pull/138> - marcrohloff
data/Manifest.txt CHANGED
@@ -1,38 +1,21 @@
1
1
  CONTRIBUTING.md
2
2
  HISTORY.md
3
- LICENSE
3
+ LICENSE.txt
4
4
  Manifest.txt
5
5
  README.md
6
- Rakefile
7
- bin/launchy
6
+ exe/launchy
7
+ launchy.gemspec
8
8
  lib/launchy.rb
9
9
  lib/launchy/application.rb
10
10
  lib/launchy/applications/browser.rb
11
11
  lib/launchy/argv.rb
12
12
  lib/launchy/cli.rb
13
- lib/launchy/deprecated.rb
14
13
  lib/launchy/descendant_tracker.rb
15
14
  lib/launchy/detect.rb
16
15
  lib/launchy/detect/host_os.rb
17
16
  lib/launchy/detect/host_os_family.rb
18
17
  lib/launchy/detect/nix_desktop_environment.rb
19
- lib/launchy/detect/ruby_engine.rb
20
- lib/launchy/detect/runner.rb
21
18
  lib/launchy/error.rb
22
19
  lib/launchy/os_family.rb
20
+ lib/launchy/runner.rb
23
21
  lib/launchy/version.rb
24
- spec/application_spec.rb
25
- spec/applications/browser_spec.rb
26
- spec/cli_spec.rb
27
- spec/detect/host_os_family_spec.rb
28
- spec/detect/host_os_spec.rb
29
- spec/detect/nix_desktop_environment_spec.rb
30
- spec/detect/ruby_engine_spec.rb
31
- spec/detect/runner_spec.rb
32
- spec/launchy_spec.rb
33
- spec/mock_application.rb
34
- spec/spec_helper.rb
35
- spec/tattle-host-os.yaml
36
- spec/version_spec.rb
37
- tasks/default.rake
38
- tasks/this.rb
data/README.md CHANGED
@@ -92,7 +92,6 @@ At the moment, the only available options are:
92
92
  :debug Turn on debugging output
93
93
  :application Explicitly state what application class is going to be used
94
94
  :host_os Explicitly state what host operating system to pretend to be
95
- :ruby_engine Explicitly state what ruby engine to pretend to be under
96
95
  :dry_run Do nothing and print the command that would be executed on $stdout
97
96
 
98
97
  If `Launchy.open` is invoked with a block, then no exception will be thrown, and
@@ -110,41 +109,6 @@ exception that was raised.
110
109
  puts "Attempted to open #{uri} and failed because #{exception}"
111
110
  end
112
111
 
113
- ## UPGRADING from versions before 2.0.0
114
-
115
- The previously published version of Launchy before the 2.0.0 series was 0.4.0.
116
- There have been so many changes, and a mistaken tag at 1.0.0, that I have
117
- decided to bump all the way to 2.x.y.
118
-
119
- I have attempted to keep backward compatibility with the previous examples. The
120
- previous API examples of:
121
-
122
- Launchy::Browser.run("https://www.ruby-lang.org/")
123
-
124
- and
125
-
126
- Launchy::Browser.new.visit("https://www.ruby-lang.org/")
127
-
128
- will still work, and you will get a deprecation notice, along with the line
129
- of code you should probably update. For example, this is what would print out
130
- in the github gem if it was updated to use 2.0.x but not use the supported API.
131
-
132
- % gh home
133
- WARNING: You made a call to a deprecated Launchy API. This call should be changed to 'Launchy.open( uri )'
134
- WARNING: I think I was able to find the location that needs to be fixed. Please go look at:
135
- WARNING:
136
- WARNING: /Users/jeremy/.rvm/gems/ruby-1.8.7-p334/gems/github-0.6.2/lib/commands/helpers.rb:275:in `open'
137
- WARNING: helper :open do |url|
138
- WARNING: has_launchy? proc {
139
- WARNING: Launchy::Browser.new.visit url
140
- WARNING: }
141
- WARNING: end
142
- WARNING:
143
- WARNING: If this is not the case, please file a bug. Please file a bug at https://github.com/copiousfreetime/launchy/issues/new
144
-
145
- These deprecation notices will go away with version 3.0 and the only available
146
- API will be the documented one.
147
-
148
112
  ## ISC LICENSE
149
113
 
150
114
  https://opensource.org/licenses/isc-license.txt
data/exe/launchy ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "launchy"
5
+ Launchy::Cli.new.run(ARGV, ENV)
data/launchy.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # DO NOT EDIT - This file is automatically generated
2
+ # Make changes to Manifest.txt and/or Rakefile and regenerate
3
+ # -*- encoding: utf-8 -*-
4
+ # stub: launchy 3.1.1 ruby lib
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "launchy".freeze
8
+ s.version = "3.1.1".freeze
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
11
+ s.metadata = { "bug_tracker_uri" => "https://github.com/copiousfreetime/launchy/issues", "changelog_uri" => "https://github.com/copiousfreetime/launchy/blob/master/HISTORY.md", "homepage_uri" => "https://github.com/copiousfreetime/launchy", "source_code_uri" => "https://github.com/copiousfreetime/launchy" } if s.respond_to? :metadata=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Jeremy Hinegardner".freeze]
14
+ s.bindir = "exe".freeze
15
+ s.date = "2025-02-21"
16
+ s.description = "Launchy is helper class for launching cross-platform applications in a fire and forget manner. There are application concepts (browser, email client, etc) that are common across all platforms, and they may be launched differently on each platform. Launchy is here to make a common approach to launching external applications from within ruby programs.".freeze
17
+ s.email = "jeremy@copiousfreetime.org".freeze
18
+ s.executables = ["launchy".freeze]
19
+ s.extra_rdoc_files = ["CONTRIBUTING.md".freeze, "HISTORY.md".freeze, "LICENSE.txt".freeze, "Manifest.txt".freeze, "README.md".freeze]
20
+ s.files = ["CONTRIBUTING.md".freeze, "HISTORY.md".freeze, "LICENSE.txt".freeze, "Manifest.txt".freeze, "README.md".freeze, "exe/launchy".freeze, "launchy.gemspec".freeze, "lib/launchy.rb".freeze, "lib/launchy/application.rb".freeze, "lib/launchy/applications/browser.rb".freeze, "lib/launchy/argv.rb".freeze, "lib/launchy/cli.rb".freeze, "lib/launchy/descendant_tracker.rb".freeze, "lib/launchy/detect.rb".freeze, "lib/launchy/detect/host_os.rb".freeze, "lib/launchy/detect/host_os_family.rb".freeze, "lib/launchy/detect/nix_desktop_environment.rb".freeze, "lib/launchy/error.rb".freeze, "lib/launchy/os_family.rb".freeze, "lib/launchy/runner.rb".freeze, "lib/launchy/version.rb".freeze]
21
+ s.homepage = "https://github.com/copiousfreetime/launchy".freeze
22
+ s.licenses = ["ISC".freeze]
23
+ s.rdoc_options = ["--main".freeze, "README.md".freeze, "--markup".freeze, "tomdoc".freeze]
24
+ s.required_ruby_version = Gem::Requirement.new(">= 2.3.0".freeze)
25
+ s.rubygems_version = "3.6.3".freeze
26
+ s.summary = "Launchy is helper class for launching cross-platform applications in a fire and forget manner.".freeze
27
+
28
+ s.specification_version = 4
29
+
30
+ s.add_runtime_dependency(%q<addressable>.freeze, ["~> 2.8".freeze])
31
+ s.add_runtime_dependency(%q<childprocess>.freeze, ["~> 5.0".freeze])
32
+ s.add_runtime_dependency(%q<logger>.freeze, ["~> 1.6".freeze])
33
+ end
@@ -1,4 +1,6 @@
1
- require 'set'
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
2
4
  module Launchy
3
5
  #
4
6
  # Application is the base class of all the application types that launchy may
@@ -18,45 +20,61 @@ module Launchy
18
20
  # Find the application that handles the given uri.
19
21
  #
20
22
  # returns the Class that can handle the uri
21
- def handling( uri )
22
- klass = find_child( :handles?, uri )
23
+ def handling(uri)
24
+ klass = find_child(:handles?, uri)
23
25
  return klass if klass
26
+
24
27
  raise ApplicationNotFoundError, "No application found to handle '#{uri}'"
25
28
  end
26
29
 
30
+ # Find the application with the given name
27
31
  #
32
+ # returns the Class that has the given name
33
+ def for_name(name)
34
+ klass = find_child(:has_name?, name)
35
+ return klass if klass
36
+
37
+ raise ApplicationNotFoundError, "No application found named '#{name}'"
38
+ end
39
+
28
40
  # Find the given executable in the available paths
29
- def find_executable( bin, *paths )
30
- paths = Launchy.path.split( File::PATH_SEPARATOR ) if paths.empty?
41
+ #
42
+ # returns the path to the executable or nil if not found
43
+ def find_executable(bin, *paths)
44
+ paths = Launchy.path.split(File::PATH_SEPARATOR) if paths.empty?
31
45
  paths.each do |path|
32
- file = File.join( path, bin )
33
- if File.executable?( file ) then
34
- Launchy.log "#{self.name} : found executable #{file}"
46
+ file = File.join(path, bin)
47
+ if File.executable?(file)
48
+ Launchy.log "#{name} : found executable #{file}"
35
49
  return file
36
50
  end
37
51
  end
38
- Launchy.log "#{self.name} : Unable to find `#{bin}' in #{paths.join(", ")}"
39
- return nil
52
+ Launchy.log "#{name} : Unable to find `#{bin}' in #{paths.join(', ')}"
53
+ nil
54
+ end
55
+
56
+ # Does this class have the given name-like string?
57
+ #
58
+ # returns true if the class has the given name
59
+ def has_name?(qname)
60
+ qname.to_s.downcase == name.split("::").last.downcase
40
61
  end
41
62
  end
42
63
 
43
- attr_reader :host_os_family
44
- attr_reader :ruby_engine
45
- attr_reader :runner
64
+ attr_reader :host_os_family, :runner
46
65
 
47
66
  def initialize
48
67
  @host_os_family = Launchy::Detect::HostOsFamily.detect
49
- @ruby_engine = Launchy::Detect::RubyEngine.detect
50
- @runner = Launchy::Detect::Runner.detect
68
+ @runner = Launchy::Runner.new
51
69
  end
52
70
 
53
- def find_executable( bin, *paths )
54
- Application.find_executable( bin, *paths )
71
+ def find_executable(bin, *paths)
72
+ Application.find_executable(bin, *paths)
55
73
  end
56
74
 
57
- def run( cmd, *args )
58
- runner.run( cmd, *args )
75
+ def run(cmd, *args)
76
+ runner.run(cmd, *args)
59
77
  end
60
78
  end
61
79
  end
62
- require 'launchy/applications/browser'
80
+ require "launchy/applications/browser"
@@ -1,82 +1,89 @@
1
- class Launchy::Application
2
- #
3
- # The class handling the browser application and all of its schemes
4
- #
5
- class Browser < Launchy::Application
6
- def self.schemes
7
- %w[ http https ftp file ]
8
- end
1
+ # frozen_string_literal: true
9
2
 
10
- def self.handles?( uri )
11
- return true if schemes.include?( uri.scheme )
12
- return true if File.exist?( uri.path )
13
- end
3
+ module Launchy
4
+ class Application
5
+ #
6
+ # The class handling the browser application and all of its schemes
7
+ #
8
+ class Browser < Launchy::Application
9
+ def self.schemes
10
+ %w[http https ftp file]
11
+ end
14
12
 
15
- def windows_app_list
16
- [ 'start "launchy" /b' ]
17
- end
13
+ def self.handles?(uri)
14
+ return true if schemes.include?(uri.scheme)
18
15
 
19
- def cygwin_app_list
20
- [ 'cmd /C start "launchy" /b' ]
21
- end
16
+ true if File.exist?(uri.path)
17
+ end
22
18
 
23
- # hardcode this to open?
24
- def darwin_app_list
25
- [ find_executable( "open" ) ]
26
- end
19
+ # The escaped \\ is necessary so that when shellsplit is done later,
20
+ # the "launchy", with quotes, goes through to the commandline, since that
21
+ def windows_app_list
22
+ ['start \\"launchy\\" /b']
23
+ end
27
24
 
28
- def nix_app_list
29
- nix_de = Launchy::Detect::NixDesktopEnvironment.detect
30
- list = nix_de.browsers
31
- list.find_all { |argv| argv.valid? }
32
- end
25
+ def cygwin_app_list
26
+ ['cmd /C start \\"launchy\\" /b']
27
+ end
33
28
 
34
- # use a call back mechanism to get the right app_list that is decided by the
35
- # host_os_family class.
36
- def app_list
37
- host_os_family.app_list( self )
38
- end
29
+ # hardcode this to open?
30
+ def darwin_app_list
31
+ [find_executable("open")]
32
+ end
39
33
 
40
- def browser_env
41
- return [] unless ENV['BROWSER']
42
- browser_env = ENV['BROWSER'].split( File::PATH_SEPARATOR )
43
- browser_env.flatten!
44
- browser_env.delete_if { |b| b.nil? || (b.strip.size == 0) }
45
- return browser_env
46
- end
34
+ def nix_app_list
35
+ nix_de = Launchy::Detect::NixDesktopEnvironment.detect
36
+ list = nix_de.browsers
37
+ list.find_all(&:valid?)
38
+ end
47
39
 
48
- # Get the full commandline of what we are going to add the uri to
49
- def browser_cmdline
50
- browser_env.each do |p|
51
- Launchy.log "#{self.class.name} : possibility from BROWSER environment variable : #{p}"
40
+ # use a call back mechanism to get the right app_list that is decided by the
41
+ # host_os_family class.
42
+ def app_list
43
+ host_os_family.app_list(self)
52
44
  end
53
- app_list.each do |p|
54
- Launchy.log "#{self.class.name} : possibility from app_list : #{p}"
45
+
46
+ def browser_env
47
+ return [] unless ENV["BROWSER"]
48
+
49
+ browser_env = ENV["BROWSER"].split(File::PATH_SEPARATOR)
50
+ browser_env.flatten!
51
+ browser_env.delete_if { |b| b.nil? || b.strip.empty? }
52
+ browser_env
55
53
  end
56
54
 
57
- possibilities = (browser_env + app_list).flatten
55
+ # Get the full commandline of what we are going to add the uri to
56
+ def browser_cmdline
57
+ browser_env.each do |p|
58
+ Launchy.log "#{self.class.name} : possibility from BROWSER environment variable : #{p}"
59
+ end
60
+ app_list.each do |p|
61
+ Launchy.log "#{self.class.name} : possibility from app_list : #{p}"
62
+ end
63
+
64
+ possibilities = (browser_env + app_list).flatten
58
65
 
59
- if browser = possibilities.shift then
60
- Launchy.log "#{self.class.name} : Using browser value '#{browser}'"
61
- return browser
66
+ if (browser = possibilities.shift)
67
+ Launchy.log "#{self.class.name} : Using browser value '#{browser}'"
68
+ return browser
69
+ end
70
+ raise Launchy::CommandNotFoundError,
71
+ "Unable to find a browser command. If this is unexpected, #{Launchy.bug_report_message}"
62
72
  end
63
- raise Launchy::CommandNotFoundError, "Unable to find a browser command. If this is unexpected, #{Launchy.bug_report_message}"
64
- end
65
73
 
66
- def cmd_and_args( uri, options = {} )
67
- cmd = browser_cmdline.to_s
68
- args = [ uri.to_s ]
69
- if cmd =~ /%s/ then
70
- cmd.gsub!( /%s/, args.shift )
74
+ def cmd_and_args(uri, _options = {})
75
+ cmd = browser_cmdline.to_s
76
+ args = [uri.to_s]
77
+ cmd.gsub!("%s", args.shift) if cmd.include?("%s")
78
+ [cmd, args]
71
79
  end
72
- [cmd, args]
73
- end
74
80
 
75
- # final assembly of the command and do %s substitution
76
- # http://www.catb.org/~esr/BROWSER/index.html
77
- def open( uri, options = {} )
78
- cmd, args = cmd_and_args( uri, options )
79
- run( cmd, args )
81
+ # final assembly of the command and do %s substitution
82
+ # http://www.catb.org/~esr/BROWSER/index.html
83
+ def open(uri, options = {})
84
+ cmd, args = cmd_and_args(uri, options)
85
+ run(cmd, args)
86
+ end
80
87
  end
81
88
  end
82
89
  end
data/lib/launchy/argv.rb CHANGED
@@ -1,12 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Launchy
4
+ # Internal: Ecapsulate the commandline argumens passed to Launchy
5
+ #
2
6
  class Argv
3
7
  attr_reader :argv
4
- def initialize( *args )
8
+
9
+ def initialize(*args)
5
10
  @argv = args.flatten
6
11
  end
7
12
 
8
13
  def to_s
9
- @argv.join(' ')
14
+ @argv.join(" ")
10
15
  end
11
16
 
12
17
  def to_str
@@ -18,18 +23,18 @@ module Launchy
18
23
  end
19
24
 
20
25
  def valid?
21
- (not blank?) && executable?
26
+ !blank? && executable?
22
27
  end
23
28
 
24
29
  def blank?
25
- @argv.empty? || (@argv.first.strip.size == 0)
30
+ @argv.empty? || @argv.first.strip.empty?
26
31
  end
27
32
 
28
33
  def executable?
29
- ::Launchy::Application.find_executable( @argv.first )
34
+ ::Launchy::Application.find_executable(@argv.first)
30
35
  end
31
36
 
32
- def ==( other )
37
+ def ==(other)
33
38
  @argv == other.argv
34
39
  end
35
40
  end
data/lib/launchy/cli.rb CHANGED
@@ -1,9 +1,13 @@
1
- require 'optparse'
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
2
4
 
3
5
  module Launchy
6
+ # Internal: Command line interface for Launchy
7
+ #
4
8
  class Cli
5
-
6
9
  attr_reader :options
10
+
7
11
  def initialize
8
12
  @options = {}
9
13
  end
@@ -15,75 +19,66 @@ module Launchy
15
19
  op.separator ""
16
20
  op.separator "Launch Options:"
17
21
 
18
- op.on( "-a", "--application APPLICATION",
19
- "Explicitly specify the application class to use in the launch") do |app|
22
+ op.on("-a", "--application APPLICATION",
23
+ "Explicitly specify the application class to use in the launch") do |app|
20
24
  @options[:application] = app
21
25
  end
22
26
 
23
- op.on( "-d", "--debug",
24
- "Force debug. Output lots of information.") do |d|
27
+ op.on("-d", "--debug",
28
+ "Force debug. Output lots of information.") do |_d|
25
29
  @options[:debug] = true
26
30
  end
27
31
 
28
- op.on( "-e", "--engine RUBY_ENGINE",
29
- "Force launchy to behave as if it was on a particular ruby engine.") do |e|
30
- @options[:ruby_engine] = e
31
- end
32
-
33
- op.on( "-n", "--dry-run", "Don't launchy, print the command to be executed on stdout" ) do |x|
32
+ op.on("-n", "--dry-run", "Don't launchy, print the command to be executed on stdout") do |_x|
34
33
  @options[:dry_run] = true
35
34
  end
36
35
 
37
- op.on( "-o", "--host-os HOST_OS",
38
- "Force launchy to behave as if it was on a particular host os.") do |os|
36
+ op.on("-o", "--host-os HOST_OS",
37
+ "Force launchy to behave as if it was on a particular host os.") do |os|
39
38
  @options[:host_os] = os
40
39
  end
41
40
 
42
-
43
41
  op.separator ""
44
42
  op.separator "Standard Options:"
45
43
 
46
- op.on( "-h", "--help", "Print this message.") do |h|
44
+ op.on("-h", "--help", "Print this message.") do |_h|
47
45
  $stdout.puts op.to_s
48
46
  exit 0
49
47
  end
50
48
 
51
- op.on( "-v", "--version", "Output the version of Launchy") do |v|
49
+ op.on("-v", "--version", "Output the version of Launchy") do |_v|
52
50
  $stdout.puts "Launchy version #{Launchy::VERSION}"
53
51
  exit 0
54
52
  end
55
-
56
53
  end
57
54
  end
58
55
 
59
- def parse( argv, env )
60
- parser.parse!( argv )
61
- return true
62
- rescue ::OptionParser::ParseError => pe
63
- error_output( pe )
56
+ def parse(argv, _env)
57
+ parser.parse!(argv)
58
+ true
59
+ rescue ::OptionParser::ParseError => e
60
+ error_output(e)
64
61
  end
65
62
 
66
- def good_run( argv, env )
67
- if parse( argv, env ) then
68
- Launchy.open( argv.shift, options ) { |e| error_output( e ) }
69
- return true
70
- else
71
- return false
72
- end
63
+ def good_run(argv, env)
64
+ return false unless parse(argv, env)
65
+
66
+ Launchy.open(argv.shift, options) { |e| error_output(e) }
67
+ true
73
68
  end
74
69
 
75
- def error_output( error )
70
+ def error_output(error)
76
71
  $stderr.puts "ERROR: #{error}"
77
72
  Launchy.log "ERROR: #{error}"
78
73
  error.backtrace.each do |bt|
79
74
  Launchy.log bt
80
75
  end
81
76
  $stderr.puts "Try `#{parser.program_name} --help' for more information."
82
- return false
77
+ false
83
78
  end
84
79
 
85
- def run( argv = ARGV, env = ENV )
86
- exit 1 unless good_run( argv, env )
80
+ def run(argv = ARGV, env = ENV)
81
+ exit 1 unless good_run(argv, env)
87
82
  end
88
83
  end
89
84
  end
@@ -1,4 +1,6 @@
1
- require 'set'
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
2
4
 
3
5
  module Launchy
4
6
  #
@@ -9,7 +11,7 @@ module Launchy
9
11
  # end
10
12
  #
11
13
  # or
12
- #
14
+ #
13
15
  # class Foo
14
16
  # class << self
15
17
  # include DescendantTracker
@@ -20,29 +22,29 @@ module Launchy
20
22
  # them in a Set that is available via the 'children' method.
21
23
  #
22
24
  module DescendantTracker
23
- def inherited( klass )
24
- return unless klass.instance_of?( Class )
25
- self.children << klass
25
+ def inherited(klass)
26
+ super
27
+ return unless klass.instance_of?(Class)
28
+
29
+ children << klass
26
30
  end
27
31
 
28
32
  #
29
33
  # The list of children that are registered
30
34
  #
31
35
  def children
32
- unless defined? @children
33
- @children = Array.new
34
- end
35
- return @children
36
+ @children = [] unless defined? @children
37
+ @children
36
38
  end
37
39
 
38
40
  #
39
41
  # Find one of the child classes by calling the given method
40
- # and passing all the rest of the parameters to that method in
42
+ # and passing all the rest of the parameters to that method in
41
43
  # each child
42
- def find_child( method, *args )
44
+ def find_child(method, *args)
43
45
  children.find do |child|
44
46
  Launchy.log "Checking if class #{child} is the one for #{method}(#{args.join(', ')})}"
45
- child.send( method, *args )
47
+ child.send(method, *args)
46
48
  end
47
49
  end
48
50
  end