agile_utils 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +6 -0
- data/README.md +2 -2
- data/bin/agile_utils +0 -1
- data/lib/agile_utils.rb +0 -1
- data/lib/agile_utils/base_option.rb +34 -32
- data/lib/agile_utils/cli.rb +3 -5
- data/lib/agile_utils/file_util.rb +2 -12
- data/lib/agile_utils/helper.rb +8 -35
- data/lib/agile_utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f859098d2725f7d1a7e5266f444962509b4628cf
|
4
|
+
data.tar.gz: 60b292342f8eab2409285a9c27d5bfbb7c7be1c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d309c40b193b8b47a57bcd6867215f21ce3b31855269dbf7f807b0c34bb3d6144435f862fd5dac6b366717f4ee3382bd2f6464c7fd311babf8263e438b70c0eb
|
7
|
+
data.tar.gz: 4e1b069c620904bac94df517aa89ae54fa4c46c5e43826b32c176b8c33201dde57556b984b60a52ab6aef8b1bedd85b265fec32682c850f262827681a3007aea
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -39,8 +39,8 @@ include AgileUtils
|
|
39
39
|
|
40
40
|
# Then call the right method to use.
|
41
41
|
AgileUtils::Helper.capture
|
42
|
-
AgileUtils::Helper.
|
43
|
-
AgileUtils::Helper.
|
42
|
+
AgileUtils::Helper.linux?
|
43
|
+
AgileUtils::Helper.osx?
|
44
44
|
AgileUtils::Helper.make_list
|
45
45
|
AgileUtils::Helper.shell
|
46
46
|
AgileUtils::Helper.time
|
data/bin/agile_utils
CHANGED
data/lib/agile_utils.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require_relative "./agile_utils/core_ext/hash/hash"
|
2
2
|
require_relative "./agile_utils/core_ext/kernel/reporting"
|
3
|
-
require_relative "./agile_utils/constant"
|
4
3
|
require_relative "./agile_utils/version"
|
5
4
|
require_relative "./agile_utils/logger"
|
6
5
|
require_relative "./agile_utils/cli"
|
@@ -2,66 +2,68 @@ module AgileUtils
|
|
2
2
|
module Options
|
3
3
|
BASE_DIR = [
|
4
4
|
:base_dir,
|
5
|
-
{type:
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
{ type: :string,
|
6
|
+
aliases: "-b",
|
7
|
+
desc: "Base directory",
|
8
|
+
default: Dir.pwd
|
9
|
+
}
|
9
10
|
]
|
10
11
|
|
11
12
|
EXTS = [
|
12
13
|
:exts,
|
13
|
-
{type: :array,
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
{ type: :array,
|
15
|
+
aliases: "-e",
|
16
|
+
desc: "List of extensions to search for",
|
17
|
+
default: []
|
18
|
+
}
|
17
19
|
]
|
18
20
|
|
19
21
|
NON_EXTS = [
|
20
22
|
:non_exts,
|
21
|
-
{type: :array,
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
{ type: :array,
|
24
|
+
aliases: "-f",
|
25
|
+
desc: "List of files without extension to search for",
|
26
|
+
default: [] }
|
25
27
|
]
|
26
28
|
|
27
29
|
INC_WORDS = [
|
28
30
|
:inc_words,
|
29
|
-
{type: :array,
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
{ type: :array,
|
32
|
+
aliases: "-n",
|
33
|
+
desc: "List of words in the filename to be included with the result if any",
|
34
|
+
default: [] }
|
33
35
|
]
|
34
36
|
|
35
37
|
EXC_WORDS = [
|
36
38
|
:exc_words,
|
37
|
-
{type: :array,
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
{ type: :array,
|
40
|
+
aliases: "-x",
|
41
|
+
desc: "List of words in the filename to be excluded from the result if any",
|
42
|
+
default: [] }
|
41
43
|
]
|
42
44
|
|
43
45
|
IGNORE_CASE = [
|
44
46
|
:ignore_case,
|
45
|
-
{type: :boolean,
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
{ type: :boolean,
|
48
|
+
aliases: "-i",
|
49
|
+
desc: "Ignore the case in the input filename",
|
50
|
+
default: true }
|
49
51
|
]
|
50
52
|
|
51
53
|
RECURSIVE = [
|
52
54
|
:recursive,
|
53
|
-
{type: :boolean,
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
{ type: :boolean,
|
56
|
+
aliases: "-r",
|
57
|
+
desc: "Search for files recursively",
|
58
|
+
default: true }
|
57
59
|
]
|
58
60
|
|
59
61
|
VERSION = [
|
60
62
|
:version,
|
61
|
-
{type: :boolean,
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
{ type: :boolean,
|
64
|
+
aliases: "-v",
|
65
|
+
desc: "Display version information",
|
66
|
+
default: false }
|
65
67
|
]
|
66
68
|
end
|
67
69
|
end
|
data/lib/agile_utils/cli.rb
CHANGED
@@ -6,7 +6,7 @@ module AgileUtils
|
|
6
6
|
def main
|
7
7
|
opts = options.symbolize_keys
|
8
8
|
if opts[:version]
|
9
|
-
puts "You are using
|
9
|
+
puts "You are using AgileUtils version #{AgileUtils::VERSION}"
|
10
10
|
exit
|
11
11
|
end
|
12
12
|
end
|
@@ -19,14 +19,12 @@ include AgileUtils
|
|
19
19
|
|
20
20
|
# General methods
|
21
21
|
AgileUtils::Helper.capture
|
22
|
-
AgileUtils::Helper.is_linux?
|
23
|
-
AgileUtils::Helper.is_osx?
|
24
22
|
AgileUtils::Helper.make_list
|
25
23
|
AgileUtils::Helper.shell
|
24
|
+
AgileUtils::Helper.linux?
|
25
|
+
AgileUtils::Helper.osx?
|
26
26
|
AgileUtils::Helper.time
|
27
27
|
AgileUtils::Helper.uname
|
28
|
-
|
29
|
-
# File and related methods
|
30
28
|
AgileUtils::FileUtil.find()
|
31
29
|
AgileUtils::FileUtils.delete()
|
32
30
|
AgileUtils::FileUtils.gunzip()
|
@@ -15,6 +15,7 @@ module AgileUtils
|
|
15
15
|
# @param [String] extension the file extension to search for
|
16
16
|
#
|
17
17
|
# @return [Array<String>] list of matching files or empty list
|
18
|
+
# rubocop:disable CollectionMethods
|
18
19
|
def find(base_dir, extension = "xhtml")
|
19
20
|
file_paths = []
|
20
21
|
Find.find(base_dir) do |path|
|
@@ -22,6 +23,7 @@ module AgileUtils
|
|
22
23
|
end
|
23
24
|
file_paths
|
24
25
|
end
|
26
|
+
# rubocop:enable All
|
25
27
|
|
26
28
|
# Tar and gzip list of files
|
27
29
|
#
|
@@ -35,7 +37,6 @@ module AgileUtils
|
|
35
37
|
Archive::Tar::Minitar.pack_file(file, tar)
|
36
38
|
end
|
37
39
|
ensure
|
38
|
-
# Closes both tar and sgz.
|
39
40
|
tar.close unless tar.nil?
|
40
41
|
tar = nil
|
41
42
|
end
|
@@ -53,23 +54,12 @@ module AgileUtils
|
|
53
54
|
# Delete the files from the given list
|
54
55
|
#
|
55
56
|
# @param files list of files to be deleted
|
56
|
-
# @todo add ! to flag it as destructive!
|
57
57
|
def delete(files)
|
58
58
|
files.each do |file|
|
59
59
|
FileUtils.rm_rf(file)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
# Add suffix to each extensions
|
64
|
-
#
|
65
|
-
# @param [Array<String>] extensions list of extension
|
66
|
-
# @param [String] suffix the suffix string
|
67
|
-
#
|
68
|
-
# @return [Array<String>] new list with the suffix added to each element
|
69
|
-
def add_suffix(extensions = [], suffix)
|
70
|
-
extensions.map { |e| "#{e}.#{suffix}" }
|
71
|
-
end
|
72
|
-
|
73
63
|
# Time the operation before and after the operation for tuning purpose
|
74
64
|
def time
|
75
65
|
beg_time = Time.now
|
data/lib/agile_utils/helper.rb
CHANGED
@@ -5,8 +5,9 @@ module AgileUtils
|
|
5
5
|
class << self
|
6
6
|
# Wrapper function to call the 'popen3' and return the result
|
7
7
|
#
|
8
|
-
# @param [Array<String>] commands list of command
|
8
|
+
# @param [Array<String>] commands list of command and arguments to be executed
|
9
9
|
# @return [String] result of the command as the string
|
10
|
+
# @raise [RuntimeError] an exception to raise when the command result in error
|
10
11
|
def shell(commands = [])
|
11
12
|
begin
|
12
13
|
command = commands.join(" ")
|
@@ -17,47 +18,19 @@ module AgileUtils
|
|
17
18
|
stdin
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
-
|
21
|
+
def osx?
|
22
|
+
RbConfig::CONFIG["host_os"] =~ /darwin/
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
-
|
25
|
+
def linux?
|
26
|
+
RbConfig::CONFIG["host_os"] =~ /linux/
|
26
27
|
end
|
27
28
|
|
29
|
+
# Wrap the call to `uname` command
|
28
30
|
def uname
|
29
31
|
shell(%w[uname])
|
30
32
|
end
|
31
33
|
|
32
|
-
# Extract "key1: value1\nkey2: value 2" to
|
33
|
-
# hash of { "key1" => "value1", "key2" => "value 2" }
|
34
|
-
#
|
35
|
-
# @param [String] input the input string from the unix command
|
36
|
-
# @return [Hash<Symbol,String>] result hash extracted from the command
|
37
|
-
# @todo re-implement the code and look for specific list of keys and quit
|
38
|
-
# as fast as we get the specific list of keys
|
39
|
-
def string_to_hash(input)
|
40
|
-
hash = {}
|
41
|
-
input.split('\n').each do |i|
|
42
|
-
# TODO: code smell?
|
43
|
-
item = i.split(":") if is_linux?
|
44
|
-
item = i.split("=") if is_osx?
|
45
|
-
next if item.empty? || item.size != 2
|
46
|
-
hash[item[0].strip] = item[1].strip
|
47
|
-
end
|
48
|
-
hash
|
49
|
-
end
|
50
|
-
|
51
|
-
# Add suffix to each item in the list
|
52
|
-
#
|
53
|
-
# @param [Array<String>] list the input list
|
54
|
-
# @param [String] suffix the suffix string
|
55
|
-
# @return [Array<String.] list of input where each element is append with
|
56
|
-
# suffix string
|
57
|
-
def add_suffix(list = [], suffix)
|
58
|
-
list.map { |e| "#{e}.#{suffix}" }
|
59
|
-
end
|
60
|
-
|
61
34
|
# For tuning the operation
|
62
35
|
def time
|
63
36
|
beg_time = Time.now
|
@@ -95,7 +68,7 @@ module AgileUtils
|
|
95
68
|
|
96
69
|
# Cross-platform way of finding an executable in the $PATH.
|
97
70
|
#
|
98
|
-
# @param
|
71
|
+
# @param [String] command the command to look up
|
99
72
|
# @return [String, NilClass] full path to the executable file or nil if the
|
100
73
|
# executable is not valid or available.
|
101
74
|
# Example:
|
data/lib/agile_utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agile_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burin Choomnuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|