tools 0.4.5 → 0.4.6
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/.rubocop.yml +11 -0
- data/Gemfile +1 -1
- data/Rakefile +9 -15
- data/aux2 +1 -5
- data/bin/tools +29 -37
- data/lib/files/requireds.rb +0 -2
- data/lib/lib/array.rb +45 -65
- data/lib/lib/cache.rb +11 -18
- data/lib/lib/config.rb +47 -76
- data/lib/lib/console.rb +92 -108
- data/lib/lib/display.rb +10 -29
- data/lib/lib/files.rb +26 -44
- data/lib/lib/hash.rb +21 -22
- data/lib/lib/log.rb +28 -32
- data/lib/lib/net.rb +58 -80
- data/lib/lib/object.rb +8 -7
- data/lib/lib/prompt.rb +24 -26
- data/lib/lib/string.rb +15 -15
- data/lib/lib/utils.rb +90 -66
- data/lib/tools.rb +3 -8
- data/lib/tools/version.rb +2 -2
- data/test/mini_array.rb +7 -12
- data/test/mini_cache.rb +9 -12
- data/test/mini_config.rb +21 -12
- data/test/mini_console.rb +6 -8
- data/test/mini_display.rb +6 -9
- data/test/mini_file.rb +20 -24
- data/test/mini_hash.rb +27 -38
- data/test/mini_log.rb +2 -4
- data/test/mini_net.rb +167 -185
- data/test/mini_object.rb +16 -21
- data/test/mini_prompt.rb +28 -16
- data/test/mini_string.rb +11 -14
- data/test/mini_utils.rb +13 -16
- data/test/run +9 -9
- data/tools.gemspec +12 -14
- metadata +35 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de676d58cf2e9d530a137126d4889ee97548464d5fab8be7b557625cefe69e2f
|
4
|
+
data.tar.gz: 94d0bb63e9f471d3bc8896e91711de2a15877144a02e18593dbb22465946e824
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93d1d598688624b7b187fcc909718252b8630071b5ccf65fbe0802555090ffd2318544a00de4e8f90c6529b4a741bbdcbe76cb2ba620d3f5b4f587946a91cb26
|
7
|
+
data.tar.gz: 282fe27e88c0ce4e916efdb669acecb69de02f846f9354b7414670b94b3b01e4b1c0279c594fdb530fe26eaf728f3773bc494bc6fc75cbfca5f58fda43ba48d8
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,15 +1,11 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
|
4
1
|
require 'bundler/gem_helper'
|
5
|
-
Bundler::GemHelper.install_tasks :
|
2
|
+
Bundler::GemHelper.install_tasks name: 'tools'
|
6
3
|
|
7
|
-
#require 'bundler/gem_tasks'
|
4
|
+
# require 'bundler/gem_tasks'
|
8
5
|
require_relative 'lib/tools/version'
|
9
6
|
|
10
|
-
|
11
7
|
# Default.
|
12
|
-
task :
|
8
|
+
task default: :help
|
13
9
|
|
14
10
|
# Help.
|
15
11
|
desc 'Help'
|
@@ -26,7 +22,7 @@ task :dev do
|
|
26
22
|
|
27
23
|
Rake::Task['install'].invoke
|
28
24
|
|
29
|
-
source = File.dirname(File.absolute_path
|
25
|
+
source = File.dirname(File.absolute_path(__FILE__))
|
30
26
|
target = "#{ENV['GEM_HOME']}/gems/tools-#{Tools::VERSION}"
|
31
27
|
target_bin = "#{ENV['GEM_HOME']}/bin/tools"
|
32
28
|
system("rm -f #{target_bin}")
|
@@ -37,16 +33,14 @@ task :dev do
|
|
37
33
|
puts 'You may now start editing and testing files from within this repo.'
|
38
34
|
end
|
39
35
|
|
40
|
-
|
41
|
-
desc "Release the gem in rubygems (DEV)"
|
36
|
+
desc 'Release the gem in rubygems (DEV)'
|
42
37
|
task :push do
|
43
|
-
gem_file
|
38
|
+
gem_file = "#{ENV['PWD']}/pkg/tools-#{Tools::VERSION}.gem"
|
44
39
|
gem_server_url = 'https://rubygems.org'
|
45
40
|
system("gem push #{gem_file} --host #{gem_server_url}")
|
46
41
|
end
|
47
42
|
|
48
|
-
|
49
|
-
desc "Run all minitests."
|
43
|
+
desc 'Run all minitests.'
|
50
44
|
task :mini do
|
51
|
-
system(
|
52
|
-
end
|
45
|
+
system('./test/minitest/run')
|
46
|
+
end
|
data/aux2
CHANGED
data/bin/tools
CHANGED
@@ -1,30 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
3
|
require 'tools'
|
4
4
|
require 'thor'
|
5
5
|
|
6
|
-
Signal.trap(
|
6
|
+
Signal.trap('INT') do
|
7
7
|
puts "\n\tNote: You will typically use Signal.trap instead.\n".light_red
|
8
8
|
exit
|
9
|
-
|
9
|
+
end
|
10
10
|
|
11
|
-
Signal.trap(
|
11
|
+
Signal.trap('TERM') do
|
12
12
|
puts "\n\tNote: You will typically use Signal.trap instead.\n".light_red
|
13
13
|
exit
|
14
|
-
|
14
|
+
end
|
15
15
|
|
16
16
|
load Tools.files + '/requireds.rb'
|
17
17
|
|
18
18
|
class Tools_exec < Thor
|
19
|
-
|
20
19
|
desc 'help', ''
|
21
|
-
def help(
|
20
|
+
def help(_command = '')
|
22
21
|
puts "\tHELP will be here..... Coming soon....".light_green
|
23
|
-
|
24
22
|
end
|
25
23
|
|
26
24
|
desc 'show', ''
|
27
|
-
def show(
|
25
|
+
def show(_command = '')
|
28
26
|
puts "Gem_path.: #{Tools.gem_path}"
|
29
27
|
puts "Ldap_pass.: #{Tools.ldap_pass}"
|
30
28
|
puts "Ldap_user.: #{Tools.ldap_user}"
|
@@ -36,8 +34,8 @@ class Tools_exec < Thor
|
|
36
34
|
|
37
35
|
desc 'config', ''
|
38
36
|
def config
|
39
|
-
|
40
|
-
|
37
|
+
ap 'config'
|
38
|
+
# ToolsConfig.config
|
41
39
|
end
|
42
40
|
|
43
41
|
desc 'exec', ''
|
@@ -49,34 +47,28 @@ class Tools_exec < Thor
|
|
49
47
|
desc 'console', ''
|
50
48
|
def console
|
51
49
|
ap 'console'
|
52
|
-
#ToolsConsole.create_console
|
53
|
-
#ToolsConsole.run_console
|
50
|
+
# ToolsConsole.create_console
|
51
|
+
# ToolsConsole.run_console
|
54
52
|
end
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
ToolsDisplay.show "export ldap_user=<your_ldap_login> ".fix(65,'.'), :cyan
|
74
|
-
ToolsDisplay.show "export ldap_pass=<your_ldap_password>".fix(65,'.'), :cyan
|
75
|
-
|
76
|
-
|
77
|
-
exit()
|
54
|
+
def method_missing(_method, *_args)
|
55
|
+
# ap method
|
56
|
+
# ap args.extract_option '-v', false #=> 8
|
57
|
+
# ap args.extract_option '-x' #=> true
|
58
|
+
# ap args.extract_option '-f' #=> false
|
59
|
+
# ap args.extract_symbol :json #=> true
|
60
|
+
# ap args.extract_symbol :yaml #=> false
|
61
|
+
# ap args.extract_color #=> :yellow
|
62
|
+
# ap args.extract_color #=> red
|
63
|
+
# ap args.extract_option_value '--class' #=> 'tools'
|
64
|
+
# ap args #=> [-c -vcv -v2 -s ]
|
65
|
+
|
66
|
+
ToolsDisplay.show 'To export ldap variables use: '.fix(60, '.'), :cyan
|
67
|
+
ToolsDisplay.show 'export ldap_user=<your_ldap_login> '.fix(65, '.'), :cyan
|
68
|
+
ToolsDisplay.show 'export ldap_pass=<your_ldap_password>'.fix(65, '.'), :cyan
|
69
|
+
|
70
|
+
exit
|
78
71
|
end
|
79
|
-
|
80
72
|
end
|
81
73
|
|
82
74
|
begin
|
@@ -86,4 +78,4 @@ rescue SystemExit => e
|
|
86
78
|
exit(e.status)
|
87
79
|
rescue Exception => e
|
88
80
|
puts e
|
89
|
-
end
|
81
|
+
end
|
data/lib/files/requireds.rb
CHANGED
data/lib/lib/array.rb
CHANGED
@@ -1,54 +1,42 @@
|
|
1
1
|
class Array
|
2
|
-
|
3
2
|
# Self pop first element.
|
4
3
|
# @return first element
|
5
4
|
def extract_first
|
6
5
|
first = self[0]
|
7
|
-
|
8
|
-
|
6
|
+
delete_at(0)
|
7
|
+
first
|
9
8
|
end
|
10
9
|
|
11
10
|
# Self extract symbol.
|
12
11
|
# @param symbol to retrive
|
13
12
|
# @return boolean
|
14
|
-
def extract_symbol
|
13
|
+
def extract_symbol(symbol)
|
15
14
|
status = false
|
16
|
-
if
|
15
|
+
if include? symbol
|
17
16
|
status = true
|
18
|
-
|
17
|
+
delete(symbol)
|
19
18
|
end
|
20
|
-
|
19
|
+
status
|
21
20
|
end
|
22
21
|
|
23
22
|
# Self extract color.
|
24
23
|
# @return boolean
|
25
24
|
def extract_color
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
if argument.string?
|
37
|
-
if argument.start_with? ':'
|
38
|
-
color_candidate = argument.gsub(':','').to_sym
|
39
|
-
color = color_candidate if colors.include? color_candidate
|
40
|
-
self.delete(argument)
|
41
|
-
return color
|
42
|
-
end
|
43
|
-
end
|
25
|
+
each do |argument|
|
26
|
+
if argument.symbol? && String.colors.include?(argument)
|
27
|
+
color = argument
|
28
|
+
delete(argument)
|
29
|
+
return color
|
30
|
+
elsif argument.string? && argument.start_with?(':')
|
31
|
+
color_candidate = argument.gsub(':', '').to_sym
|
32
|
+
color = color_candidate if String.colors.include? color_candidate
|
33
|
+
delete(argument)
|
34
|
+
return color
|
44
35
|
end
|
45
36
|
end
|
46
|
-
|
37
|
+
:default
|
47
38
|
end
|
48
39
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
40
|
# Self extract option.
|
53
41
|
# @param option to extract.
|
54
42
|
# @param single boolean to repeat
|
@@ -65,67 +53,59 @@ class Array
|
|
65
53
|
# args.extract_color => red
|
66
54
|
# args => [-c -vcv -v2 -s ]
|
67
55
|
#
|
68
|
-
def extract_option
|
56
|
+
def extract_option(option, single = true)
|
69
57
|
if single
|
70
58
|
result = false
|
71
|
-
if
|
59
|
+
if include? option
|
72
60
|
index = self.index(option)
|
73
|
-
|
61
|
+
delete_at(index)
|
74
62
|
result = true
|
75
63
|
end
|
76
64
|
else
|
77
65
|
result = 0
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
66
|
+
each do |argument|
|
67
|
+
next unless argument.to_s.start_with? option
|
68
|
+
# puts "'#{option}' '#{argument}' #{argument.start_with? option} \n"
|
69
|
+
search_char = option.sub('-', '')
|
70
|
+
aux_string = argument.to_s.sub('-', '')
|
71
|
+
count = argument.to_s.count(search_char)
|
72
|
+
if count == aux_string.size
|
73
|
+
result += count
|
74
|
+
# self.delete(argument)
|
88
75
|
end
|
89
|
-
|
90
76
|
end
|
91
77
|
end
|
92
|
-
|
78
|
+
result
|
93
79
|
end
|
94
80
|
|
95
|
-
def extract_option_value
|
81
|
+
def extract_option_value(option, args = {})
|
82
|
+
args[:multiple] = false if args[:multiple].nil?
|
96
83
|
|
97
|
-
if args[:
|
98
|
-
args[:multiple] = false
|
99
|
-
end
|
100
|
-
|
101
|
-
if args[:separator].nil?
|
102
|
-
args[:separator] = '='
|
103
|
-
end
|
84
|
+
args[:separator] = '=' if args[:separator].nil?
|
104
85
|
|
105
86
|
result = false
|
106
87
|
if args[:multiple]
|
107
88
|
multiple_value = []
|
108
|
-
while
|
89
|
+
while include? option
|
109
90
|
index = self.index(option)
|
110
|
-
|
91
|
+
delete_at(index)
|
111
92
|
result = true
|
112
|
-
value =
|
113
|
-
multiple_value <<
|
114
|
-
multiple_value <<
|
115
|
-
|
93
|
+
value = at(index)
|
94
|
+
multiple_value << at(index).split(args[:separator]).first
|
95
|
+
multiple_value << at(index).split(args[:separator]).last
|
96
|
+
delete_at(index)
|
116
97
|
end
|
117
98
|
return [result, multiple_value]
|
118
99
|
else
|
119
|
-
value
|
120
|
-
while
|
100
|
+
value = nil
|
101
|
+
while include? option
|
121
102
|
index = self.index(option)
|
122
|
-
|
103
|
+
delete_at(index)
|
123
104
|
result = true
|
124
|
-
value =
|
125
|
-
|
105
|
+
value = at(index)
|
106
|
+
delete_at(index)
|
126
107
|
end
|
127
108
|
return [result, value]
|
128
109
|
end
|
129
110
|
end
|
130
|
-
|
131
|
-
end
|
111
|
+
end
|
data/lib/lib/cache.rb
CHANGED
@@ -2,9 +2,7 @@ require 'singleton'
|
|
2
2
|
class ToolsCache
|
3
3
|
include Singleton
|
4
4
|
|
5
|
-
def initialize(options = {})
|
6
|
-
end
|
7
|
-
|
5
|
+
def initialize(options = {}); end
|
8
6
|
|
9
7
|
# Create a cache file in work area
|
10
8
|
#
|
@@ -12,12 +10,11 @@ class ToolsCache
|
|
12
10
|
# @param cache_file
|
13
11
|
# @param ttl
|
14
12
|
# @return
|
15
|
-
def self.create_cache_file
|
13
|
+
def self.create_cache_file(cache_name, cache_file, ttl = nil)
|
16
14
|
cache = Persistent::Cache.new(cache_file, ttl)
|
17
15
|
ToolsUtil.set_variable "#{cache_name}_cache", cache
|
18
16
|
end
|
19
17
|
|
20
|
-
|
21
18
|
# Add a record in a cache work area
|
22
19
|
#
|
23
20
|
# Sample
|
@@ -41,8 +38,7 @@ class ToolsCache
|
|
41
38
|
# @param args
|
42
39
|
# @param block
|
43
40
|
# @return
|
44
|
-
def self.method_missing(method, *args
|
45
|
-
|
41
|
+
def self.method_missing(method, *args)
|
46
42
|
cache_name = method.to_s.split('_').first
|
47
43
|
cache_method = method.to_s.split('_').last
|
48
44
|
cache = ToolsUtil.get_variable "#{cache_name}_cache"
|
@@ -52,16 +48,14 @@ class ToolsCache
|
|
52
48
|
when 'set'
|
53
49
|
key = args.extract_first
|
54
50
|
values = args.extract_first
|
55
|
-
|
56
|
-
cache[key] = values
|
57
|
-
else
|
51
|
+
if cache.key?(key)
|
58
52
|
aux = cache[key]
|
59
53
|
case aux.class.to_s
|
60
54
|
when 'Hash'
|
61
55
|
begin
|
62
56
|
aux.merge! values
|
63
57
|
cache[key] = aux
|
64
|
-
rescue
|
58
|
+
rescue StandardError => e
|
65
59
|
ToolsDisplay.show "\tError in ToolsCache: #{e.exception}", :light_yellow
|
66
60
|
exit
|
67
61
|
end
|
@@ -70,15 +64,17 @@ class ToolsCache
|
|
70
64
|
case values.class.to_s
|
71
65
|
when 'Array'
|
72
66
|
values.each do |value|
|
73
|
-
aux.insert(-1,value)
|
67
|
+
aux.insert(-1, value)
|
74
68
|
end
|
75
69
|
cache[key] = aux
|
76
70
|
else
|
77
|
-
aux.insert(-1,values)
|
71
|
+
aux.insert(-1, values)
|
78
72
|
cache[key] = aux
|
79
73
|
end
|
80
74
|
end
|
81
75
|
|
76
|
+
else
|
77
|
+
cache[key] = values
|
82
78
|
end
|
83
79
|
|
84
80
|
# when 'set'
|
@@ -125,12 +121,9 @@ class ToolsCache
|
|
125
121
|
return result
|
126
122
|
|
127
123
|
when 'clear'
|
128
|
-
|
124
|
+
cache.each do |key|
|
129
125
|
cache[key] = nil
|
130
126
|
end
|
131
127
|
end
|
132
|
-
|
133
128
|
end
|
134
|
-
|
135
|
-
|
136
|
-
end
|
129
|
+
end
|