launchy 2.5.0 → 3.0.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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -0
  3. data/HISTORY.md +38 -20
  4. data/{LICENSE → LICENSE.txt} +1 -1
  5. data/Manifest.txt +4 -21
  6. data/README.md +10 -47
  7. data/exe/launchy +5 -0
  8. data/launchy.gemspec +32 -0
  9. data/lib/launchy/application.rb +38 -20
  10. data/lib/launchy/applications/browser.rb +68 -63
  11. data/lib/launchy/argv.rb +11 -6
  12. data/lib/launchy/cli.rb +29 -34
  13. data/lib/launchy/descendant_tracker.rb +14 -12
  14. data/lib/launchy/detect/host_os.rb +21 -18
  15. data/lib/launchy/detect/host_os_family.rb +94 -53
  16. data/lib/launchy/detect/nix_desktop_environment.rb +74 -69
  17. data/lib/launchy/detect.rb +7 -5
  18. data/lib/launchy/error.rb +2 -0
  19. data/lib/launchy/os_family.rb +2 -0
  20. data/lib/launchy/runner.rb +54 -0
  21. data/lib/launchy/version.rb +7 -5
  22. data/lib/launchy.rb +76 -68
  23. metadata +22 -93
  24. data/Rakefile +0 -27
  25. data/bin/launchy +0 -4
  26. data/lib/launchy/deprecated.rb +0 -52
  27. data/lib/launchy/detect/ruby_engine.rb +0 -78
  28. data/lib/launchy/detect/runner.rb +0 -152
  29. data/spec/application_spec.rb +0 -43
  30. data/spec/applications/browser_spec.rb +0 -78
  31. data/spec/cli_spec.rb +0 -75
  32. data/spec/detect/host_os_family_spec.rb +0 -42
  33. data/spec/detect/host_os_spec.rb +0 -19
  34. data/spec/detect/nix_desktop_environment_spec.rb +0 -27
  35. data/spec/detect/ruby_engine_spec.rb +0 -37
  36. data/spec/detect/runner_spec.rb +0 -103
  37. data/spec/launchy_spec.rb +0 -119
  38. data/spec/mock_application.rb +0 -9
  39. data/spec/spec_helper.rb +0 -11
  40. data/spec/tattle-host-os.yaml +0 -427
  41. data/spec/version_spec.rb +0 -11
  42. data/tasks/default.rake +0 -242
  43. data/tasks/this.rb +0 -208
data/lib/launchy.rb CHANGED
@@ -1,4 +1,9 @@
1
- require 'addressable/uri'
1
+ # frozen_string_literal: true
2
+
3
+ require "English"
4
+ require "addressable/uri"
5
+ require "shellwords"
6
+ require "stringio"
2
7
 
3
8
  #
4
9
  # The entry point into Launchy. This is the sole supported public API.
@@ -11,113 +16,118 @@ require 'addressable/uri'
11
16
  # :application Explicitly state what application class is going to be used.
12
17
  # This must be a child class of Launchy::Application
13
18
  # :host_os Explicitly state what host operating system to pretend to be
14
- # :ruby_engine Explicitly state what ruby engine to pretend to be under
15
19
  # :dry_run Do nothing and print the command that would be executed on $stdout
16
20
  #
17
21
  # Other options may be used, and those will be passed directly to the
18
22
  # application class
19
23
  #
20
24
  module Launchy
21
-
22
25
  class << self
23
26
  #
24
27
  # Launch an application for the given uri string
25
28
  #
26
- def open(uri_s, options = {}, &error_block )
27
- leftover = extract_global_options( options )
28
- uri = string_to_uri( uri_s )
29
- app = app_for_uri( uri )
30
- app.new.open( uri, leftover )
31
- rescue Launchy::Error => le
32
- raise le
33
- rescue Exception => e
29
+ def open(uri_s, options = {})
30
+ leftover = extract_global_options(options)
31
+ uri = string_to_uri(uri_s)
32
+ if (name = options[:application])
33
+ app = app_for_name(name)
34
+ end
35
+
36
+ app = app_for_uri(uri) if app.nil?
37
+
38
+ app.new.open(uri, leftover)
39
+ rescue Launchy::Error => e
40
+ raise e
41
+ rescue StandardError => e
34
42
  msg = "Failure in opening uri #{uri_s.inspect} with options #{options.inspect}: #{e}"
35
43
  raise Launchy::Error, msg
36
44
  ensure
