hocho 0.3.6 → 0.3.8

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
  SHA256:
3
- metadata.gz: fc1d89aba4bdb301b19444dc5d87cbe529b75cd7fd2a5862af8a0e0eee0f06c9
4
- data.tar.gz: a1e4308126d79cb3b4365c0dda2737ff2c57ca1f9a71ff74ba86948a0d4e4ab7
3
+ metadata.gz: 624f4576bac01ab09d957ba4252d50364c64a3129a09a25ec09773be27f7d1c8
4
+ data.tar.gz: 2c217ddcb5f628117d587e6d0d6f4db55dc5f87b951d59aee276acf4dec3872d
5
5
  SHA512:
6
- metadata.gz: e9a5930caf9ce31ba052af069126bb6230b275ab007c00a0edbaf08a8d30fc0b4135aeae57899ebc8428a068a0f7221dd4249f1fa6af240830fb98b045aaeef5
7
- data.tar.gz: 89d2ac75f09f14d2e569a7a229cfa61a625dbda5e1da6d035d54ac240d9cb78fd6272a85cc686166004404994a98384b1e6466d86ee349ab4d28270ad33c5e45
6
+ metadata.gz: '0315529a8835d22611d7e8d64763d21e497022958756c13d8d61bc915dc48f751b0672cf569fa535d76b882d5d20041f6787d72caecd37c54d608380a7887309'
7
+ data.tar.gz: ba8d6825082b32a63d03d8196d2180e99c43597c4e93cd63b4dd701f4bf172fbd2ddca810b448bf67659133cff70175abe4728c843c6ab6c0272db377c239b42
data/lib/hocho/command.rb CHANGED
@@ -36,7 +36,7 @@ module Hocho
36
36
  desc "show NAME", ""
37
37
  method_option :format, enum: %w(yaml json), default: 'yaml'
38
38
  def show(name)
39
- host = inventory.filter(name: name).first
39
+ host = inventory.filter({name: name}).first
40
40
  if host
41
41
  case options[:format]
42
42
  when 'yaml'
@@ -22,14 +22,15 @@ module Hocho
22
22
  ssh_cmd = ['ssh', *host.openssh_config.flat_map { |l| ['-o', "\"#{l}\""] }].join(' ')
23
23
  shm_exclude = shm_prefix.map{ |_| "--exclude=#{_}" }
24
24
  compress = host.compress? ? ['-z'] : []
25
- rsync_cmd = [*%w(rsync -a --copy-links --copy-unsafe-links --delete --exclude=.git), *compress, *shm_exclude, '--rsh', ssh_cmd, '.', "#{host.hostname}:#{host_basedir}"]
25
+ hostname = host.hostname.include?(?:) ? "[#{host.hostname}]" : host.hostname # surround with square bracket for ipv6 address
26
+ rsync_cmd = [*%w(rsync -a --copy-links --copy-unsafe-links --delete --exclude=.git), *compress, *shm_exclude, '--rsh', ssh_cmd, '.', "#{hostname}:#{host_basedir}"]
26
27
 
27
28
  puts "=> $ #{rsync_cmd.shelljoin}"
28
29
  system(*rsync_cmd, chdir: base_dir) or raise 'failed to rsync'
29
30
 
30
31
  unless shm_prefix.empty?
31
32
  shm_include = shm_prefix.map{ |_| "--include=#{_.sub(%r{/\z},'')}/***" }
32
- rsync_cmd = [*%w(rsync -a --copy-links --copy-unsafe-links --delete), *compress, *shm_include, '--exclude=*', '--rsh', ssh_cmd, '.', "#{host.hostname}:#{host_shm_basedir}"]
33
+ rsync_cmd = [*%w(rsync -a --copy-links --copy-unsafe-links --delete), *compress, *shm_include, '--exclude=*', '--rsh', ssh_cmd, '.', "#{hostname}:#{host_shm_basedir}"]
33
34
  puts "=> $ #{rsync_cmd.shelljoin}"
34
35
  system(*rsync_cmd, chdir: base_dir) or raise 'failed to rsync'
35
36
  shm_prefix.each do |x|
@@ -109,30 +110,36 @@ module Hocho
109
110
  end
110
111
 
111
112
  def set_ssh_output_hook(c)
112
- outbuf, errbuf = [], []
113
- check = ->(prefix,data,buf) do
114
- has_newline = data.include?("\n")
113
+ check = ->(prefix, data, buf) do
114
+ data = buf + data unless buf.empty?
115
+ return if data.empty?
116
+
115
117
  lines = data.lines
116
- last = lines.pop
117
- if last[-1] == "\n"
118
- buf << last
119
- end
120
- if has_newline
121
- (buf+lines).join.each_line do |line|
122
- puts "#{prefix} #{line}"
123
- end
124
- buf.replace([])
118
+
119
+ # If data is not NL-terminated, its last line is carried over to next check.call
120
+ if lines.last.end_with?("\n")
121
+ buf.clear
122
+ else
123
+ buf.replace(lines.pop)
125
124
  end
126
- if last[-1] != "\n"
127
- buf << last
125
+
126
+ lines.each do |line|
127
+ puts "#{prefix}#{line}"
128
128
  end
129
129
  end
130
130
 
131
+ outbuf, errbuf = +"", +""
132
+ outpre, errpre = "[#{host.name}] ", "[#{host.name}/ERR] "
133
+
131
134
  c.on_data do |c, data|
132
- check.call "[#{host.name}] ", data, outbuf
135
+ check.call outpre, data, outbuf
133
136
  end
134
137
  c.on_extended_data do |c, _, data|
135
- check.call "[#{host.name}/ERR] ", data, errbuf
138
+ check.call errpre, data, errbuf
139
+ end
140
+ c.on_close do
141
+ puts "#{outpre}#{outbuf}" unless outbuf.empty?
142
+ puts "#{errpre}#{errbuf}" unless errbuf.empty?
136
143
  end
137
144
  end
138
145
 
data/lib/hocho/host.rb CHANGED
@@ -107,7 +107,7 @@ module Hocho
107
107
  when :encryption
108
108
  [["Ciphers", [*value].join(?,)]]
109
109
  when :compression
110
- [["Compression", value]]
110
+ [["Compression", value ? 'yes' : 'no']]
111
111
  when :compression_level
112
112
  [["CompressionLevel", value]]
113
113
  when :timeout
data/lib/hocho/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hocho
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hocho
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - sorah (Shota Fukumori)
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-25 00:00:00.000000000 Z
11
+ date: 2023-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description:
111
+ description:
112
112
  email:
113
113
  - her@sorah.jp
114
114
  executables:
@@ -153,7 +153,7 @@ homepage: https://github.com/sorah/hocho
153
153
  licenses:
154
154
  - MIT
155
155
  metadata: {}
156
- post_install_message:
156
+ post_install_message:
157
157
  rdoc_options: []
158
158
  require_paths:
159
159
  - lib
@@ -168,8 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  requirements: []
171
- rubygems_version: 3.1.2
172
- signing_key:
171
+ rubygems_version: 3.4.0.dev
172
+ signing_key:
173
173
  specification_version: 4
174
174
  summary: Server provisioning tool with itamae
175
175
  test_files: []