launchy 2.5.0 → 3.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45f9c18d9b5afe8a29abfbdfb770545f3616ee1ec2547d60762e14604fd5c2e6
4
- data.tar.gz: e84671dd85e089af53899b7ee595450536522bf5f00bf88d61a775a70dfc0647
3
+ metadata.gz: 9d637a77afa69826953a3226c55fc20334c6fa90e268912bcf9a208bc9b448e2
4
+ data.tar.gz: 2f5ff5e1401319e3a97655848f4f61b9bb33e786cd1b22b76aa20a7729e0b885
5
5
  SHA512:
6
- metadata.gz: ffb4ab18f93e33bbedfe05f3506574dc7163974bcaca7057d46eae15c1a3a7369d6031cf4779769e873c33bcfb16808e0e2dddfa4477fc72c469549b68ec5685
7
- data.tar.gz: f43067afd034ea8b145a3b183ccd5ed3c4cfff4c2524233310112fdbb39e69fb7d1493f4b0816a58e7297dde8ef4efd783dec699ff262317dfe27b959b9d3943
6
+ metadata.gz: bb02ca4bd30a8394ca2a6c8e86518eb4f403d5b56c574f7730d1581a19ca686c94a001c641a09620b799b620f9d8e6be54ad39c27bb980e67268d01f68d8eae1
7
+ data.tar.gz: ba3bc128ef33d39c87b50e187ca71e0f39a2382cdf3513122ec1a108b71a55d2e2a8e0f81f138a27b8c9b1f74b8df183fe0b626d9718236efb3cb6a653fd1e62
data/CONTRIBUTING.md CHANGED
@@ -51,6 +51,7 @@ easiest way to contribute.
51
51
  * [Daniel Farina](https://github.com/fdr)
52
52
  * [Jack Turnbull](https://github.com/jackturnbull)
53
53
  * [Jeremy Moritz](https://github.com/jeremymoritz)
54
+ * [Jamie Donnelly](https://github.com/JamieKDonnelly)
54
55
 
55
56
  [GitHub Account]: https://github.com/signup/free "GitHub Signup"
56
57
  [GitHub Issues]: https://github.com/copiousfreetime/launchy/issues "Launchy Issues"
data/HISTORY.md CHANGED
@@ -1,4 +1,15 @@
1
1
  # Launchy Changelog
2
+ ## Version 3.0.0 - 2024-03-03
3
+ * Remove unused `deprecated.rb` file - <https://github.com/copiousfreetime/launchy/issues/148>
4
+ * Update supported ruby versin to be 3.x
5
+ * use the `:application` parameter - <https://github.com/copiousfreetime/launchy/issues/121>
6
+ * adjust the semaphore configuration to allow better caching
7
+ * replace the homegrown process runner with [`childprocess`](https://rubygems.org/gems/childprocess)
8
+
9
+ ## Version 2.5.2 - 2022-12-27
10
+ * Update Addressable - <https://github.com/copiousfreetime/launchy/pull/145> - JamieKDonnelly
11
+ * Fix deprecated usage of `Object#=~` - <https://github.com/copiousfreetime/launchy/pull/138> - marcrohloff
12
+ * Move to sempahore for matrix builds and macos tests
2
13
 
3
14
  ## Version 2.5.0 - 2020-02-27
4
15
  * Update depedencies
@@ -21,12 +32,12 @@
21
32
  * Abstract out the argv of the commandline - <https://github.com/copiousfreetime/launchy/issues/71>
22
33
 
23
34
  ## Version 2.4.0 - 2013-11-12
24
- * Support `Launchy.open( url, :debug => true )` - <http://github.com/copiousfreetime/launchy/issues/63> - schmich
25
- * Fix inconsistencies in `debug?` and `dry_run?` methods - <http://github.com/copiousfreetime/launchy/issues/63> - schmich
26
- * Fix detection of missing *nix desktops - <http://github.com/copiousfreetime/launchy/issues/70>
27
- * Fix running tests in bare Linux environment - <http://github.com/copiousfreetime/launchy/issues/67> - gioele
28
- * Fix mistaking windows drive as uri schema - <http://github.com/copiousfreetime/launchy/issues/65>
29
- * Attempt fixing windows `start` command oddities, again - <http://github.com/copiousfreetime/launchy/issues/62>
35
+ * Support `Launchy.open( url, :debug => true )` - <https://github.com/copiousfreetime/launchy/issues/63> - schmich
36
+ * Fix inconsistencies in `debug?` and `dry_run?` methods - <https://github.com/copiousfreetime/launchy/issues/63> - schmich
37
+ * Fix detection of missing *nix desktops - <https://github.com/copiousfreetime/launchy/issues/70>
38
+ * Fix running tests in bare Linux environment - <https://github.com/copiousfreetime/launchy/issues/67> - gioele
39
+ * Fix mistaking windows drive as uri schema - <https://github.com/copiousfreetime/launchy/issues/65>
40
+ * Attempt fixing windows `start` command oddities, again - <https://github.com/copiousfreetime/launchy/issues/62>
30
41
 
31
42
  ## Version 2.3.0 - 2013-04-11
32
43
 
@@ -34,39 +45,39 @@
34
45
 
35
46
  ## Version 2.2.0 - 2013-02-06
36
47
 
37
- * Change XFCE detection to not depend on grep <http://github.com/copiousfreetime/launchy/issues/52> - bogdan
38
- * Suppress forked process output <http://github.com/copiousfreetime/launchy/issues/51>
39
- * Display help/usage if no url is given <http://github.com/copiousfreetime/launchy/issues/54>
40
- * Detect the fluxbox environment <http://github.com/copiousfreetime/launchy/issues/53>
41
- * Automatically detect `http` url's if they are missing the `http://` <http://github.com/copiousfreetime/launchy/issues/55>
48
+ * Change XFCE detection to not depend on grep <https://github.com/copiousfreetime/launchy/issues/52> - bogdan
49
+ * Suppress forked process output <https://github.com/copiousfreetime/launchy/issues/51>
50
+ * Display help/usage if no url is given <https://github.com/copiousfreetime/launchy/issues/54>
51
+ * Detect the fluxbox environment <https://github.com/copiousfreetime/launchy/issues/53>
52
+ * Automatically detect `http` url's if they are missing the `http://` <https://github.com/copiousfreetime/launchy/issues/55>
42
53
  * Update to latest project management rake tasks
43
54
 
44
55
  ## Version 2.1.2 - 2012-08-06
45
56
 
46
- * Fix where HostOS would fail to convert to string on JRuby in 1.9 mode <http://github.com/copiousfreetime/launchy/issues/45>
57
+ * Fix where HostOS would fail to convert to string on JRuby in 1.9 mode <https://github.com/copiousfreetime/launchy/issues/45>
47
58
 
48
59
  ## Version 2.1.1 - 2012-07-28
49
60
 
50
- * Update addressable runtime dependency <http://github.com/copiousfreetime/launchy/issues/47>
61
+ * Update addressable runtime dependency <https://github.com/copiousfreetime/launchy/issues/47>
51
62
  * Bring minitest and ffi development dependencies up to date
52
63
 
53
64
  ## Version 2.1.0 - 2012-03-18
54
65
 
55
- * Fix raising exception when no browser program found <http://github.com/copiousfreetime/launchy/issues/42>
66
+ * Fix raising exception when no browser program found <https://github.com/copiousfreetime/launchy/issues/42>
56
67
  * Add `LAUNCHY_DRY_RUN` environment variable (Mariusz Pietrzyk / wijet)
57
68
  * Update dependencies
58
69
 
59
70
  ## Version 2.0.5 - 2011-07-24
60
71
 
61
- * Fix the case where `$BROWSER` is set and no *nix desktop was found <http://github.com/copiousfreetime/launchy/issues/33>
72
+ * Fix the case where `$BROWSER` is set and no *nix desktop was found <https://github.com/copiousfreetime/launchy/issues/33>
62
73
 
63
74
  ## Version 2.0.4 - 2011-07-23
64
75
 
65
- * Fix windows `start` commandline <http://github.com/copiousfreetime/launchy/issues/5>
66
- * Add capability to open local files with no file: scheme present <http://github.com/copiousfreetime/launchy/issues/29>
67
- * Added `rake how_to_contribute` task <http://github.com/copiousfreetime/launchy/issues/30>
68
- * Make better decisions on when to do shell escaping <http://github.com/copiousfreetime/launchy/issues/31>
69
- * Switch to Addressable::URI so UTF-8 urls may be parsed. <http://github.com/copiousfreetime/launchy/issues/32>
76
+ * Fix windows `start` commandline <https://github.com/copiousfreetime/launchy/issues/5>
77
+ * Add capability to open local files with no file: scheme present <https://github.com/copiousfreetime/launchy/issues/29>
78
+ * Added `rake how_to_contribute` task <https://github.com/copiousfreetime/launchy/issues/30>
79
+ * Make better decisions on when to do shell escaping <https://github.com/copiousfreetime/launchy/issues/31>
80
+ * Switch to Addressable::URI so UTF-8 urls may be parsed. <https://github.com/copiousfreetime/launchy/issues/32>
70
81
 
71
82
  ## Version 2.0.3 - 2011-07-17
72
83
 
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- ISC LICENSE - http://opensource.org/licenses/isc-license.txt
1
+ ISC LICENSE - https://opensource.org/licenses/isc-license.txt
2
2
 
3
3
  Copyright (c) 2007-2020 Jeremy Hinegardner
4
4
 
data/Manifest.txt CHANGED
@@ -10,16 +10,14 @@ 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
22
  spec/application_spec.rb
25
23
  spec/applications/browser_spec.rb
@@ -27,8 +25,6 @@ spec/cli_spec.rb
27
25
  spec/detect/host_os_family_spec.rb
28
26
  spec/detect/host_os_spec.rb
29
27
  spec/detect/nix_desktop_environment_spec.rb
30
- spec/detect/ruby_engine_spec.rb
31
- spec/detect/runner_spec.rb
32
28
  spec/launchy_spec.rb
33
29
  spec/mock_application.rb
34
30
  spec/spec_helper.rb
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # launchy
2
2
 
3
- [![Build Status](https://travis-ci.org/copiousfreetime/launchy.svg?branch=master)](https://travis-ci.org/copiousfreetime/launchy)
4
-
3
+ [![Build Status](https://copiousfreetime.semaphoreci.com/badges/launchy/branches/main.svg)](https://copiousfreetime.semaphoreci.com/projects/launchy)
5
4
 
6
5
  * [Homepage](https://github.com/copiousfreetime/launchy)
7
6
  * [Github Project](https://github.com/copiousfreetime/launchy)
@@ -27,14 +26,14 @@ testing environment, or via its API.
27
26
 
28
27
  ### Commandline
29
28
 
30
- % launchy http://www.ruby-lang.org/
29
+ % launchy https://www.ruby-lang.org/
31
30
 
32
31
  There are additional command line options, use `launchy --help` to see them.
33
32
 
34
33
  ### Using the `BROWSER` environment variable
35
34
 
36
35
  Launchy has a predefined set of common browsers on each platform that it
37
- attempts to use, and of course it is not exhaustive. As a fallbabck you can make
36
+ attempts to use, and of course it is not exhaustive. As a fallback you can make
38
37
  use of the somewhat standard `BROWSER` environment variable.
39
38
 
40
39
  `BROWSER` works in a similar same way to `PATH`. It is a colon (`:`) separated
@@ -43,10 +42,10 @@ you are attempting to open will be substituted there.
43
42
 
44
43
  As an example if you set `BROWSER=/usr/local/bin/firefox-bin -new-tab
45
44
  '%s':/usr/local/bin/google-chrome-stable` and you call
46
- `Launchy.open("http://www.ruby-lang.org/")` then Launchy will try, in order:
45
+ `Launchy.open("https://www.ruby-lang.org/")` then Launchy will try, in order:
47
46
 
48
- * `/usr/local/bin/firefox-bin -new-tab 'http://www.ruby-lang.org'`
49
- * `/usr/local/bin/google-chrome-stable http://www.ruby-lang.org`
47
+ * `/usr/local/bin/firefox-bin -new-tab 'https://www.ruby-lang.org'`
48
+ * `/usr/local/bin/google-chrome-stable https://www.ruby-lang.org`
50
49
 
51
50
  Additional links on the use of `BROWSER` as an environment variable.
52
51
 
@@ -83,7 +82,7 @@ in integration tests. For example:
83
82
 
84
83
  ### Public API
85
84
 
86
- In the vein of [Semantic Versioning](http://semver.org), this is the sole
85
+ In the vein of [Semantic Versioning](https://semver.org), this is the sole
87
86
  supported public API.
88
87
 
89
88
  Launchy.open( uri, options = {} ) { |exception| }
@@ -93,7 +92,6 @@ At the moment, the only available options are:
93
92
  :debug Turn on debugging output
94
93
  :application Explicitly state what application class is going to be used
95
94
  :host_os Explicitly state what host operating system to pretend to be
96
- :ruby_engine Explicitly state what ruby engine to pretend to be under
97
95
  :dry_run Do nothing and print the command that would be executed on $stdout
98
96
 
99
97
  If `Launchy.open` is invoked with a block, then no exception will be thrown, and
@@ -102,53 +100,18 @@ exception that was raised.
102
100
 
103
101
  ### An example of using the public API:
104
102
 
105
- Launchy.open( "http://www.ruby-lang.org" )
103
+ Launchy.open( "https://www.ruby-lang.org" )
106
104
 
107
105
  ### An example of using the public API and using the error block:
108
106
 
109
- uri = "http://www.ruby-lang.org"
107
+ uri = "https://www.ruby-lang.org"
110
108
  Launchy.open( uri ) do |exception|
111
109
  puts "Attempted to open #{uri} and failed because #{exception}"
112
110
  end
113
111
 
114
- ## UPGRADING from versions before 2.0.0
115
-
116
- The previously published version of Launchy before the 2.0.0 series was 0.4.0.
117
- There have been so many changes, and a mistaken tag at 1.0.0, that I have
118
- decided to bump all the way to 2.x.y.
119
-
120
- I have attempted to keep backward compatibility with the previous examples. The
121
- previous API examples of:
122
-
123
- Launchy::Browser.run("http://www.ruby-lang.org/")
124
-
125
- and
126
-
127
- Launchy::Browser.new.visit("http://www.ruby-lang.org/")
128
-
129
- will still work, and you will get a deprecation notice, along with the line
130
- of code you should probably update. For example, this is what would print out
131
- in the github gem if it was updated to use 2.0.x but not use the supported API.
132
-
133
- % gh home
134
- WARNING: You made a call to a deprecated Launchy API. This call should be changed to 'Launchy.open( uri )'
135
- WARNING: I think I was able to find the location that needs to be fixed. Please go look at:
136
- WARNING:
137
- WARNING: /Users/jeremy/.rvm/gems/ruby-1.8.7-p334/gems/github-0.6.2/lib/commands/helpers.rb:275:in `open'
138
- WARNING: helper :open do |url|
139
- WARNING: has_launchy? proc {
140
- WARNING: Launchy::Browser.new.visit url
141
- WARNING: }
142
- WARNING: end
143
- WARNING:
144
- WARNING: If this is not the case, please file a bug. Please file a bug at https://github.com/copiousfreetime/launchy/issues/new
145
-
146
- These deprecation notices will go away with version 3.0 and the only available
147
- API will be the documented one.
148
-
149
112
  ## ISC LICENSE
150
113
 
151
- http://opensource.org/licenses/isc-license.txt
114
+ https://opensource.org/licenses/isc-license.txt
152
115
 
153
116
  Copyright (c) 2007-2020 Jeremy Hinegardner
154
117
 
data/Rakefile CHANGED
@@ -4,15 +4,17 @@ load 'tasks/this.rb'
4
4
  This.name = "launchy"
5
5
  This.author = "Jeremy Hinegardner"
6
6
  This.email = "jeremy@copiousfreetime.org"
7
- This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
7
+ This.homepage = "https://github.com/copiousfreetime/#{ This.name }"
8
8
 
9
9
  This.ruby_gemspec do |spec|
10
- spec.add_dependency( 'addressable', '~> 2.7')
10
+ spec.add_dependency( 'addressable', '~> 2.8')
11
+ spec.add_dependency( 'childprocess', '~> 5.0')
11
12
 
12
13
  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' )
14
+ spec.add_development_dependency( 'minitest' , '~> 5.21' )
15
+ spec.add_development_dependency( 'minitest-junit' , '~> 1.0' )
16
+ spec.add_development_dependency( 'rdoc' , '~> 6.6' )
17
+ spec.add_development_dependency( 'simplecov', '~> 0.22' )
16
18
 
17
19
  spec.licenses = ['ISC']
18
20
 
@@ -24,8 +24,18 @@ module Launchy
24
24
  raise ApplicationNotFoundError, "No application found to handle '#{uri}'"
25
25
  end
26
26
 
27
+ # Find the application with the given name
27
28
  #
29
+ # returns the Class that has the given name
30
+ def for_name( name )
31
+ klass = find_child( :has_name?, name )
32
+ return klass if klass
33
+ raise ApplicationNotFoundError, "No application found named '#{name}'"
34
+ end
35
+
28
36
  # Find the given executable in the available paths
37
+ #
38
+ # returns the path to the executable or nil if not found
29
39
  def find_executable( bin, *paths )
30
40
  paths = Launchy.path.split( File::PATH_SEPARATOR ) if paths.empty?
31
41
  paths.each do |path|
@@ -38,16 +48,21 @@ module Launchy
38
48
  Launchy.log "#{self.name} : Unable to find `#{bin}' in #{paths.join(", ")}"
39
49
  return nil
40
50
  end
51
+
52
+ # Does this class have the given name-like string?
53
+ #
54
+ # returns true if the class has the given name
55
+ def has_name?( qname )
56
+ qname.to_s.downcase == self.name.split("::").last.downcase
57
+ end
41
58
  end
42
59
 
43
60
  attr_reader :host_os_family
44
- attr_reader :ruby_engine
45
61
  attr_reader :runner
46
62
 
47
63
  def initialize
48
64
  @host_os_family = Launchy::Detect::HostOsFamily.detect
49
- @ruby_engine = Launchy::Detect::RubyEngine.detect
50
- @runner = Launchy::Detect::Runner.detect
65
+ @runner = Launchy::Runner.new
51
66
  end
52
67
 
53
68
  def find_executable( bin, *paths )
@@ -64,12 +64,12 @@ class Launchy::Application
64
64
  end
65
65
 
66
66
  def cmd_and_args( uri, options = {} )
67
- cmd = browser_cmdline
67
+ cmd = browser_cmdline.to_s
68
68
  args = [ uri.to_s ]
69
69
  if cmd =~ /%s/ then
70
70
  cmd.gsub!( /%s/, args.shift )
71
71
  end
72
- return [cmd, args]
72
+ [cmd, args]
73
73
  end
74
74
 
75
75
  # final assembly of the command and do %s substitution
data/lib/launchy/cli.rb CHANGED
@@ -15,7 +15,7 @@ module Launchy
15
15
  op.separator ""
16
16
  op.separator "Launch Options:"
17
17
 
18
- op.on( "-a", "--application APPLICATION",
18
+ op.on( "-a", "--application APPLICATION",
19
19
  "Explicitly specify the application class to use in the launch") do |app|
20
20
  @options[:application] = app
21
21
  end
@@ -25,11 +25,6 @@ module Launchy
25
25
  @options[:debug] = true
26
26
  end
27
27
 
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
28
  op.on( "-n", "--dry-run", "Don't launchy, print the command to be executed on stdout" ) do |x|
34
29
  @options[:dry_run] = true
35
30
  end
@@ -20,7 +20,7 @@ module Launchy::Detect
20
20
  end
21
21
 
22
22
  def default_host_os
23
- ::RbConfig::CONFIG['host_os']
23
+ ::RbConfig::CONFIG['host_os'].downcase
24
24
  end
25
25
 
26
26
  def override_host_os
@@ -42,7 +42,7 @@ module Launchy::Detect
42
42
  #
43
43
  class Windows < HostOsFamily
44
44
  def self.matching_regex
45
- /(mingw|mswin|windows)/i
45
+ /(mingw|mswin|msys|windows)/i
46
46
  end
47
47
  def app_list( app ) app.windows_app_list; end
48
48
  end
@@ -56,7 +56,7 @@ module Launchy::Detect
56
56
 
57
57
  class Nix < HostOsFamily
58
58
  def self.matching_regex
59
- /(linux|bsd|aix|solaris)/i
59
+ /(linux|bsd|aix|solaris|sunos|dragonfly)/i
60
60
  end
61
61
  def app_list( app ) app.nix_app_list; end
62
62
  end
@@ -5,6 +5,4 @@ end
5
5
 
6
6
  require 'launchy/detect/host_os'
7
7
  require 'launchy/detect/host_os_family'
8
- require 'launchy/detect/ruby_engine'
9
8
  require 'launchy/detect/nix_desktop_environment'
10
- require 'launchy/detect/runner'
@@ -0,0 +1,46 @@
1
+ require 'childprocess'
2
+ module Launchy
3
+ class Runner
4
+ def run( cmd, *args )
5
+ raise Launchy::CommandNotFoundError, "No command found to run with args '#{args.join(' ')}'. If this is unexpected, #{Launchy.bug_report_message}" unless cmd
6
+ if Launchy.dry_run? then
7
+ $stdout.puts dry_run( cmd, *args )
8
+ else
9
+ wet_run( cmd, *args )
10
+ end
11
+ end
12
+
13
+ def wet_run( cmd, *args )
14
+ argv = [ cmd, *args ].flatten
15
+ Launchy.log "ChildProcess: argv => #{argv.inspect}"
16
+ process = ChildProcess.build( *argv )
17
+
18
+ process.io.inherit!
19
+ process.leader = true
20
+ process.detach = true
21
+ process.start
22
+ end
23
+
24
+ def dry_run( cmd, *args )
25
+ shell_commands(cmd, args).join(" ")
26
+ end
27
+
28
+ # cut it down to just the shell commands that will be passed to exec or
29
+ # posix_spawn. The cmd argument is split according to shell rules and the
30
+ # args are not escaped because the whole set is passed to system as *args
31
+ # and in that case system shell escaping rules are not done.
32
+ #
33
+ def shell_commands( cmd, args )
34
+ cmdline = [ cmd.to_s.shellsplit ]
35
+ cmdline << args.flatten.collect{ |a| a.to_s }
36
+ return commandline_normalize( cmdline )
37
+ end
38
+
39
+ def commandline_normalize( cmdline )
40
+ c = cmdline.flatten!
41
+ c = c.find_all { |a| (not a.nil?) and ( a.size > 0 ) }
42
+ Launchy.log "commandline_normalized => #{c.join(' ')}"
43
+ return c
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  module Launchy
2
- VERSION = "2.5.0"
2
+ VERSION = "3.0.0"
3
3
 
4
4
  module Version
5
5
 
data/lib/launchy.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'addressable/uri'
2
+ require 'shellwords'
3
+ require 'stringio'
2
4
 
3
5
  #
4
6
  # The entry point into Launchy. This is the sole supported public API.
@@ -11,7 +13,6 @@ require 'addressable/uri'
11
13
  # :application Explicitly state what application class is going to be used.
12
14
  # This must be a child class of Launchy::Application
13
15
  # :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
16
  # :dry_run Do nothing and print the command that would be executed on $stdout
16
17
  #
17
18
  # Other options may be used, and those will be passed directly to the
@@ -26,7 +27,14 @@ module Launchy
26
27
  def open(uri_s, options = {}, &error_block )
27
28
  leftover = extract_global_options( options )
28
29
  uri = string_to_uri( uri_s )
29
- app = app_for_uri( uri )
30
+ if name = options[:application] then
31
+ app = app_for_name( name )
32
+ end
33
+
34
+ if app.nil? then
35
+ app = app_for_uri( uri )
36
+ end
37
+
30
38
  app.new.open( uri, leftover )
31
39
  rescue Launchy::Error => le
32
40
  raise le
@@ -34,7 +42,7 @@ module Launchy
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
45
+ if $! && block_given? then
38
46
  yield $!
39
47
  return # explicitly swallow the errors
40
48
  end
@@ -44,6 +52,12 @@ module Launchy
44
52
  Launchy::Application.handling( uri )
45
53
  end
46
54
 
55
+ def app_for_name( name )
56
+ Launchy::Application.for_name( name )
57
+ rescue Launchy::ApplicationNotFoundError
58
+ nil
59
+ end
60
+
47
61
  def app_for_uri_string( s )
48
62
  app_for_uri( string_to_uri( s ) )
49
63
  end
@@ -64,7 +78,6 @@ module Launchy
64
78
  Launchy.debug = false
65
79
  Launchy.application = nil
66
80
  Launchy.host_os = nil
67
- Launchy.ruby_engine = nil
68
81
  Launchy.dry_run = false
69
82
  Launchy.path = ENV['PATH']
70
83
  end
@@ -74,7 +87,6 @@ module Launchy
74
87
  Launchy.debug = leftover.delete( :debug ) || ENV['LAUNCHY_DEBUG']
75
88
  Launchy.application = leftover.delete( :application ) || ENV['LAUNCHY_APPLICATION']
76
89
  Launchy.host_os = leftover.delete( :host_os ) || ENV['LAUNCHY_HOST_OS']
77
- Launchy.ruby_engine = leftover.delete( :ruby_engine ) || ENV['LAUNCHY_RUBY_ENGINE']
78
90
  Launchy.dry_run = leftover.delete( :dry_run ) || ENV['LAUNCHY_DRY_RUN']
79
91
  end
80
92
 
@@ -104,14 +116,6 @@ module Launchy
104
116
  @host_os || ENV['LAUNCHY_HOST_OS']
105
117
  end
106
118
 
107
- def ruby_engine=( ruby_engine )
108
- @ruby_engine = ruby_engine
109
- end
110
-
111
- def ruby_engine
112
- @ruby_engine || ENV['LAUNCHY_RUBY_ENGINE']
113
- end
114
-
115
119
  def dry_run=( dry_run )
116
120
  @dry_run = to_bool( dry_run )
117
121
  end
@@ -160,4 +164,4 @@ require 'launchy/descendant_tracker'
160
164
  require 'launchy/error'
161
165
  require 'launchy/application'
162
166
  require 'launchy/detect'
163
- require 'launchy/deprecated'
167
+ require 'launchy/runner'
@@ -13,22 +13,17 @@ describe Launchy::Application::Browser do
13
13
  ENV.delete( 'BROWSER' )
14
14
  end
15
15
 
16
- { 'windows' => 'start "launchy" /b' ,
17
- 'darwin' => [ '/usr/bin/open', '/bin/open' ], # because running tests on linux
18
- 'cygwin' => 'cmd /C start "launchy" /b',
19
- 'linux' => [nil, "xdg-open"], # because running tests on linux
20
- }.each do |host_os, expected|
21
- it "when host_os is '#{host_os}' the appropriate 'app_list' method is called" do
16
+ { 'windows' => 'windows_app_list',
17
+ 'darwin' => 'darwin_app_list',
18
+ 'cygwin' => 'cygwin_app_list',
19
+ 'linux' => 'nix_app_list',
20
+ }.each do |host_os, called_method|
21
+ it "when host_os is '#{host_os}' the '#{called_method}' method is called" do
22
22
  Launchy.host_os = host_os
23
23
  browser = Launchy::Application::Browser.new
24
-
25
- item = browser.app_list.first
26
- item = item.to_s if item.kind_of?(::Launchy::Argv)
27
- case expected
28
- when Array
29
- _(expected).must_include item
30
- when String
31
- _(item).must_equal expected
24
+ browser.stub(called_method, [:called_me]) do
25
+ item = browser.app_list.first
26
+ _(item).must_equal :called_me
32
27
  end
33
28
  end
34
29
  end
data/spec/cli_spec.rb CHANGED
@@ -45,29 +45,28 @@ describe Launchy::Cli do
45
45
 
46
46
  it "leaves the url on argv after parsing" do
47
47
  l = Launchy::Cli.new
48
- argv = %w[ --debug --dry-run http://github.com/copiousfreetime/launchy ]
48
+ argv = %w[ --debug --dry-run https://github.com/copiousfreetime/launchy ]
49
49
  l.parse( argv , {} )
50
50
  _(argv.size).must_equal 1
51
- _(argv[0]).must_equal "http://github.com/copiousfreetime/launchy"
51
+ _(argv[0]).must_equal "https://github.com/copiousfreetime/launchy"
52
52
  end
53
53
 
54
54
  it "prints the command on stdout when using --dry-run" do
55
- argv = %w[ --debug --dry-run http://github.com/copiousfreetime/launchy ]
55
+ argv = %w[ --debug --dry-run https://github.com/copiousfreetime/launchy ]
56
56
  Launchy::Cli.new.good_run( argv, {} )
57
57
  _($stdout.string).must_match %r[github.com]
58
58
  end
59
59
 
60
60
  {
61
61
  '--application' => [ :application, 'Browser'],
62
- '--engine' => [ :ruby_engine, 'rbx'],
63
62
  '--host-os' => [ :host_os, 'cygwin'] }.each_pair do |opt, val|
64
63
  it "the commandline option #{opt} sets the program option #{val[0]}" do
65
- argv = [ opt, val[1], "http://github.com/copiousfreetime/launchy" ]
64
+ argv = [ opt, val[1], "https://github.com/copiousfreetime/launchy" ]
66
65
  l = Launchy::Cli.new
67
66
  rc = l.parse( argv, {} )
68
67
  _(rc).must_equal true
69
68
  _(argv.size).must_equal 1
70
- _(argv[0]).must_equal "http://github.com/copiousfreetime/launchy"
69
+ _(argv[0]).must_equal "https://github.com/copiousfreetime/launchy"
71
70
  _(l.options[val[0]]).must_equal val[1]
72
71
  end
73
72
  end