37
- if $! and block_given? then
38
- yield $!
39
- return # explicitly swallow the errors
45
+ if $ERROR_INFO && block_given?
46
+ yield $ERROR_INFO
47
+
48
+ # explicitly return here to swallow the errors if there was an error
49
+ # and we yielded to the block
50
+ # rubocop:disable Lint/EnsureReturn
51
+ return
52
+ # rubocop:enable Lint/EnsureReturn
40
53
  end
41
54
  end
42
55
 
43
- def app_for_uri( uri )
44
- Launchy::Application.handling( uri )
56
+ def app_for_uri(uri)
57
+ Launchy::Application.handling(uri)
58
+ end
59
+
60
+ def app_for_name(name)
61
+ Launchy::Application.for_name(name)
62
+ rescue Launchy::ApplicationNotFoundError
63
+ nil
45
64
  end
46
65
 
47
- def app_for_uri_string( s )
48
- app_for_uri( string_to_uri( s ) )
66
+ def app_for_uri_string(str)
67
+ app_for_uri(string_to_uri(str))
49
68
  end
50
69
 
51
- def string_to_uri( s )
52
- s = s.to_s
53
- uri = Addressable::URI.parse( s )
54
- Launchy.log "URI parsing pass 1 : #{s} -> #{uri.to_hash}"
55
- if not uri.scheme then
56
- uri = Addressable::URI.heuristic_parse( s )
57
- Launchy.log "URI parsing pass 2 : #{s} -> #{uri.to_hash}"
70
+ def string_to_uri(str)
71
+ str = str.to_s
72
+ uri = Addressable::URI.parse(str)
73
+ Launchy.log "URI parsing pass 1 : #{str} -> #{uri.to_hash}"
74
+ unless uri.scheme
75
+ uri = Addressable::URI.heuristic_parse(str)
76
+ Launchy.log "URI parsing pass 2 : #{str} -> #{uri.to_hash}"
58
77
  end
59
- raise Launchy::ArgumentError, "Invalid URI given: #{s.inspect}" unless uri
60
- return uri
78
+ raise Launchy::ArgumentError, "Invalid URI given: #{str.inspect}" unless uri
79
+
80
+ uri
61
81
  end
62
82
 
63
83
  def reset_global_options
64
84
  Launchy.debug = false
65
85
  Launchy.application = nil
66
86
  Launchy.host_os = nil
67
- Launchy.ruby_engine = nil
68
87
  Launchy.dry_run = false
69
- Launchy.path = ENV['PATH']
88
+ Launchy.path = ENV.fetch("PATH", nil)
70
89
  end
71
90
 
72
- def extract_global_options( options )
91
+ def extract_global_options(options)
73
92
  leftover = options.dup
74
- Launchy.debug = leftover.delete( :debug ) || ENV['LAUNCHY_DEBUG']
75
- Launchy.application = leftover.delete( :application ) || ENV['LAUNCHY_APPLICATION']
76
- Launchy.host_os = leftover.delete( :host_os ) || ENV['LAUNCHY_HOST_OS']
77
- Launchy.ruby_engine = leftover.delete( :ruby_engine ) || ENV['LAUNCHY_RUBY_ENGINE']
78
- Launchy.dry_run = leftover.delete( :dry_run ) || ENV['LAUNCHY_DRY_RUN']
93
+ Launchy.debug = leftover.delete(:debug) || ENV.fetch("LAUNCHY_DEBUG", nil)
94
+ Launchy.application = leftover.delete(:application) || ENV.fetch("LAUNCHY_APPLICATION", nil)
95
+ Launchy.host_os = leftover.delete(:host_os) || ENV.fetch("LAUNCHY_HOST_OS", nil)
96
+ Launchy.dry_run = leftover.delete(:dry_run) || ENV.fetch("LAUNCHY_DRY_RUN", nil)
79
97
  end
80
98
 
81
- def debug=( d )
82
- @debug = to_bool( d )
99
+ def debug=(enabled)
100
+ @debug = to_bool(enabled)
83
101
  end
84
102
 
85
103
  # we may do logging before a call to 'open', hence the need to check
86
104
  # LAUNCHY_DEBUG here
87
105
  def debug?
88
- @debug || to_bool( ENV['LAUNCHY_DEBUG'] )
106
+ @debug || to_bool(ENV.fetch("LAUNCHY_DEBUG", nil))
89
107
  end
90
108
 
91
- def application=( app )
109
+ def application=(app)
92
110
  @application = app
93
111
  end
94
112
 
95
113
  def application
96
- @application || ENV['LAUNCHY_APPLICATION']
114
+ @application || ENV.fetch("LAUNCHY_APPLICATION", nil)
97
115
  end
