Class: Envo::Cli::InstallerWinCmd
- Inherits:
-
Object
- Object
- Envo::Cli::InstallerWinCmd
- Defined in:
- lib/envo/cli/installer_win_cmd.rb
Constant Summary collapse
- ENVO_RUN_CMD =
"envo_run"- INSTALL_FILE =
"envo.bat"- SOURCE_FILE =
"envo.bat"- USAGE =
"usage: envo-install [u] [--path <path>]\n"
Instance Method Summary collapse
- #each_path_dir ⇒ Object
- #run(argv) ⇒ Object
- #try_install(path) ⇒ Object
- #try_uninstall(path) ⇒ Object
Instance Method Details
#each_path_dir ⇒ Object
4 5 6 |
# File 'lib/envo/cli/installer_win_cmd.rb', line 4 def each_path_dir ENV["Path"].split(';').each { |p| yield p } end |
#run(argv) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/envo/cli/installer_win_cmd.rb', line 55 def run(argv) if argv.empty? try_install(nil) return 0 end if argv[0] == '--help' || argv[0] == '-?' puts "installer for envo v#{Envo::VERSION} #{Envo::VERSION_TYPE}" puts USAGE puts puts ' u - uninstall envo' puts ' --path <path> - install to or uninstall form a specified directory' return 0 end if argv[0] == 'u' @uninstalling = true argv.shift end path = nil if !argv.empty? arg = argv.shift if arg != '--path' STDERR.puts "Unknown argument #{arg}" STDERR.puts USAGE return 1 end if argv.empty? STDERR.puts "Missing path" STDERR.puts USAGE return 1 end path = argv.shift end @uninstalling ? try_uninstall(path) : try_install(path) return 0 end |
#try_install(path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/envo/cli/installer_win_cmd.rb', line 12 def try_install(path) if !path each_path_dir do |dir| if File.file?(File.join(dir, ENVO_RUN_CMD)) path = dir break end end raise Error.new("Couldn't find a good place to install envo. Please use '--path <path>' to provide one") if !path end raise Error.new("'#{path}' is not an existing directory") if !File.directory?(path) src = File.read(File.join(__dir__, SOURCE_FILE)) target = File.join(path, INSTALL_FILE) File.open(target, 'w') do |f| f.puts ":: envo #{VERSION}" f.write(src) end puts "Successfully installed #{target}" end |
#try_uninstall(path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/envo/cli/installer_win_cmd.rb', line 33 def try_uninstall(path) if path file = File.join(path, INSTALL_FILE) raise Error.new "Couldn't find an existing envo installation in #{path}" if !File.file?(file) File.delete(file) puts "Sucessfully uninstalled #{file}" return else each_path_dir do |dir| file = File.join(dir, INSTALL_FILE) next if !File.file?(file) File.delete(file) puts "Sucessfully uninstalled #{file}" return end end raise Error.new "Couldn't find an existing envo installation to uninstall" end |