launchy 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d637a77afa69826953a3226c55fc20334c6fa90e268912bcf9a208bc9b448e2
4
- data.tar.gz: 2f5ff5e1401319e3a97655848f4f61b9bb33e786cd1b22b76aa20a7729e0b885
3
+ metadata.gz: 7001cb9d1f872b482b6356d68289a022fdc12d57a128b1efe264e598d794d2a8
4
+ data.tar.gz: 0a76868c2abfc6da776b6d62c2d5be2ef1e872a37ffc244207030653aa16da9d
5
5
  SHA512:
6
- metadata.gz: bb02ca4bd30a8394ca2a6c8e86518eb4f403d5b56c574f7730d1581a19ca686c94a001c641a09620b799b620f9d8e6be54ad39c27bb980e67268d01f68d8eae1
7
- data.tar.gz: ba3bc128ef33d39c87b50e187ca71e0f39a2382cdf3513122ec1a108b71a55d2e2a8e0f81f138a27b8c9b1f74b8df183fe0b626d9718236efb3cb6a653fd1e62
6
+ metadata.gz: 34bb32f9dcedf678f7d22ac4dbb3febfb565609738f4150efb0000ca4b1867bdadd12b76cb1441c49d25015cfa43a9a651aa5f2a5bd2929468bb63822f4bf741
7
+ data.tar.gz: 462cce3f0d4c1239e16a3667428d0e54aedb7b5d0bcad9762ae8c3e65020882c45da1614882893af16b6db2dcf467782abc62a503d3d8ed6818c288aba6fdaea
data/HISTORY.md CHANGED
@@ -1,7 +1,14 @@
1
1
  # Launchy Changelog
2
+ ## Version 3.0.1 - 2024-05-03
3
+ * Added rubocop and fix all the warnings
4
+ * Fix rubygem changelog_uri - Spone
5
+ * Update the semaphore flow
6
+ * Update the ruby test matrix
7
+ * Change to Gemfile for development
8
+
2
9
  ## Version 3.0.0 - 2024-03-03
3
10
  * Remove unused `deprecated.rb` file - <https://github.com/copiousfreetime/launchy/issues/148>
4
- * Update supported ruby versin to be 3.x
11
+ * Update supported ruby version to be 3.x
5
12
  * use the `:application` parameter - <https://github.com/copiousfreetime/launchy/issues/121>
6
13
  * adjust the semaphore configuration to allow better caching
7
14
  * replace the homegrown process runner with [`childprocess`](https://rubygems.org/gems/childprocess)
data/Manifest.txt CHANGED
@@ -1,10 +1,10 @@
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
@@ -19,16 +19,3 @@ lib/launchy/error.rb
19
19
  lib/launchy/os_family.rb
20
20
  lib/launchy/runner.rb
21
21
  lib/launchy/version.rb
22
- spec/application_spec.rb
23
- spec/applications/browser_spec.rb
24
- spec/cli_spec.rb
25
- spec/detect/host_os_family_spec.rb
26
- spec/detect/host_os_spec.rb
27
- spec/detect/nix_desktop_environment_spec.rb
28
- spec/launchy_spec.rb
29
- spec/mock_application.rb
30
- spec/spec_helper.rb
31
- spec/tattle-host-os.yaml
32
- spec/version_spec.rb
33
- tasks/default.rake
34
- tasks/this.rb
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,32 @@
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.0.1 ruby lib
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "launchy".freeze
8
+ s.version = "3.0.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 = "2024-05-03"
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.5.9".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
+ 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,60 +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
 
27
30
  # Find the application with the given name
28
31
  #
29
32
  # returns the Class that has the given name
30
- def for_name( name )
31
- klass = find_child( :has_name?, name )
33
+ def for_name(name)
34
+ klass = find_child(:has_name?, name)
32
35
  return klass if klass
36
+
33
37
  raise ApplicationNotFoundError, "No application found named '#{name}'"
34
38
  end
35
39
 
36
40
  # Find the given executable in the available paths
37
41
  #
38
42
  # returns the path to the executable or nil if not found
39
- def find_executable( bin, *paths )
40
- paths = Launchy.path.split( File::PATH_SEPARATOR ) if paths.empty?
43
+ def find_executable(bin, *paths)
44
+ paths = Launchy.path.split(File::PATH_SEPARATOR) if paths.empty?
41
45
  paths.each do |path|
42
- file = File.join( path, bin )
43
- if File.executable?( file ) then
44
- 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}"
45
49
  return file