98
116
 
99
- def host_os=( host_os )
117
+ def host_os=(host_os)
100
118
  @host_os = host_os
101
119
  end
102
120
 
103
121
  def host_os
104
- @host_os || ENV['LAUNCHY_HOST_OS']
105
- end
106
-
107
- def ruby_engine=( ruby_engine )
108
- @ruby_engine = ruby_engine
122
+ @host_os || ENV.fetch("LAUNCHY_HOST_OS", nil)
109
123
  end
110
124
 
111
- def ruby_engine
112
- @ruby_engine || ENV['LAUNCHY_RUBY_ENGINE']
113
- end
114
-
115
- def dry_run=( dry_run )
116
- @dry_run = to_bool( dry_run )
125
+ def dry_run=(dry_run)
126
+ @dry_run = to_bool(dry_run)
117
127
  end
118
128
 
119
129
  def dry_run?
120
- @dry_run || to_bool( ENV['LAUNCHY_DRY_RUN'] )
130
+ @dry_run || to_bool(ENV.fetch("LAUNCHY_DRY_RUN", nil))
121
131
  end
122
132
 
123
133
  def bug_report_message
@@ -136,15 +146,13 @@ module Launchy
136
146
  @path = path
137
147
  end
138
148
 
139
- private
140
- def to_bool( arg )
149
+ private
150
+
151
+ def to_bool(arg)
141
152
  if arg.is_a? String
142
- arg == 'true'
143
- elsif arg.is_a? TrueClass
144
- true
153
+ arg == "true"
145
154
  else
146
- # All other values mapped to false.
147
- false
155
+ arg.is_a? TrueClass
148
156
  end
149
157
  end
150
158
  end
@@ -153,11 +161,11 @@ module Launchy
153
161
  Launchy.reset_global_options
154
162
  end
155
163
 
156
- require 'launchy/version'
157
- require 'launchy/argv'
158
- require 'launchy/cli'
159
- require 'launchy/descendant_tracker'
160
- require 'launchy/error'
161
- require 'launchy/application'
162
- require 'launchy/detect'
163
- require 'launchy/deprecated'
164
+ require "launchy/version"
165
+ require "launchy/argv"
166
+ require "launchy/cli"
167
+ require "launchy/descendant_tracker"
168
+ require "launchy/error"
169
+ require "launchy/application"
170
+ require "launchy/detect"
171
+ require "launchy/runner"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: launchy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Hinegardner
8
- autorequire:
9
- bindir: bin
8
+ autorequire:
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-28 00:00:00.000000000 Z
11
+ date: 2024-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -16,70 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.7'
19
+ version: '2.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.7'
26
+ version: '2.8'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: childprocess
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '13.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '13.0'
41
- - !ruby/object:Gem::Dependency
42
- name: minitest
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '5.14'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '5.14'
55
- - !ruby/object:Gem::Dependency
56
- name: rdoc
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '6.2'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '6.2'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '0.18'
76
- type: :development
33
+ version: '5.0'
34
+ type: :runtime
77
35
  prerelease: false
78
36
  version_requirements: !ruby/object:Gem::Requirement
79
37
  requirements:
80
38
  - - "~>"
81
39
  - !ruby/object:Gem::Version
82
- version: '0.18'
40
+ version: '5.0'
83
41
  description: Launchy is helper class for launching cross-platform applications in
84
42
  a fire and forget manner. There are application concepts (browser, email client,
85
43
  etc) that are common across all platforms, and they may be launched differently
@@ -92,56 +50,40 @@ extensions: []
92
50
  extra_rdoc_files:
93
51
  - CONTRIBUTING.md
94
52
  - HISTORY.md
53
+ - LICENSE.txt
95
54
  - Manifest.txt
96
55
  - README.md
97
56
  files:
98
57
  - CONTRIBUTING.md
99
58
  - HISTORY.md
100
- - LICENSE
59
+ - LICENSE.txt
101
60
  - Manifest.txt
102
61
  - README.md
103
- - Rakefile
104
- - bin/launchy
62
+ - exe/launchy
63
+ - launchy.gemspec
105
64
  - lib/launchy.rb
106
65
  - lib/launchy/application.rb
107
66
  - lib/launchy/applications/browser.rb
108
67
  - lib/launchy/argv.rb
109
68
  - lib/launchy/cli.rb
110
- - lib/launchy/deprecated.rb
111
69
  - lib/launchy/descendant_tracker.rb
112
70
  - lib/launchy/detect.rb
