Class: Hoof::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/hoof/cli.rb

Instance Method Summary collapse

Instance Method Details

#init(name = nil) ⇒ Object



33
34
35
36
37
# File 'lib/hoof/cli.rb', line 33

def init name = nil
  name ||= File.basename Dir.getwd
  create_link File.expand_path(File.join("~/.hoof", name)), Dir.getwd
  append_to_file 'Gemfile', "\ngem 'unicorn'"
end

#install(target = '') ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/hoof/cli.rb', line 45

def install target = ''
  ext = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'ext'))
  puts "Successfully installed NSS library" if system "cd #{ext} && make && sudo make install"
  puts "Successfully added iptables rules" if system <<-E
    sudo iptables -t nat -I OUTPUT --source 0/0 --destination 127.0.0.1 -p tcp --dport 80 -j REDIRECT --to-ports #{Hoof.http_port} &&
    sudo iptables -t nat -I OUTPUT --source 0/0 --destination 127.0.0.1 -p tcp --dport 443 -j REDIRECT --to-ports #{Hoof.https_port}
  E
end

#restartObject



22
23
24
# File 'lib/hoof/cli.rb', line 22

def restart
  daemon 'restart'
end

#startObject



12
13
14
# File 'lib/hoof/cli.rb', line 12

def start
  daemon 'start'
end

#statusObject



40
41
42
# File 'lib/hoof/cli.rb', line 40

def status
  control 'status'
end

#stopObject



17
18
19
# File 'lib/hoof/cli.rb', line 17

def stop
  daemon 'stop'
end

#uninstall(target = '') ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/hoof/cli.rb', line 55

def uninstall target = ''
  ext = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'ext'))
  puts "Successfully uninstalled NSS library" if system "cd #{ext} && sudo make uninstall && make clean"
  puts "Successfully removed iptables rules" if system <<-E
    sudo iptables -t nat -D OUTPUT --source 0/0 --destination 127.0.0.1 -p tcp --dport 80 -j REDIRECT --to-ports #{Hoof.http_port} &&
    sudo iptables -t nat -D OUTPUT --source 0/0 --destination 127.0.0.1 -p tcp --dport 443 -j REDIRECT --to-ports #{Hoof.https_port}
  E
end