Class: InstallCommand

Inherits:
Command show all
Includes:
Rcli::Installation
Defined in:
lib/commands/install.rb

Instance Attribute Summary

Attributes inherited from Command

#description

Instance Method Summary collapse

Methods included from Rcli::Installation

#_installed_rcli_base?

Methods inherited from Command

#after_init, #before_init, default_cmd, describe, description, get_allowed_commands, #help, #initialize, load, load_all, #run, show_use, usage

Constructor Details

This class inherits a constructor from Command

Instance Method Details

#mainObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
# File 'lib/commands/install.rb', line 9

def main()
  
  if $verbose
    print "params : "
    pp @params
  end
    
  if _installed_rcli_base? && @params[:args].length > 0
    if @params[:args].length != 2
      puts "ERROR: Incorrect syntax. Please use 'rcli install [script] [alias]'"
      exit
    end
    unless File.exists? @params[:args][0]
      puts "ERROR: The filename provided does not exist. Please type 'rcli install help' for proper usage."
    end
    unless File.executable_real? @params[:args][0]
      puts "ERROR: The script you're trying to install is not executable. Please type 'rcli install help' for proper usage."
    end
    if File.exists? Rcli::RCLI_DOTFOLDER + DS + 'bin' + DS + @params[:args][1]
      puts "ERROR: The install name for that script is already taken"
      exit
    end
          
    unless FileUtils.ln_s(File.expand_path(@params[:args][0]),Rcli::RCLI_DOTFOLDER + DS + 'bin' + DS + @params[:args][1])
      puts "ERROR: There was a problem installing " + @params[:args][1]
      exit
    end
    
    unless File.open(File.expand_path(Rcli::RCLI_DOTFOLDER + DS + 'app_info' + DS + @params[:args][1] + '.yml'),'w') { |f|
        f << 'application_root: ' + File.dirname(File.expand_path(@params[:args][0])) + "\n"
        f << 'executable: ' + File.basename(File.expand_path(@params[:args][0]))
      }
      puts "ERROR: There was a problem installing " + @params[:args][1]
      FileUtils.rm(File.expand_path(@params[:args][0]),Rcli::RCLI_DOTFOLDER + DS + 'bin' + DS + @params[:args][1])
      exit
    end
      
  elsif @params[:args].length > 0 && !_installed_rcli_base?
    puts "You haven't installed the rcli base yet. Please run 'rcli install' first."
  elsif _installed_rcli_base?
    puts "rcli base already installed"
  else
    if _install_rcli_base
      puts "rcli successfully installed"
    else
      puts "ERROR"
    end
  end
end