113
71
  - lib/launchy/detect/host_os.rb
114
72
  - lib/launchy/detect/host_os_family.rb
115
73
  - lib/launchy/detect/nix_desktop_environment.rb
116
- - lib/launchy/detect/ruby_engine.rb
117
- - lib/launchy/detect/runner.rb
118
74
  - lib/launchy/error.rb
119
75
  - lib/launchy/os_family.rb
76
+ - lib/launchy/runner.rb
120
77
  - lib/launchy/version.rb
121
- - spec/application_spec.rb
122
- - spec/applications/browser_spec.rb
123
- - spec/cli_spec.rb
124
- - spec/detect/host_os_family_spec.rb
125
- - spec/detect/host_os_spec.rb
126
- - spec/detect/nix_desktop_environment_spec.rb
127
- - spec/detect/ruby_engine_spec.rb
128
- - spec/detect/runner_spec.rb
129
- - spec/launchy_spec.rb
130
- - spec/mock_application.rb
131
- - spec/spec_helper.rb
132
- - spec/tattle-host-os.yaml
133
- - spec/version_spec.rb
134
- - tasks/default.rake
135
- - tasks/this.rb
136
- homepage: http://github.com/copiousfreetime/launchy
78
+ homepage: https://github.com/copiousfreetime/launchy
137
79
  licenses:
138
80
  - ISC
139
81
  metadata:
140
82
  bug_tracker_uri: https://github.com/copiousfreetime/launchy/issues
141
- changelog_uri: https://github.com/copiousfreetime/launchy/blob/master/README.md
83
+ changelog_uri: https://github.com/copiousfreetime/launchy/blob/master/HISTORY.md
142
84
  homepage_uri: https://github.com/copiousfreetime/launchy
143
85
  source_code_uri: https://github.com/copiousfreetime/launchy
144
- post_install_message:
86
+ post_install_message:
145
87
  rdoc_options:
146
88
  - "--main"
147
89
  - README.md
@@ -153,29 +95,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
95
  requirements:
154
96
  - - ">="
155
97
  - !ruby/object:Gem::Version
156
- version: 2.4.0
98
+ version: 2.3.0
157
99
  required_rubygems_version: !ruby/object:Gem::Requirement
158
100
  requirements:
159
101
  - - ">="
160
102
  - !ruby/object:Gem::Version
161
103
  version: '0'
162
104
  requirements: []
163
- rubygems_version: 3.0.3
164
- signing_key:
105
+ rubygems_version: 3.5.9
106
+ signing_key:
165
107
  specification_version: 4
166
108
  summary: Launchy is helper class for launching cross-platform applications in a fire
167
109
  and forget manner.
