fantassh 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3313e2ac142946ca069a6aa41411ffba516b69db
4
- data.tar.gz: 6b7ca5d40c94b48c95c0d3c4a588a99397fb41af
3
+ metadata.gz: 55f938c65343a5ff9f5620e28edcb6c362bc06eb
4
+ data.tar.gz: 20e00024d671a981a137c677ebeba590e533adcc
5
5
  SHA512:
6
- metadata.gz: e1a8a47857b20d771656245ddc4db65a7aa1a1b66ce626c1d5359494892b99b3fc6537695db9579efdddac156a5c7ddf8076dc575c5309335caf6b08aeaa0fbe
7
- data.tar.gz: a404aacc74a19a34c2ca713e515353543f03af7cc503716f2cbb985fd3f82d2a8bcf1c0fcc9427e0e710c8e3977d98280fbeb0f513cb6a7a1b2bc01cb894cdbf
6
+ metadata.gz: f5d22fa1cffc5eb16e024f374ccaf4f5edfa781cee4f3272e9b338786904a5e37c842175a703f915808ed5ba51b5aaefaf5318acc37de329f208b6907e0ace9c
7
+ data.tar.gz: 9670c393604e09c06e730a2f99943a2444c5c8115c78d54bd0995e5c88bf8d241df23ae8511f311af9f7aa40ffdd067db35ac1201fc6196fd88176e4f6a3536d
data/fantassh.gemspec CHANGED
@@ -18,6 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
+ spec.required_ruby_version = '>= 2.0'
22
+
23
+ spec.requirements << 'selecta'
24
+
21
25
  spec.add_dependency 'slop'
22
26
 
23
27
  spec.add_development_dependency 'bundler', '~> 1.3'
@@ -1,6 +1,7 @@
1
1
  require 'slop'
2
2
  require_relative 'bash_history'
3
3
  require_relative 'entries'
4
+ require_relative 'history'
4
5
 
5
6
  module Fantassh
6
7
  class Application
@@ -17,6 +18,14 @@ module Fantassh
17
18
  Fantassh::Application.list
18
19
  end
19
20
 
21
+ command :last do
22
+ banner "Usage: #{File.basename($0)} last"
23
+
24
+ run do
25
+ Fantassh::Application.last
26
+ end
27
+ end
28
+
20
29
  command :exclude do
21
30
  banner "Usage: #{File.basename($0)} exclude <ssh command>"
22
31
 
@@ -38,8 +47,17 @@ module Fantassh
38
47
  selected_entry = `echo '#{entries.all.join("\n")}' | selecta`
39
48
  # in case selecta receives ctrl+c we don't proceed
40
49
  unless selected_entry.empty?
41
- # indent by whitespace so it doesn't show up in the history
42
- exec " ssh #{selected_entry}"
50
+ history.add(selected_entry)
51
+ run_ssh_command(selected_entry)
52
+ end
53
+ end
54
+
55
+ def last
56
+ last = history.last
57
+ if last
58
+ run_ssh_command(last)
59
+ else
60
+ puts "There is no history entry just yet!"
43
61
  end
44
62
  end
45
63
 
@@ -54,6 +72,15 @@ module Fantassh
54
72
  def bash_history
55
73
  BashHistory.new
56
74
  end
75
+
76
+ def history
77
+ History.new
78
+ end
79
+
80
+ def run_ssh_command(argument)
81
+ # indent by whitespace so it doesn't show up in the history
82
+ exec " ssh #{argument}"
83
+ end
57
84
  end
58
85
  end
59
86
  end
@@ -0,0 +1,19 @@
1
+ require_relative 'history_file'
2
+
3
+ module Fantassh
4
+ class History
5
+ def initialize(file: HistoryFile.new)
6
+ @file = file
7
+
8
+ @file.init_file_structure
9
+ end
10
+
11
+ def last
12
+ @file.all.last
13
+ end
14
+
15
+ def add(entry)
16
+ @file.add([entry])
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ require 'fileutils'
2
+ require_relative 'entries_file'
3
+
4
+ module Fantassh
5
+ class HistoryFile < EntriesFile
6
+ def file
7
+ File.join(@config_dir, 'history')
8
+ end
9
+ end
10
+ end
11
+
@@ -1,3 +1,3 @@
1
1
  module Fantassh
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -17,5 +17,32 @@ module Fantassh
17
17
  end