46
50
  end
47
51
  end
48
- Launchy.log "#{self.name} : Unable to find `#{bin}' in #{paths.join(", ")}"
49
- return nil
52
+ Launchy.log "#{name} : Unable to find `#{bin}' in #{paths.join(', ')}"
53
+ nil
50
54
  end
51
55
 
52
56
  # Does this class have the given name-like string?
53
57
  #
54
58
  # returns true if the class has the given name
55
- def has_name?( qname )
56
- qname.to_s.downcase == self.name.split("::").last.downcase
59
+ def has_name?(qname)
60
+ qname.to_s.downcase == name.split("::").last.downcase
57
61
  end
58
62
  end
59
63
 
60
- attr_reader :host_os_family
61
- attr_reader :runner
64
+ attr_reader :host_os_family, :runner
62
65
 
63
66
  def initialize
64
67
  @host_os_family = Launchy::Detect::HostOsFamily.detect
65
68
  @runner = Launchy::Runner.new
66
69
  end
67
70
 
68
- def find_executable( bin, *paths )
69
- Application.find_executable( bin, *paths )
71
+ def find_executable(bin, *paths)
72
+ Application.find_executable(bin, *paths)
70
73
  end
71
74
 
72
- def run( cmd, *args )
73
- runner.run( cmd, *args )
75
+ def run(cmd, *args)
76
+ runner.run(cmd, *args)
74
77
  end
75
78
  end
76
79
  end
77
- require 'launchy/applications/browser'
80
+ require "launchy/applications/browser"
@@ -1,82 +1,87 @@
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
+ def windows_app_list
20
+ ['start "launchy" /b']
21
+ end
27
22
 
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
23
+ def cygwin_app_list
24
+ ['cmd /C start "launchy" /b']
25
+ end
33
26
 
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
27
+ # hardcode this to open?
28
+ def darwin_app_list
29
+ [find_executable("open")]
30
+ end
39
31
 
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
32
+ def nix_app_list
33
+ nix_de = Launchy::Detect::NixDesktopEnvironment.detect
34
+ list = nix_de.browsers
35
+ list.find_all(&:valid?)
36
+ end
47
37
 
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}"
38
+ # use a call back mechanism to get the right app_list that is decided by the
39
+ # host_os_family class.
40
+ def app_list
41
+ host_os_family.app_list(self)
52
42
  end
53
- app_list.each do |p|
54
- Launchy.log "#{self.class.name} : possibility from app_list : #{p}"
43
+
44
+ def browser_env
45
+ return [] unless ENV["BROWSER"]
46
+
47
+ browser_env = ENV["BROWSER"].split(File::PATH_SEPARATOR)
48
+ browser_env.flatten!
49
+ browser_env.delete_if { |b| b.nil? || b.strip.empty? }
50
+ browser_env
55
51
  end
56
52
 
57
- possibilities = (browser_env + app_list).flatten
53
+ # Get the full commandline of what we are going to add the uri to
54
+ def browser_cmdline
55
+ browser_env.each do |p|
56
+ Launchy.log "#{self.class.name} : possibility from BROWSER environment variable : #{p}"
57
+ end
58
+ app_list.each do |p|
59
+ Launchy.log "#{self.class.name} : possibility from app_list : #{p}"
60
+ end
61
+
62
+ possibilities = (browser_env + app_list).flatten
58
63
 
59
- if browser = possibilities.shift then
60
- Launchy.log "#{self.class.name} : Using browser value '#{browser}'"
61
- return browser
64
+ if (browser = possibilities.shift)
65
+ Launchy.log "#{self.class.name} : Using browser value '#{browser}'"
66
+ return browser
67
+ end
68
+ raise Launchy::CommandNotFoundError,
69
+ "Unable to find a browser command. If this is unexpected, #{Launchy.bug_report_message}"
62
70
  end
63
- raise Launchy::CommandNotFoundError, "Unable to find a browser command. If this is unexpected, #{Launchy.bug_report_message}"
64
- end
65
71
 
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 )
72
+ def cmd_and_args(uri, _options = {})
73
+ cmd = browser_cmdline.to_s
74
+ args = [uri.to_s]
75
+ cmd.gsub!("%s", args.shift) if cmd.include?("%s")
76
+ [cmd, args]
71
77
  end
