Module: Sqlpkg::Commands

Defined in:
lib/sqlpkg/commands.rb

Defined Under Namespace

Classes: DirectoryNotFoundException, ExecutableNotFoundException, UnsupportedPlatformException

Constant Summary collapse

DEFAULT_DIR =
File.expand_path(File.join(__dir__, "..", "..", "exe"))
GEM_NAME =
"sqlpkg"

Class Method Summary collapse

Class Method Details

.executable(exe_path: DEFAULT_DIR) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
# File 'lib/sqlpkg/commands.rb', line 24

def self.executable(exe_path: DEFAULT_DIR)
  sqlpkg_install_dir = ENV["SQLPKG_INSTALL_DIR"]
  if sqlpkg_install_dir
    if File.directory?(sqlpkg_install_dir)
      warn "NOTE: using SQLPKG_INSTALL_DIR to find sqlpkg executable: #{sqlpkg_install_dir}"
      exe_path = sqlpkg_install_dir
      exe_file = File.expand_path(File.join(sqlpkg_install_dir, "sqlpkg"))
    else
      raise DirectoryNotFoundException, "        SQLPKG_INSTALL_DIR is set to \#{sqlpkg_install_dir}, but that directory does not exist.\n      MESSAGE\n    end\n  else\n    if Sqlpkg::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), GEM_NAME) }\n      raise UnsupportedPlatformException, <<~MESSAGE\n        sqlpkg-ruby does not support the \#{platform} platform\n        Please install sqlpkg following instructions at https://github.com/nalgeon/sqlpkg-cli#download-and-install-preferred-method\n      MESSAGE\n    end\n\n    exe_file = Dir.glob(File.expand_path(File.join(exe_path, \"*\", \"sqlpkg\"))).find do |f|\n      Gem::Platform.match_gem?(Gem::Platform.new(File.basename(File.dirname(f))), GEM_NAME)\n    end\n  end\n\n  if exe_file.nil? || !File.exist?(exe_file)\n    raise ExecutableNotFoundException, <<~MESSAGE\n      Cannot find the sqlpkg executable for \#{platform} in \#{exe_path}\n\n      If you're using bundler, please make sure you're on the latest bundler version:\n\n          gem install bundler\n          bundle update --bundler\n\n      Then make sure your lock file includes this platform by running:\n\n          bundle lock --add-platform \#{platform}\n          bundle install\n\n      See `bundle lock --help` output for details.\n\n      If you're still seeing this message after taking those steps, try running\n      `bundle config` and ensure `force_ruby_platform` isn't set to `true`. See\n      https://github.com/fractaledmind/sqlpkg-ruby#check-bundle_force_ruby_platform\n      for more details.\n    MESSAGE\n  end\n\n  exe_file\nend\n"

.platformObject



20
21
22
# File 'lib/sqlpkg/commands.rb', line 20

def self.platform
  [:cpu, :os].map { |m| Gem::Platform.local.send(m) }.join("-")
end