shell_helpers 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog.md +236 -2
- data/LICENSE.txt +1 -1
- data/Rakefile +7 -10
- data/gemspec.yml +1 -0
- data/lib/shell_helpers.rb +61 -23
- data/lib/shell_helpers/export.rb +4 -4
- data/lib/shell_helpers/logger.bak.rb +481 -0
- data/lib/shell_helpers/logger.rb +274 -56
- data/lib/shell_helpers/pathname.rb +16 -3
- data/lib/shell_helpers/run.rb +48 -19
- data/lib/shell_helpers/sh.rb +97 -30
- data/lib/shell_helpers/sysutils.rb +71 -8
- data/lib/shell_helpers/utils.rb +12 -8
- data/lib/shell_helpers/version.rb +1 -1
- data/test/test_logger.rb +48 -0
- metadata +20 -5
data/lib/shell_helpers/utils.rb
CHANGED
@@ -29,7 +29,7 @@ module ShellHelpers
|
|
29
29
|
return ShLog.sh(r)
|
30
30
|
when :exec_quiet
|
31
31
|
require 'shell_helpers/sh'
|
32
|
-
return Sh.sh(r)
|
32
|
+
return Sh.sh(*r)
|
33
33
|
end
|
34
34
|
return r
|
35
35
|
end
|
@@ -202,7 +202,7 @@ module ShellHelpers
|
|
202
202
|
path.map { |dir| Pathname.glob(dir+pattern) }.flatten
|
203
203
|
end
|
204
204
|
|
205
|
-
def rsync(*files, out, default_opts: "-
|
205
|
+
def rsync(*files, out, default_opts: "-vczz", preserve: true, partial: true, keep_dirlinks: false, backup: false, relative: false, delete: false, clean_out: false, clobber: true, expected: 23, chown: nil, sshcommand: nil, exclude: [], **opts, &b)
|
206
206
|
require 'shell_helpers/sh'
|
207
207
|
rsync_opts=[*opts.delete(:rsync_opts)] || []
|
208
208
|
rsync_opts << default_opts
|
@@ -210,6 +210,7 @@ module ShellHelpers
|
|
210
210
|
rsync_opts << "-P" if partial #--partial --progress
|
211
211
|
rsync_opts+=%w(--no-owner --no-group) if preserve==:nochown
|
212
212
|
rsync_opts+=["--chown", chown] if chown
|
213
|
+
rsync_opts << "--ignore-existing" unless clobber
|
213
214
|
#on dest: do not replace a symlink to a directory with the real directory
|
214
215
|
#use --copy-dirlinks for the same usage on source
|
215
216
|
rsync_opts << "--keep-dirlinks" if keep_dirlinks
|
@@ -237,17 +238,18 @@ module ShellHelpers
|
|
237
238
|
rsync_opts << sshcommand.shellescape
|
238
239
|
end
|
239
240
|
rsync_opts+=opts.delete(:rsync_late_opts)||[]
|
240
|
-
|
241
|
+
cmd=["rsync"]+rsync_opts+files.map(&:to_s)+[out.to_s]
|
242
|
+
Sh.sh(*cmd, expected: expected, **opts, &b)
|
241
243
|
#expected: rsync error code 23 is some files/attrs were not transferred
|
242
244
|
end
|
243
245
|
|
244
246
|
# host can be of the form user@host:port
|
245
247
|
# warning this is different from standard ssh syntax of user@host:path
|
246
|
-
def ssh(host, *commands, mode: :
|
248
|
+
def ssh(host, *commands, mode: :system, ssh_command: 'ssh',
|
247
249
|
ssh_options: [], ssh_Ooptions: [],
|
248
250
|
port: nil, forward: nil, x11: nil, user: nil, path: nil, parse: true,
|
249
|
-
pty: nil,
|
250
|
-
**opts)
|
251
|
+
pty: nil, ssh_env:nil,
|
252
|
+
**opts, &b)
|
251
253
|
|
252
254
|
#sshkit has a special setting for :local
|
253
255
|
host=host.to_s unless mode==:sshkit and host.is_a?(Symbol)
|
@@ -276,11 +278,12 @@ module ShellHelpers
|
|
276
278
|
case mode
|
277
279
|
when :system,:spawn,:capture,:exec
|
278
280
|
host="#{user}@#{host}" if user
|
279
|
-
|
281
|
+
env_commands= ssh_env ? [Export.export_variables(ssh_env, inline: true)]+commands : commands
|
282
|
+
Sh.sh(* [ssh_command]+ssh_options+[host]+env_commands, mode: mode, **opts)
|
280
283
|
when :net_ssh
|
281
284
|
require 'net/ssh'
|
282
285
|
user=nil;
|
283
|
-
Net::SSH.start(host, user, ssh_options)
|
286
|
+
Net::SSH.start(host, user, ssh_options, &b)
|
284
287
|
when :sshkit
|
285
288
|
require 'sshkit'
|
286
289
|
host=SSHKit::Host.new(host)
|
@@ -298,6 +301,7 @@ module ShellHelpers
|
|
298
301
|
ssh_command_options: ([ssh_command]+ssh_options).shelljoin,
|
299
302
|
user: user,
|
300
303
|
host: host,
|
304
|
+
path: path,
|
301
305
|
hostssh: user ? "#{user}@#{host}" : host,
|
302
306
|
command: commands }
|
303
307
|
end
|
data/test/test_logger.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'shell_helpers'
|
3
|
+
|
4
|
+
describe ShellHelpers::ColorLogger do
|
5
|
+
before do
|
6
|
+
@buffer=StringIO.new
|
7
|
+
@logger=SH::ColorLogger.new(@buffer, default_formatter: :color)
|
8
|
+
end
|
9
|
+
it "Has a info mode" do
|
10
|
+
@logger.info "foo"
|
11
|
+
@buffer.string.must_equal "foo\n"
|
12
|
+
end
|
13
|
+
it "Has a color mark mode" do
|
14
|
+
@logger.mark "foo"
|
15
|
+
@buffer.string.must_equal "\e[1mfoo\e[0m\n"
|
16
|
+
end
|
17
|
+
it "Has a colored important mode" do
|
18
|
+
@logger.important "foo"
|
19
|
+
@buffer.string.must_equal "\e[34;1mfoo\e[0m\n"
|
20
|
+
end
|
21
|
+
it "The colored mode can add colors" do
|
22
|
+
@logger.important "foo", color: [:red]
|
23
|
+
@buffer.string.must_equal "\e[34;1;31mfoo\e[0m\n"
|
24
|
+
end
|
25
|
+
it "Has a raw important mode" do
|
26
|
+
@logger.important "foo", format: :blank
|
27
|
+
@buffer.string.must_equal "foo\n"
|
28
|
+
end
|
29
|
+
it "Can give a numeric level" do
|
30
|
+
@logger.add(@logger.severity_lvl(:important), "foo")
|
31
|
+
@buffer.string.must_equal "foo\n"
|
32
|
+
end
|
33
|
+
it "Default to info level" do
|
34
|
+
@logger.debug("foo")
|
35
|
+
@buffer.string.must_equal ""
|
36
|
+
end
|
37
|
+
it "Don't show below debug level" do
|
38
|
+
@logger.debug3("foo")
|
39
|
+
@buffer.string.must_equal ""
|
40
|
+
end
|
41
|
+
it "Can change level" do
|
42
|
+
old_level=@logger.level
|
43
|
+
@logger.level=:debug3
|
44
|
+
@logger.debug3("foo")
|
45
|
+
@logger.level=old_level
|
46
|
+
@buffer.string.must_equal "foo\n"
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shell_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Robert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: drain
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simplecolor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +96,7 @@ dependencies:
|
|
82
96
|
version: '0.8'
|
83
97
|
description: 'Collection of script to ease working with the shell with ruby.
|
84
98
|
|
85
|
-
'
|
99
|
+
'
|
86
100
|
email: Damien.Olivier.Robert+gems@gmail.com
|
87
101
|
executables:
|
88
102
|
- abs_to_rel.rb
|
@@ -107,6 +121,7 @@ files:
|
|
107
121
|
- gemspec.yml
|
108
122
|
- lib/shell_helpers.rb
|
109
123
|
- lib/shell_helpers/export.rb
|
124
|
+
- lib/shell_helpers/logger.bak.rb
|
110
125
|
- lib/shell_helpers/logger.rb
|
111
126
|
- lib/shell_helpers/options.rb
|
112
127
|
- lib/shell_helpers/pathname.rb
|
@@ -118,6 +133,7 @@ files:
|
|
118
133
|
- shell_helpers.gemspec
|
119
134
|
- test/helper.rb
|
120
135
|
- test/test_export.rb
|
136
|
+
- test/test_logger.rb
|
121
137
|
- test/test_shell_helpers.rb
|
122
138
|
homepage: https://github.com/DamienRobert/shell_helpers#readme
|
123
139
|
licenses:
|
@@ -139,8 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
155
|
- !ruby/object:Gem::Version
|
140
156
|
version: '0'
|
141
157
|
requirements: []
|
142
|
-
|
143
|
-
rubygems_version: 2.7.7
|
158
|
+
rubygems_version: 3.1.2
|
144
159
|
signing_key:
|
145
160
|
specification_version: 4
|
146
161
|
summary: Shell Helpers
|