18
18
  end
19
19
  end
20
+
21
+ context 'last' do
22
+ it 'runs the last called connection' do
23
+ Dir.mktmpdir do |dir|
24
+ history = History.new(
25
+ file: HistoryFile.new(config_dir: dir))
26
+ history.add('user@last')
27
+ Application.stub(history: history)
28
+
29
+ Application.should_receive(:exec).with(' ssh user@last')
30
+
31
+ Application.run(['last'])
32
+ end
33
+ end
34
+
35
+ it 'prints a message if the history is empty' do
36
+ Dir.mktmpdir do |dir|
37
+ history = History.new(
38
+ file: HistoryFile.new(config_dir: dir))
39
+ Application.stub(history: history)
40
+
41
+ STDOUT.should_receive(:puts).with('There is no history entry just yet!')
42
+
43
+ Application.run(['last'])
44
+ end
45
+ end
46
+ end
20
47
  end
21
48
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'fantassh/history'
3
+
4
+ module Fantassh
5
+ describe History do
6
+ let(:file) { double(:file, init_file_structure: nil) }
7
+
8
+ context "#initialize" do
9
+ it "calls init_file_structure on the file" do
10
+ file.should_receive(:init_file_structure)
11
+
12
+ History.new(file: file)
13
+ end
14
+ end
15
+
16
+ context "#add" do
17
+ it "calls #add on the file" do
18
+ file.should_receive(:add).with(['user@last'])
19
+ History.new(file: file).add('user@last')
20
+ end
21
+ end
22
+
23
+ context "#last" do
24
+ it "returns the last entry if there is one" do
25
+ file.stub(all: ['user@last'])
26
+ History.new(file: file).last.should == 'user@last'
27
+ end
28
+
29
+ it "returns nil if there is no entry" do
30
+ file.stub(all: [])
31
+ History.new(file: file).last.should be_nil
32
+ end
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fantassh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Reigel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-26 00:00:00.000000000 Z
11
+ date: 2014-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -88,12 +88,15 @@ files:
88
88
  - lib/fantassh/entries.rb
89
89
  - lib/fantassh/entries_file.rb
90
90
  - lib/fantassh/excluded_entries_file.rb
91
+ - lib/fantassh/history.rb
92
+ - lib/fantassh/history_file.rb
91
93
  - lib/fantassh/version.rb
92
94
  - spec/lib/application_spec.rb
93
95
  - spec/lib/bash_history_spec.rb
94
96
  - spec/lib/entries_file_spec.rb
95
97
  - spec/lib/entries_spec.rb
96
98
  - spec/lib/excluded_entries_file_spec.rb
99
+ - spec/lib/history_spec.rb
97
100
  - spec/spec_helper.rb
98
101
  homepage: https://github.com/koffeinfrei/fantassh
99
102
  licenses:
@@ -107,13 +110,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
110
  requirements:
108
111
  - - ">="
109
112
  - !ruby/object:Gem::Version
110
- version: '0'
113
+ version: '2.0'
111
114
  required_rubygems_version: !ruby/object:Gem::Requirement
112
115
  requirements:
113
116
  - - ">="
114
117
  - !ruby/object:Gem::Version
115
118
  version: '0'
116
- requirements: []
119
+ requirements:
120
+ - selecta
117
121
  rubyforge_project:
118
122
  rubygems_version: 2.2.2
119
123
  signing_key:
@@ -125,4 +129,5 @@ test_files:
125
129
  - spec/lib/entries_file_spec.rb
126
130
  - spec/lib/entries_spec.rb
127
131
  - spec/lib/excluded_entries_file_spec.rb
132
+ - spec/lib/history_spec.rb
128
133
  - spec/spec_helper.rb