Chee 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,8 +2,14 @@
2
2
  Chee
3
3
  ================
4
4
 
5
- Send commands through SSH, but using a tty/pty and STDIN.
6
- That's right: Interactive SSH sessions.
5
+ A Ruby gem that allows interactive `User <-> Ruby <-> SSH` sessions.
6
+ It uses Net::SSH and a pseudo-terminal.
7
+
8
+ Thanks
9
+ ------
10
+
11
+ This post by `jtzero` provided the solution for using STDIN and Net::SSH:
12
+ [http://stackoverflow.com/questions/6942279/ruby-net-ssh-channel-dies](http://stackoverflow.com/questions/6942279/ruby-net-ssh-channel-dies)
7
13
 
8
14
  Limitations
9
15
  -----------
@@ -12,8 +18,9 @@ Limitations
12
18
  Apt-get and
13
19
  other programs that request input in a simple manner should work well enough.
14
20
 
15
- * PTY (psuedo-terminal) is used. Which means it runs in a sub-shell.
16
- Which leads to *no* STDERR access. All output is done on STDOUT.
21
+ * A pseudo-terminal is used. Which means it runs in a sub-shell.
22
+ Which leads to *no* STDERR access. All returning output from your command
23
+ is done on STDOUT.
17
24
 
18
25
  Installation
19
26
  ------------
@@ -27,14 +34,12 @@ You could include the DSL into your own object:
27
34
 
28
35
  require "Chee"
29
36
  Class My_SSH
30
-
31
37
  include Chee::DSL
38
+ end
32
39
 
33
- def ssh cmd
34
- super cmd.strip
35
- end
36
-
37
- end # === Class My_SSH
40
+ o = My_SSH.new
41
+ o.server 'my_server'
42
+ o.ssh "uptime"
38
43
 
39
44
  Or you could use Chee directly:
40
45
 
@@ -42,31 +47,50 @@ Or you could use Chee directly:
42
47
  Chee.server 'my_server'
43
48
  Chee.ssh "uptime"
44
49
 
50
+ `:server` accepts the same options as `Net::SSH.start`:
51
+
52
+ Chee.server(
53
+ 'localhost',
54
+ 'me',
55
+ :password => "try to use private/public keys",
56
+ :timeout => 3
57
+ )
58
+
45
59
  `:ssh` returns a `Chee::Result` object:
46
60
 
47
61
  result = Chee.ssh( "uptime" )
48
-
49
62
  result.out # ==> output from STDOUT
50
63
  result.exit_status
51
64
 
65
+ Usage: Printing Output
66
+ -----
67
+
68
+ Override default printing with `:print_data`:
69
+
70
+ def print_data data
71
+ # ignore data
72
+ end
73
+
74
+ # The default is:
75
+ def print_data data
76
+ print data
77
+ STDOUT.flush
78
+ end
79
+
80
+ You can still get the output with the returned value of `:ssh`
81
+ or `:ssh_to_all`:
82
+
83
+ o.ssh( "uptime" ).out
84
+
85
+ o.ssh_to_all("uptime").map(&:out)
86
+
52
87
  Usage: Single Server
53
88
  -----
54
89
 
55
90
  require "Chee"
56
91
 
57
- # If you configured server using ~/.ssh/config:
58
92
  Chee.server "my_server"
59
93
 
60
- # You can also use the same options you would send to
61
- # Net::SSH:
62
- Chee.server(
63
- 'localhost',
64
- 'me',
65
- :password => "try to use private/public keys",
66
- :timeout => 3
67
- )
68
-
69
- # Send a command
70
94
  Chee.ssh %^ sudo add-apt-repository ppa:nginx/stable ^
71
95
 
72
96
 
@@ -99,11 +123,13 @@ Multiple servers, multiple commands:
99
123
  Chee.server 'localhost'
100
124
  Chee.server 'my_other_host'
101
125
 
102
- Chee.ssh_to_all %^
126
+ Chee.ssh_to_all('
103
127
  echo "a"
104
128
  echo "b"
105
- ^
106
- # ---> [ Chee::Result, Chee::Result, Chee::Result, Chee::Result ]
129
+ ')
130
+ .map(&:out)
131
+
132
+ # ---> [ "a", "b", "a", "b" ]
107
133
 
108
134
  Run Tests
109
135
  ---------
@@ -29,10 +29,9 @@ class Chee
29
29
  @server = args
30
30
  end
31
31
 
32
- def print_data &blok
33
- @print_data ||= proc { |d| print d; STDOUT.flush; }
34
- return(@print_data) if blok.nil?
35
- @print_data = blok
32
+ def print_data d
33
+ print d
34
+ STDOUT.flush
36
35
  end
37
36
 
38
37
  def ssh_to_all command
@@ -127,7 +126,7 @@ class Chee
127
126
  stdout << d # .sub(%r!\r?\n\Z!,'')
128
127
 
129
128
  unless prev_cmd.to_s.strip == d.strip
130
- print_data.call d
129
+ print_data d
131
130
  end
132
131
 
133
132
  prev_data = d
@@ -1,3 +1,3 @@
1
1
  class Chee
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -9,8 +9,7 @@ class My_SSH
9
9
 
10
10
  include Chee::DSL
11
11
 
12
- def print_data
13
- @print_data ||= proc {}
12
+ def print_data data
14
13
  end
15
14
 
16
15
  end # === My_SSH
@@ -10,11 +10,14 @@ describe "Chee :ssh" do
10
10
  ]
11
11
 
12
12
  Chee.server @localhost
13
- @data = ''
14
13
 
15
- Chee.print_data { |d|
16
- @data << d
17
- }
14
+ def Chee.data
15
+ @data
16
+ end
17
+
18
+ def Chee.print_data d
19
+ @data = d
20
+ end
18
21
  end
19
22
 
20
23
  it 'accepts a String for the server info.' do
@@ -29,7 +32,7 @@ describe "Chee :ssh" do
29
32
 
30
33
  it 'uses :print_data to print data' do
31
34
  Chee.ssh 'echo c'
32
- @data.strip.should == 'c'
35
+ Chee.data.strip.should == 'c'
33
36
  end
34
37
 
35
38
  it 'uses a PTY' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Chee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: