Class: Fantassh::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/fantassh/application.rb

Class Method Summary collapse

Class Method Details

.bash_historyObject



72
73
74
# File 'lib/fantassh/application.rb', line 72

def bash_history
  BashHistory.new
end

.entriesObject



68
69
70
# File 'lib/fantassh/application.rb', line 68

def entries
  Entries.new
end

.exclude(entry) ⇒ Object



64
65
66
# File 'lib/fantassh/application.rb', line 64

def exclude(entry)
  entries.exclude([entry])
end

.historyObject



76
77
78
# File 'lib/fantassh/application.rb', line 76

def history
  History.new
end

.lastObject



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

def last
  last = history.last
  if last
    run_ssh_command(last)
  else
    puts "There is no history entry just yet!"
  end
end

.listObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/fantassh/application.rb', line 44

def list
  entries.add(bash_history.entries)

  selected_entry = `echo '#{entries.all.join("\n")}' | selecta`
  # in case selecta receives ctrl+c we don't proceed
  unless selected_entry.empty?
    history.add(selected_entry)
    run_ssh_command(selected_entry)
  end
end

.run(argv = ARGV) ⇒ Object



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
# File 'lib/fantassh/application.rb', line 9

def run(argv = ARGV)
  Slop.parse(argv, help: true) do
    on '-v', '--version', 'Print the program version.' do
      puts "#{File.basename($0)} v#{Fantassh::VERSION}"
      exit
    end

    # default, runs when called without arguments
    run do
      Fantassh::Application.list
    end

    command :last do
      banner "Usage: #{File.basename($0)} last"

      run do
        Fantassh::Application.last
      end
    end

    command :exclude do
      banner "Usage: #{File.basename($0)} exclude <ssh command>"

      run do |opts, args|
        if args.empty?
          puts help
          exit
        end

        Fantassh::Application.exclude(args.join(' '))
      end
    end
  end
end

.run_ssh_command(argument) ⇒ Object



80
81
82
83
# File 'lib/fantassh/application.rb', line 80

def run_ssh_command(argument)
  # indent by whitespace so it doesn't show up in the history
  exec " ssh #{argument}"
end