72
- [cmd, args]
73
- end
74
78
 
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 )
79
+ # final assembly of the command and do %s substitution
80
+ # http://www.catb.org/~esr/BROWSER/index.html
81
+ def open(uri, options = {})
82
+ cmd, args = cmd_and_args(uri, options)
83
+ run(cmd, args)
84
+ end
80
85
  end
81
86
  end
82
87
  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,70 +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( "-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|
29
33
  @options[:dry_run] = true
30
34
  end
31
35
 
32
- op.on( "-o", "--host-os HOST_OS",
33
- "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|
34
38
  @options[:host_os] = os
35
39
  end
36
40
 
37
-
38
41
  op.separator ""
39
42
  op.separator "Standard Options:"
40
43
 
41
- op.on( "-h", "--help", "Print this message.") do |h|
44
+ op.on("-h", "--help", "Print this message.") do |_h|
42
45
  $stdout.puts op.to_s
43
46
  exit 0
44
47
  end
45
48
 
46
- op.on( "-v", "--version", "Output the version of Launchy") do |v|
49
+ op.on("-v", "--version", "Output the version of Launchy") do |_v|
47
50
  $stdout.puts "Launchy version #{Launchy::VERSION}"
48
51
  exit 0
49
52
  end
50
-
51
53
  end
52
54
  end
53
55
 
54
- def parse( argv, env )
55
- parser.parse!( argv )
56
- return true
57
- rescue ::OptionParser::ParseError => pe
58
- error_output( pe )
56
+ def parse(argv, _env)
57
+ parser.parse!(argv)
58
+ true
59
+ rescue ::OptionParser::ParseError => e
60
+ error_output(e)
59
61
  end
60
62
 
61
- def good_run( argv, env )
62
- if parse( argv, env ) then
63
- Launchy.open( argv.shift, options ) { |e| error_output( e ) }
64
- return true
65
- else
66
- return false
67
- 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
68
68
  end
69
69
 
70
- def error_output( error )
70
+ def error_output(error)
71
71
  $stderr.puts "ERROR: #{error}"
72
72
  Launchy.log "ERROR: #{error}"
73
73
  error.backtrace.each do |bt|
74
74
  Launchy.log bt
75
75
  end
76
76
  $stderr.puts "Try `#{parser.program_name} --help' for more information."
77
- return false
77
+ false
78
78
  end
79
79
 
80
- def run( argv = ARGV, env = ENV )
81
- exit 1 unless good_run( argv, env )
80
+ def run(argv = ARGV, env = ENV)
81
+ exit 1 unless good_run(argv, env)
82
82
  end
83
83
  end
84
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
@@ -1,32 +1,35 @@
1
- require 'rbconfig'
1
+ # frozen_string_literal: true
2
2
 
3
- module Launchy::Detect
4
- class HostOs
3
+ require "rbconfig"
5
4
 
6
- attr_reader :host_os
7
- alias to_s host_os
8
- alias to_str host_os
5
+ module Launchy
6
+ module Detect
7
+ # Internal: Determine the host operating system that Launchy is running on
8
+ #
9
+ class HostOs
10
+ attr_reader :host_os
11
+ alias to_s host_os
12
+ alias to_str host_os
9
13
 
10
- def initialize( host_os = nil )
11
- @host_os = host_os
14
+ def initialize(host_os = nil)
15
+ @host_os = host_os
12
16
 
13
- if not @host_os then
14
- if @host_os = override_host_os then
17
+ return if @host_os
18
+
19
+ if (@host_os = override_host_os)
15
20
  Launchy.log "Using LAUNCHY_HOST_OS override value of '#{Launchy.host_os}'"
16
21
  else
17
22
  @host_os = default_host_os
18
23
  end
19
24
  end
20
- end
21
25
 
22
- def default_host_os
23
- ::RbConfig::CONFIG['host_os'].downcase
24
- end
26
+ def default_host_os
27
+ ::RbConfig::CONFIG["host_os"].downcase
28
+ end
25
29
 
26
- def override_host_os
27
- Launchy.host_os
30
+ def override_host_os
31
+ Launchy.host_os
32
+ end
28
33
  end
29
-
30
34
  end
31
-
32
35
  end