trop 0.0.16 → 0.4.27
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/Gemfile +17 -11
- data/LICENSE.txt +0 -0
- data/README.md +5 -2
- data/README.rakes.md +34 -0
- data/Rakefile +85 -32
- data/{TODO → TODO.md} +0 -0
- data/VERSION +1 -1
- data/bin/setup +48 -0
- data/bin/update +36 -0
- data/lib/trop/config.bundler.tpl +2 -0
- data/lib/trop/core-ext.rb +8 -0
- data/lib/trop/file_finder.rb +153 -0
- data/lib/trop/filefind.rb +501 -0
- data/lib/trop/infogit.rb +48 -0
- data/lib/trop/os.rb +31 -0
- data/lib/trop/shell_deb_verb.rb +61 -0
- data/lib/trop/version.rb +1 -5
- metadata +95 -28
- data/lib/trop.rb +0 -1
@@ -0,0 +1,501 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require_relative 'find'
|
7
|
+
require 'sys/admin'
|
8
|
+
require 'win32/file'
|
9
|
+
rescue LoadError
|
10
|
+
# Do nothing, not required, just nicer.
|
11
|
+
end
|
12
|
+
module Trop
|
13
|
+
|
14
|
+
class FileFind
|
15
|
+
|
16
|
+
# The version of the file-find library
|
17
|
+
VERSION = '0.4.1'.freeze
|
18
|
+
|
19
|
+
|
20
|
+
# :stopdoc:
|
21
|
+
VALID_OPTIONS = %w[
|
22
|
+
atime
|
23
|
+
ctime
|
24
|
+
follow
|
25
|
+
ftype
|
26
|
+
inum
|
27
|
+
group
|
28
|
+
links
|
29
|
+
maxdepth
|
30
|
+
mindepth
|
31
|
+
mount
|
32
|
+
mtime
|
33
|
+
name
|
34
|
+
pattern
|
35
|
+
path
|
36
|
+
perm
|
37
|
+
prune
|
38
|
+
size
|
39
|
+
user
|
40
|
+
]
|
41
|
+
# :startdoc:
|
42
|
+
|
43
|
+
# The starting path(s) for the search. The default is the current directory.
|
44
|
+
# This can be a single path or an array of paths.
|
45
|
+
#
|
46
|
+
attr_accessor :path
|
47
|
+
|
48
|
+
# The list of options passed to the constructor and/or used by the
|
49
|
+
# Trop::Find#find method.
|
50
|
+
#
|
51
|
+
attr_accessor :options
|
52
|
+
|
53
|
+
# Limits searches by file access time, where the value you supply is the
|
54
|
+
# number of days back from the time that the File::Find#find method was
|
55
|
+
# called.
|
56
|
+
#
|
57
|
+
attr_accessor :atime
|
58
|
+
|
59
|
+
# Limits searches by file change time, where the value you supply is the
|
60
|
+
# number of days back from the time that the File::Find#find method was
|
61
|
+
# called.
|
62
|
+
#
|
63
|
+
attr_accessor :ctime
|
64
|
+
|
65
|
+
# Limits searches to files that belong to a specific group, where the
|
66
|
+
# group can be either a group name or ID.
|
67
|
+
#
|
68
|
+
attr_accessor :group
|
69
|
+
|
70
|
+
# An array of two element arrays for storing FileTest methods and their
|
71
|
+
# boolean value.
|
72
|
+
#
|
73
|
+
attr_accessor :filetest
|
74
|
+
|
75
|
+
# Controls the behavior of how symlinks are followed. If set to true (the
|
76
|
+
# default), then follows the file pointed to. If false, it considers the
|
77
|
+
# symlink itself.
|
78
|
+
#
|
79
|
+
attr_accessor :follow
|
80
|
+
|
81
|
+
# Limits searches to specific types of files. The possible values here are
|
82
|
+
# those returned by the File.ftype method.
|
83
|
+
#
|
84
|
+
attr_accessor :ftype
|
85
|
+
|
86
|
+
# Limits search to a file with a specific inode number.
|
87
|
+
#
|
88
|
+
attr_accessor :inum
|
89
|
+
|
90
|
+
# Limits search to files with the specified number of links.
|
91
|
+
#
|
92
|
+
attr_accessor :links
|
93
|
+
|
94
|
+
# Limits search to a maximum depth into the tree relative to the starting
|
95
|
+
# search directory.
|
96
|
+
#
|
97
|
+
attr_accessor :maxdepth
|
98
|
+
|
99
|
+
# Limits searches to a minimum depth into the tree relative to the starting
|
100
|
+
# search directory.
|
101
|
+
#
|
102
|
+
attr_accessor :mindepth
|
103
|
+
|
104
|
+
# Limits searches to the same filesystem as the specified directory. For
|
105
|
+
# Windows users, this refers to the volume.
|
106
|
+
#
|
107
|
+
attr_reader :mount
|
108
|
+
|
109
|
+
# Limits searches by file modification time, where the value you supply is
|
110
|
+
# the number of days back from the time that the File::Find#find method was
|
111
|
+
# called.
|
112
|
+
#
|
113
|
+
attr_accessor :mtime
|
114
|
+
|
115
|
+
# The name pattern used to limit file searches. The patterns that are legal
|
116
|
+
# for Dir.glob are legal here. The default is '*', i.e. everything.
|
117
|
+
#
|
118
|
+
attr_accessor :name
|
119
|
+
|
120
|
+
# Limits searches to files which have permissions that match the octal
|
121
|
+
# value that you provide. For purposes of this comparison, only the user,
|
122
|
+
# group, and world settings are used.
|
123
|
+
#
|
124
|
+
# You may optionally use symbolic permissions, e.g. "g+rw", "u=rwx", etc.
|
125
|
+
#
|
126
|
+
# MS Windows only recognizes two modes, 0644 and 0444.
|
127
|
+
#
|
128
|
+
attr_accessor :perm
|
129
|
+
|
130
|
+
# Skips files or directories that match the string provided as an argument.
|
131
|
+
#
|
132
|
+
attr_accessor :prune
|
133
|
+
|
134
|
+
# If the value passed is an integer, this option limits searches to files
|
135
|
+
# that match the size, in bytes, exactly. If a string is passed, you can
|
136
|
+
# use the standard comparable operators to match files, e.g. ">= 200" would
|
137
|
+
# limit searches to files greater than or equal to 200 bytes.
|
138
|
+
#
|
139
|
+
attr_accessor :size
|
140
|
+
|
141
|
+
# Limits searches to files that belong to a specific user, where the user
|
142
|
+
# can be either a user name or an ID.
|
143
|
+
#
|
144
|
+
attr_accessor :user
|
145
|
+
|
146
|
+
# The file that matched previously in the current search.
|
147
|
+
#
|
148
|
+
attr_reader :previous
|
149
|
+
|
150
|
+
alias pattern name
|
151
|
+
alias pattern= name=
|
152
|
+
|
153
|
+
# Creates and returns a new File::Find object. The options set for this
|
154
|
+
# object serve as the rules for determining what files the File::Find#find
|
155
|
+
# method will search for.
|
156
|
+
#
|
157
|
+
# In addition to the standard list of valid options, you may also use
|
158
|
+
# FileTest methods as options, setting their value to true or false.
|
159
|
+
#
|
160
|
+
# Example:
|
161
|
+
#
|
162
|
+
# rule = File::Find.new(
|
163
|
+
# :name => "*.rb",
|
164
|
+
# :follow => false,
|
165
|
+
# :path => ['/usr/local/lib', '/opt/local/lib'],
|
166
|
+
# :readable? => true
|
167
|
+
# )
|
168
|
+
#
|
169
|
+
def initialize(options = {})
|
170
|
+
@options = options
|
171
|
+
|
172
|
+
@atime = nil
|
173
|
+
@ctime = nil
|
174
|
+
@ftype = nil
|
175
|
+
@group = nil
|
176
|
+
@follow = true
|
177
|
+
@inum = nil
|
178
|
+
@links = nil
|
179
|
+
@mount = nil
|
180
|
+
@mtime = nil
|
181
|
+
@perm = nil
|
182
|
+
@prune = nil
|
183
|
+
@size = nil
|
184
|
+
@user = nil
|
185
|
+
|
186
|
+
@previous = nil
|
187
|
+
@maxdepth = nil
|
188
|
+
@mindepth = nil
|
189
|
+
@filetest = []
|
190
|
+
|
191
|
+
validate_and_set_options(options) unless options.empty?
|
192
|
+
|
193
|
+
@filesystem = File.stat(@mount).dev if @mount
|
194
|
+
|
195
|
+
@path ||= Dir.pwd
|
196
|
+
@name ||= '*'
|
197
|
+
end
|
198
|
+
|
199
|
+
# Executes the find based on the rules you set for the File::Find object.
|
200
|
+
# In block form, yields each file in turn that matches the specified rules.
|
201
|
+
# In non-block form it will return an array of matches instead.
|
202
|
+
#
|
203
|
+
# Example:
|
204
|
+
#
|
205
|
+
# rule = Trop::Find.new(
|
206
|
+
# :name => "*.rb",
|
207
|
+
# :follow => false,
|
208
|
+
# :path => ['/usr/local/lib', '/opt/local/lib']
|
209
|
+
# )
|
210
|
+
#
|
211
|
+
# rule.find{ |f|
|
212
|
+
# puts f
|
213
|
+
# }
|
214
|
+
#
|
215
|
+
def find
|
216
|
+
results = [] unless block_given?
|
217
|
+
paths = @path.is_a?(String) ? [@path] : @path # Ruby 1.9.x compatibility
|
218
|
+
|
219
|
+
if @prune
|
220
|
+
prune_regex = Regexp.new(@prune)
|
221
|
+
else
|
222
|
+
prune_regex = nil
|
223
|
+
end
|
224
|
+
|
225
|
+
paths.each {|path|
|
226
|
+
begin
|
227
|
+
Dir.foreach(path) {|file|
|
228
|
+
next if file == '.'
|
229
|
+
next if file == '..'
|
230
|
+
|
231
|
+
if prune_regex
|
232
|
+
next if prune_regex.match(file)
|
233
|
+
end
|
234
|
+
|
235
|
+
file = File.join(path, file)
|
236
|
+
|
237
|
+
stat_method = @follow ? :stat : :lstat
|
238
|
+
# Skip files we cannot access, stale links, etc.
|
239
|
+
begin
|
240
|
+
stat_info = File.send(stat_method, file)
|
241
|
+
rescue Errno::ENOENT, Errno::EACCES
|
242
|
+
next
|
243
|
+
rescue Errno::ELOOP
|
244
|
+
stat_method = :lstat # Handle recursive symlinks
|
245
|
+
retry if stat_method.to_s != 'lstat'
|
246
|
+
end
|
247
|
+
|
248
|
+
# We need to escape any brackets in the directory name.
|
249
|
+
glob = File.join(File.dirname(file).gsub(/([\[\]])/, '\\\\\1'), @name)
|
250
|
+
|
251
|
+
# Dir[] doesn't like backslashes
|
252
|
+
if File::ALT_SEPARATOR
|
253
|
+
file.tr!(File::ALT_SEPARATOR, File::SEPARATOR)
|
254
|
+
glob.tr!(File::ALT_SEPARATOR, File::SEPARATOR)
|
255
|
+
end
|
256
|
+
|
257
|
+
if @mount
|
258
|
+
next unless stat_info.dev == @filesystem
|
259
|
+
end
|
260
|
+
|
261
|
+
if @links
|
262
|
+
next unless stat_info.nlink == @links
|
263
|
+
end
|
264
|
+
|
265
|
+
if @maxdepth || @mindepth
|
266
|
+
file_depth = file.split(File::SEPARATOR).length
|
267
|
+
current_base_path = [@path].flatten.find {|tpath| file.include?(tpath)}
|
268
|
+
path_depth = current_base_path.split(File::SEPARATOR).length
|
269
|
+
|
270
|
+
depth = file_depth - path_depth
|
271
|
+
|
272
|
+
if @maxdepth && (depth > @maxdepth)
|
273
|
+
if File.directory?(file)
|
274
|
+
unless paths.include?(file) && depth > @maxdepth
|
275
|
+
paths << file
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
next
|
280
|
+
end
|
281
|
+
|
282
|
+
if @mindepth && (depth < @mindepth)
|
283
|
+
if File.directory?(file)
|
284
|
+
unless paths.include?(file) && depth < @mindepth
|
285
|
+
paths << file
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
next
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
# Add directories back onto the list of paths to search unless
|
294
|
+
# they've already been added
|
295
|
+
#
|
296
|
+
if stat_info.directory?
|
297
|
+
paths << file unless paths.include?(file)
|
298
|
+
end
|
299
|
+
|
300
|
+
next unless Dir[glob].include?(file)
|
301
|
+
|
302
|
+
unless @filetest.empty?
|
303
|
+
file_test = true
|
304
|
+
|
305
|
+
@filetest.each {|array|
|
306
|
+
meth = array[0]
|
307
|
+
bool = array[1]
|
308
|
+
|
309
|
+
unless File.send(meth, file) == bool
|
310
|
+
file_test = false
|
311
|
+
break
|
312
|
+
end
|
313
|
+
}
|
314
|
+
|
315
|
+
next unless file_test
|
316
|
+
end
|
317
|
+
|
318
|
+
if @atime || @ctime || @mtime
|
319
|
+
date1 = Date.parse(Time.now.to_s)
|
320
|
+
|
321
|
+
if @atime
|
322
|
+
date2 = Date.parse(stat_info.atime.to_s)
|
323
|
+
next unless (date1 - date2).numerator == @atime
|
324
|
+
end
|
325
|
+
|
326
|
+
if @ctime
|
327
|
+
date2 = Date.parse(stat_info.ctime.to_s)
|
328
|
+
next unless (date1 - date2).numerator == @ctime
|
329
|
+
end
|
330
|
+
|
331
|
+
if @mtime
|
332
|
+
date2 = Date.parse(stat_info.mtime.to_s)
|
333
|
+
next unless (date1 - date2).numerator == @mtime
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
if @ftype
|
338
|
+
next unless File.ftype(file) == @ftype
|
339
|
+
end
|
340
|
+
|
341
|
+
if @group
|
342
|
+
if @group.is_a?(String)
|
343
|
+
if File::ALT_SEPARATOR
|
344
|
+
begin
|
345
|
+
next unless Sys::Admin.get_group(stat_info.gid, :LocalAccount => true).name == @group
|
346
|
+
rescue Sys::Admin::Error
|
347
|
+
next
|
348
|
+
end
|
349
|
+
else
|
350
|
+
begin
|
351
|
+
next unless Sys::Admin.get_group(stat_info.gid).name == @group
|
352
|
+
rescue Sys::Admin::Error
|
353
|
+
next
|
354
|
+
end
|
355
|
+
end
|
356
|
+
else
|
357
|
+
next unless stat_info.gid == @group
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
if @inum
|
362
|
+
next unless stat_info.ino == @inum
|
363
|
+
end
|
364
|
+
|
365
|
+
# Note that only 0644 and 0444 are supported on MS Windows.
|
366
|
+
if @perm
|
367
|
+
if @perm.is_a?(String)
|
368
|
+
octal_perm = sym2oct(@perm)
|
369
|
+
next unless stat_info.mode & octal_perm == octal_perm
|
370
|
+
else
|
371
|
+
next unless sprintf("%o", stat_info.mode & 07777) == sprintf("%o", @perm)
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
# Allow plain numbers, or strings for comparison operators.
|
376
|
+
if @size
|
377
|
+
if @size.is_a?(String)
|
378
|
+
regex = /^([><=]+)\s*?(\d+)$/
|
379
|
+
match = regex.match(@size)
|
380
|
+
|
381
|
+
if match.nil? || match.captures.include?(nil)
|
382
|
+
raise ArgumentError, "invalid size string: '#{@size}'"
|
383
|
+
end
|
384
|
+
|
385
|
+
operator = match.captures.first.strip
|
386
|
+
number = match.captures.last.strip.to_i
|
387
|
+
|
388
|
+
next unless stat_info.size.send(operator, number)
|
389
|
+
else
|
390
|
+
next unless stat_info.size == @size
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
if @user
|
395
|
+
if @user.is_a?(String)
|
396
|
+
if File::ALT_SEPARATOR
|
397
|
+
begin
|
398
|
+
next unless Sys::Admin.get_user(stat_info.uid, :LocalAccount => true).name == @user
|
399
|
+
rescue Sys::Admin::Error
|
400
|
+
next
|
401
|
+
end
|
402
|
+
else
|
403
|
+
begin
|
404
|
+
next unless Sys::Admin.get_user(stat_info.uid).name == @user
|
405
|
+
rescue Sys::Admin::Error
|
406
|
+
next
|
407
|
+
end
|
408
|
+
end
|
409
|
+
else
|
410
|
+
next unless stat_info.uid == @user
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
if block_given?
|
415
|
+
yield file
|
416
|
+
else
|
417
|
+
results << file
|
418
|
+
end
|
419
|
+
|
420
|
+
@previous = file unless @previous == file
|
421
|
+
}
|
422
|
+
rescue Errno::EACCES
|
423
|
+
next # Skip inaccessible directories
|
424
|
+
end
|
425
|
+
}
|
426
|
+
|
427
|
+
block_given? ? nil : results
|
428
|
+
end
|
429
|
+
|
430
|
+
# Limits searches to the same file system as the specified +mount_point+.
|
431
|
+
#
|
432
|
+
def mount=(mount_point)
|
433
|
+
@mount = mount_point
|
434
|
+
@filesystem = File.stat(mount_point).dev
|
435
|
+
end
|
436
|
+
|
437
|
+
private
|
438
|
+
|
439
|
+
# This validates that the keys are valid. If they are, it sets the value
|
440
|
+
# of that key's corresponding method to the given value. If a key ends
|
441
|
+
# with a '?', it's validated as a File method.
|
442
|
+
#
|
443
|
+
def validate_and_set_options(options)
|
444
|
+
options.each do |key, value|
|
445
|
+
key = key.to_s.downcase
|
446
|
+
|
447
|
+
if key[-1].chr == '?'
|
448
|
+
sym = key.to_sym
|
449
|
+
|
450
|
+
unless File.respond_to?(sym)
|
451
|
+
raise ArgumentError, "invalid option '#{key}'"
|
452
|
+
end
|
453
|
+
|
454
|
+
@filetest << [sym, value]
|
455
|
+
else
|
456
|
+
unless VALID_OPTIONS.include?(key)
|
457
|
+
raise ArgumentError, "invalid option '#{key}'"
|
458
|
+
end
|
459
|
+
|
460
|
+
send("#{key}=", value)
|
461
|
+
end
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
# Converts a symoblic permissions mode into its octal equivalent.
|
466
|
+
#--
|
467
|
+
# Taken almost entirely from ruby-talk: 96956 (Hal Fulton).
|
468
|
+
#
|
469
|
+
def sym2oct(str)
|
470
|
+
left = {'u' => 0700, 'g' => 0070, 'o' => 0007, 'a' => 0777}
|
471
|
+
right = {'r' => 0444, 'w' => 0222, 'x' => 0111}
|
472
|
+
regex = /([ugoa]+)([+-=])([rwx]+)/
|
473
|
+
|
474
|
+
cmds = str.split(',')
|
475
|
+
|
476
|
+
perm = 0
|
477
|
+
|
478
|
+
cmds.each do |cmd|
|
479
|
+
match = cmd.match(regex)
|
480
|
+
raise "Invalid symbolic permissions: '#{str}'" if match.nil?
|
481
|
+
|
482
|
+
who, what, how = match.to_a[1..-1]
|
483
|
+
|
484
|
+
who = who.split(//).inject(0) {|num, b| num |= left[b]; num}
|
485
|
+
how = how.split(//).inject(0) {|num, b| num |= right[b]; num}
|
486
|
+
mask = who & how
|
487
|
+
|
488
|
+
case what
|
489
|
+
when '+'
|
490
|
+
perm = perm | mask
|
491
|
+
when '-'
|
492
|
+
perm = perm & ~mask
|
493
|
+
when '='
|
494
|
+
perm = mask
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
perm
|
499
|
+
end
|
500
|
+
end
|
501
|
+
end
|
data/lib/trop/infogit.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
require_relative 'shell_deb_verb'
|
4
|
+
|
5
|
+
module Trop
|
6
|
+
module InfoGit
|
7
|
+
class User
|
8
|
+
attr_accessor :user_name, :user_email
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@user_name ||= `git config --get --global user.name`
|
12
|
+
@user_mail ||= `git config --get --global user.email`
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.user_name
|
16
|
+
initialize
|
17
|
+
@user_name.chomp!
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.user_mail
|
21
|
+
initialize
|
22
|
+
@user_mail.chomp!
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
class GitProject
|
28
|
+
|
29
|
+
def self.project_git_info(projectdir = '.')
|
30
|
+
Dir.chdir(File.absolute_path(projectdir)) do
|
31
|
+
@project_git_repo = `git config --get remote.origin.url`.chomp
|
32
|
+
@project_git_name = @project_git_repo.to_s.split('/').last.gsub(/.git$/, '') unless @project_git_repo.empty?
|
33
|
+
|
34
|
+
@project_username = `git config --get user.name`.chomp
|
35
|
+
@project_useremail = `git config --get user.email`.chomp
|
36
|
+
puts 'Project repo: #{@project_git_repo}'.blue if Sh.verbose?
|
37
|
+
|
38
|
+
return @project_git_name, @project_git_repo, @project_username, @project_useremail
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.commit_id
|
43
|
+
commit_id = `git show --format='%H' -q`
|
44
|
+
return commit_id
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/trop/os.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
module Trop
|
4
|
+
# OS detection lib
|
5
|
+
class OS
|
6
|
+
# @return true/false if 'on windows ?'
|
7
|
+
def self.win?
|
8
|
+
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return true/false if 'on mac?'
|
12
|
+
def self.mac?
|
13
|
+
(/darwin/ =~ RUBY_PLATFORM) != nil
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return true/false if 'on unix?'
|
17
|
+
def self.unix?
|
18
|
+
!::Trop::OS.win?
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return true/false if 'on tux?'
|
22
|
+
def self.linux?
|
23
|
+
::Trop::OS.unix? and not ::Trop::OS.mac?
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return true/false if 'on jruby?'
|
27
|
+
def self.jruby?
|
28
|
+
(RUBY_ENGINE == 'jruby')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
require 'rake/file_utils_ext'
|
3
|
+
require_relative 'core-ext'
|
4
|
+
|
5
|
+
#def bash_cmd(cmd)
|
6
|
+
# # sh <<-EOS.strip_heredoc, {verbose: false}
|
7
|
+
# sh <<-EOS << cmd
|
8
|
+
#/bin/bash -xeuo pipefail
|
9
|
+
#EOS
|
10
|
+
#end
|
11
|
+
|
12
|
+
# noinspection ALL
|
13
|
+
module Trop
|
14
|
+
class Sh
|
15
|
+
|
16
|
+
DEFAULT = false
|
17
|
+
@@verbose = false
|
18
|
+
@@debug = false
|
19
|
+
|
20
|
+
def self.verbose?
|
21
|
+
if Rake::FileUtilsExt.verbose_flag == true || (!ENV['VERBOSE'].nil? && ENV['VERBOSE'] == 'true') || !(ENV['DEBUG'].nil?)
|
22
|
+
@@verbose = true
|
23
|
+
end
|
24
|
+
return !!@@verbose
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.verbose!(mode = true)
|
28
|
+
if mode.false?
|
29
|
+
@@verbose = false
|
30
|
+
ENV['VERBOSE'] = nil
|
31
|
+
else
|
32
|
+
@@verbose = true
|
33
|
+
end
|
34
|
+
return !!@@verbose
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.silent!(mode = true)
|
38
|
+
return !::Trop::Sh.verbose!(!mode)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.silent?
|
42
|
+
return !(::Trop::Sh.verbose? || ::Trop::Sh.debug?)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.debug?
|
46
|
+
@@debug = true unless ENV['DEBUG'].nil?
|
47
|
+
@@debug = true if $DEBUG
|
48
|
+
return @@debug
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.debug!(mode = true)
|
52
|
+
if mode.false?
|
53
|
+
@@debug = false
|
54
|
+
ENV['DEBUG'] = nil
|
55
|
+
else
|
56
|
+
@@debug = true
|
57
|
+
end
|
58
|
+
return @@debug
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|