Class: Commanding::Install

Inherits:
Commanding
  • Object
show all
Defined in:
lib/commanding.rb

Instance Method Summary collapse

Methods inherited from Commanding

#shell_config_name, #shell_config_path

Constructor Details

#initialize(argv) ⇒ Install

Returns a new instance of Install.



38
39
40
41
42
# File 'lib/commanding.rb', line 38

def initialize(argv)
  @new_command_name = argv.shift_argument
  @shell_relative_path = argv.shift_argument
  super
end

Instance Method Details

#runObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/commanding.rb', line 51

def run
  File.chmod(777, shell_path) unless File.executable?(shell_path)

  file = nil
  if File.exists?(shell_config_path)
    file = File.open(shell_config_path, 'a+')
  else
    file = File.new(shell_config_path, 'w')
  end
  file.write("\n")
  file.write("alias #{@new_command_name}=\"#{@shell_path}\"")
  file.close

  `source #{"~/" + shell_config_name}`
end

#shell_pathObject



67
68
69
70
71
72
73
# File 'lib/commanding.rb', line 67

def shell_path
  if !@shell_path
    expanded_relative_path = File.expand_path(@shell_relative_path)
    @shell_path = File.expand_path(expanded_relative_path, Dir.pwd)
  end
  @shell_path
end

#validate!Object



44
45
46
47
48
49
# File 'lib/commanding.rb', line 44

def validate!
  super
  help! 'Please make sure new_command_name needed!' unless @new_command_name
  help! 'A shell_file_path is required.' unless @shell_relative_path
  help! "The #{@shell_relative_path} is invalid!!" unless File.exists?(shell_path)
end