Class: Commanding::Uninstall

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) ⇒ Uninstall

Returns a new instance of Uninstall.



82
83
84
85
# File 'lib/commanding.rb', line 82

def initialize(argv)
  @installed_command_name = argv.shift_argument
  super
end

Instance Method Details

#runObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/commanding.rb', line 93

def run
    if File.exists?(shell_config_path)
      file = File.open(shell_config_path, 'r+')
      file.each do |line|
        if line.start_with?("alias " + @installed_command_name)
          file.seek(-line.length, IO::SEEK_CUR)
          file.write(' ' * (line.length - 1))
          file.write("\n")
        end
      end

      file.close
    else
      help! 'No #{@installed_command_name}, nothing to remove.'
    end

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

#validate!Object



87
88
89
90
91
# File 'lib/commanding.rb', line 87

def validate!
super
help! 'Please make sure installed_command_name needed!' unless @installed_command_name

end