Class: Ec2ssh::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/ec2ssh/cli.rb

Instance Method Summary collapse

Instance Method Details

#initObject



13
14
15
16
17
18
# File 'lib/ec2ssh/cli.rb', line 13

def init
  command = make_command :init
  command.run
rescue MarkAlreadyExists
  red "Marker already exists in #{command.ssh_config_path}"
end

#removeObject



35
36
37
38
39
40
41
42
# File 'lib/ec2ssh/cli.rb', line 35

def remove
  check_dotfile_existence
  command = make_command :remove
  command.run
  green "Removed mark from #{command.ssh_config_path}"
rescue MarkNotFound
  red "Marker not found in #{command.ssh_config_path}"
end

#shellcomp(_ = false) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ec2ssh/cli.rb', line 45

def shellcomp(_ = false)
  if args.include?("-")
    print_rc = true
  else
    print_rc = false
  end

  # print instructions for automatically enabling shell completion
  unless print_rc
    puts "# Enable ec2ssh completion by adding\n# the following to .bash_profile/.zshrc\n\ntype ec2ssh >/dev/null 2>&1 && eval \"$(ec2ssh shellcomp -)\"\n\n"
    exit(false)
  end

  # print shell script for enabling shell completion
  zsh_comp_file = File.expand_path("../../../zsh/_ec2ssh", __FILE__)
  bash_comp_file = File.expand_path("../../../bash/ec2ssh.bash", __FILE__)
  puts "if [ -n \"${BASH_VERSION:-}\" ]; then\nsource \#{bash_comp_file}\nelif [ -n \"${ZSH_VERSION:-}\" ]; then\nsource \#{zsh_comp_file}\nfi\n"
end

#updateObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ec2ssh/cli.rb', line 21

def update
  check_dotfile_existence
  set_aws_logging
  command = make_command :update
  command.run
  green "Updated #{command.ssh_config_path}"
rescue AwsKeyNotFound
  red "Set aws keys at #{command.dotfile_path}"
rescue MarkNotFound
  red "Marker not found in #{command.ssh_config_path}"
  red "Execute '#{$0} init' first!"
end

#versionObject



77
78
79
80
# File 'lib/ec2ssh/cli.rb', line 77

def version
  require 'ec2ssh/version'
  puts "ec2ssh #{Ec2ssh::VERSION}"
end