168
- test_files:
169
- - spec/application_spec.rb
170
- - spec/applications/browser_spec.rb
171
- - spec/cli_spec.rb
172
- - spec/detect/host_os_family_spec.rb
173
- - spec/detect/host_os_spec.rb
174
- - spec/detect/nix_desktop_environment_spec.rb
175
- - spec/detect/ruby_engine_spec.rb
176
- - spec/detect/runner_spec.rb
177
- - spec/launchy_spec.rb
178
- - spec/mock_application.rb
179
- - spec/spec_helper.rb
180
- - spec/tattle-host-os.yaml
181
- - spec/version_spec.rb
110
+ test_files: []
data/Rakefile DELETED
@@ -1,27 +0,0 @@
1
- # vim: syntax=ruby
2
- load 'tasks/this.rb'
3
-
4
- This.name = "launchy"
5
- This.author = "Jeremy Hinegardner"
6
- This.email = "jeremy@copiousfreetime.org"
7
- This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
8
-
9
- This.ruby_gemspec do |spec|
10
- spec.add_dependency( 'addressable', '~> 2.7')
11
-
12
- spec.add_development_dependency( 'rake' , '~> 13.0')
13
- spec.add_development_dependency( 'minitest' , '~> 5.14' )
14
- spec.add_development_dependency( 'rdoc' , '~> 6.2' )
15
- spec.add_development_dependency( 'simplecov', '~> 0.18' )
16
-
17
- spec.licenses = ['ISC']
18
-
19
- spec.metadata = {
20
- "bug_tracker_uri" => "https://github.com/copiousfreetime/launchy/issues",
21
- "changelog_uri" => "https://github.com/copiousfreetime/launchy/blob/master/README.md",
22
- "homepage_uri" => "https://github.com/copiousfreetime/launchy",
23
- "source_code_uri" => "https://github.com/copiousfreetime/launchy",
24
- }
25
- end
26
-
27
- load 'tasks/default.rake'
data/bin/launchy DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'launchy'
4
- Launchy::Cli.new.run( ARGV, ENV )
@@ -1,52 +0,0 @@
1
- module Launchy
2
- #
3
- # This class is deprecated and will be removed
4
- #
5
- class Browser
6
- def self.run( *args )
7
- Browser.new.visit( args[0] )
8
- end
9
-
10
- def visit( url )
11
- _warn "You made a call to a deprecated Launchy API. This call should be changed to 'Launchy.open( uri )'"
12
- report_caller_context( caller )
13
-
14
- ::Launchy.open( url )
15
- end
16
-
17
- private
18
-
19
- def find_caller_context( stack )
20
- caller_file = stack.find do |line|
21
- not line.index( __FILE__ )
22
- end
23
- if caller_file then
24
- caller_fname, caller_line, _ = caller_file.split(":")
25
- if File.readable?( caller_fname ) then
26
- caller_lines = IO.readlines( caller_fname )
27
- context = [ caller_file ]
28
- context << caller_lines[(caller_line.to_i)-3, 5]
29
- return context.flatten
30
- end
31
- end
32
- return []
33
- end
34
-
35
- def report_caller_context( stack )
36
- context = find_caller_context( stack )
37
- if context.size > 0 then
38
- _warn "I think I was able to find the location that needs to be fixed. Please go look at:"
39
- _warn
40
- context.each do |line|
41
- _warn line.rstrip
42
- end
43
- _warn
44
- _warn "If this is not the case, please file a bug. #{Launchy.bug_report_message}"
45
- end
46
- end
47
-
48
- def _warn( msg = "" )
49
- warn "WARNING: #{msg}"
50
- end
51
- end
52
- end
@@ -1,78 +0,0 @@
1
- module Launchy::Detect
2
- class RubyEngine
3
- class NotFoundError < Launchy::Error; end
4
-
5
- extend ::Launchy::DescendantTracker
6
-
7
- # Detect the current ruby engine.
8
- #
9
- # If the current ruby engine cannot be detected, the return
10
- # RubyEngine::Unknown
11
- def self.detect( ruby_engine = RubyEngine.new )
12
- found = find_child( :is_current_engine?, ruby_engine.to_s )
13
- return found if found
14
- raise NotFoundError, "#{ruby_engine_error_message( ruby_engine )} #{Launchy.bug_report_message}"
15
- end
16
-
17
- def self.ruby_engine_error_message( ruby_engine )
18
- msg = "Unkonwn RUBY_ENGINE "
19
- if ruby_engine then
20
- msg += " '#{ruby_engine}'."
21
- elsif defined?( RUBY_ENGINE ) then
22
- msg += " '#{RUBY_ENGINE}'."
23
- else
24
- msg = "RUBY_ENGINE not defined for #{RUBY_DESCRIPTION}."
25
- end
26
- return msg
27
- end
28
-
29
- def self.is_current_engine?( ruby_engine )
30
- return ruby_engine == self.engine_name
31
- end
32
-
33
- def self.mri?() self == Mri; end
34
- def self.jruby?() self == Jruby; end
35
- def self.rbx?() self == Rbx; end
36
- def self.macruby?() self == MacRuby; end
37
-
38
- attr_reader :ruby_engine
39
- alias to_s ruby_engine
40
- def initialize( ruby_engine = Launchy.ruby_engine )
41
- if ruby_engine then
42
- @ruby_engine = ruby_engine
43
- else
44
- @ruby_engine = defined?( RUBY_ENGINE ) ? RUBY_ENGINE : "ruby"
45
- end
46
- end
47
-
48
-
49
- #-------------------------------
50
- # The list of known ruby engines
51
- #-------------------------------
52
-
53
- #
54
- # This is the ruby engine if the RUBY_ENGINE constant is not defined
55
- class Mri < RubyEngine
56
- def self.engine_name() "ruby"; end
57
- def self.is_current_engine?( ruby_engine )
58
- if ruby_engine then
59
- super( ruby_engine )
60
- else
61
- return true if not Launchy.ruby_engine and not defined?( RUBY_ENGINE )
62
- end
63
- end
64
- end
65
-
66
- class Jruby < RubyEngine
67
- def self.engine_name() "jruby"; end
68
- end
69
-
70
- class Rbx < RubyEngine
71
- def self.engine_name() "rbx"; end
72
- end
73
-
74
- class MacRuby < RubyEngine
75
- def self.engine_name() "macruby"; end
76
- end
77
- end
78
- end