eco-helpers 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eco/api/session.rb +3 -1
- data/lib/eco/api/usecases/default_cases/change_email_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/create_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/create_details_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/create_details_with_supervisor_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/hris_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/new_email_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/new_id_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/recover_db_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/remove_account_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/set_supervisor_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/update_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/update_details_case.rb +1 -1
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +1 -1
- data/lib/eco/scripting.rb +4 -2
- data/lib/eco/scripting/args_helpers.rb +53 -0
- data/lib/eco/scripting/argument.rb +29 -0
- data/lib/eco/scripting/arguments.rb +60 -32
- data/lib/eco/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4f70377026306ed8ee7e6bb8629bb765b92ea310b41a75dddb586cc398d5f5b
|
4
|
+
data.tar.gz: 2a25b0c4114c3b68943308e7475989a93cf8055ac59f9ff0e00173b02f2b3386
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62c5f462a9121215a5a7d45a084084b088c314544cba21dabeb0e15a4c386288b6b136a3c7bc7436f9974d84a5c3418df93803409d6637f17dde0bac8024ae27
|
7
|
+
data.tar.gz: 3e16c7ed28eeb72da9783cbbda1c4e44c3452aee7ee0eeb1c41855189f0d53f1d96dcf3caf68fc3e9eeefbd42ee9c5c63c84ee51e8b0c8e9e6c50d9d9bdcc8cb
|
data/lib/eco/api/session.rb
CHANGED
@@ -10,7 +10,7 @@ module Eco
|
|
10
10
|
change = session.job_group("main").new("change email", type: :update, sets: :core)
|
11
11
|
add_account = session.job_group("post").new("add account", type: :update, sets: :account)
|
12
12
|
|
13
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
13
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
14
14
|
|
15
15
|
entries.each.with_index do |entry, i|
|
16
16
|
person = people.find(entry, strict: strict_search)
|
@@ -8,7 +8,7 @@ module Eco
|
|
8
8
|
@cases.define("create", type: :sync) do |entries, people, session, options|
|
9
9
|
creation = session.job_group("main").new("create", type: :create, sets: [:core, :details, :account])
|
10
10
|
|
11
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
11
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
12
12
|
pgs = session.policy_groups
|
13
13
|
|
14
14
|
entries.each.with_index do |entry, i|
|
@@ -25,7 +25,7 @@ module Eco
|
|
25
25
|
ini_tags = person.account&.filter_tags || []
|
26
26
|
entry.set_account(person)
|
27
27
|
|
28
|
-
person.account
|
28
|
+
person.account&.send_invites = options[:send_invites] if options.key?(:send_invites)
|
29
29
|
|
30
30
|
person.account.policy_group_ids = pgs.user_pg_ids(
|
31
31
|
initial: ini_pg_ids,
|
@@ -8,7 +8,7 @@ module Eco
|
|
8
8
|
@cases.define("create-details", type: :sync) do |entries, people, session, options|
|
9
9
|
creation = session.job_group("main").new("create", type: :create, sets: [:core, :details])
|
10
10
|
|
11
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
11
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
12
12
|
|
13
13
|
entries.each.with_index do |entry, i|
|
14
14
|
if person = people.find(entry, strict: strict_search)
|
@@ -10,7 +10,7 @@ module Eco
|
|
10
10
|
creation = session.job_group("main").new("create", type: :create, sets: [:core, :details])
|
11
11
|
supers = session.job_group("post").new("supers", type: :update, sets: :core)
|
12
12
|
|
13
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
13
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
14
14
|
|
15
15
|
entries.each.with_index do |entry, i|
|
16
16
|
if person = people.find(entry, strict: strict_search)
|
@@ -24,7 +24,7 @@ module Eco
|
|
24
24
|
# end
|
25
25
|
#end
|
26
26
|
|
27
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
27
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
28
28
|
|
29
29
|
entries.each.with_index do |entry, i|
|
30
30
|
person = people.find(entry, strict: strict_search)
|
@@ -8,7 +8,7 @@ module Eco
|
|
8
8
|
@cases.define("new-email", type: :sync) do |entries, people, session, options|
|
9
9
|
job = session.job_group("main").new("update", type: :update, sets: :core)
|
10
10
|
|
11
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
11
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
12
12
|
|
13
13
|
entries.each.with_index do |entry, i|
|
14
14
|
if person = people.find(entry, strict: strict_search)
|
@@ -8,7 +8,7 @@ module Eco
|
|
8
8
|
@cases.define("new-id", type: :sync) do |entries, people, session, options|
|
9
9
|
job = session.job_group("main").new("update", type: :update, sets: :core)
|
10
10
|
|
11
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
11
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
12
12
|
|
13
13
|
entries.each.with_index do |entry, i|
|
14
14
|
if person = people.find(entry, strict: strict_search)
|
@@ -14,7 +14,7 @@ module Eco
|
|
14
14
|
update = session.job_group("main").new("update", type: :update, sets: [:core, :details, :account])
|
15
15
|
remove = session.job_group("main").new("remove", type: :delete, sets: [:core, :details, :account])
|
16
16
|
|
17
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
17
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
18
18
|
pgs = session.policy_groups
|
19
19
|
|
20
20
|
if options.dig(:include, :delete)
|
@@ -17,7 +17,7 @@ module Eco
|
|
17
17
|
@cases.define("remove-account", type: :sync) do |entries, people, session, options|
|
18
18
|
update = session.job_group("main").new("update", type: :update, sets: [:core, :account])
|
19
19
|
|
20
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
20
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
21
21
|
|
22
22
|
entries.each.with_index do |entry, i|
|
23
23
|
if person = people.find(entry, strict: strict_search)
|
@@ -8,7 +8,7 @@ module Eco
|
|
8
8
|
@cases.define("set-supervisor", type: :sync) do |entries, people, session, options|
|
9
9
|
job = session.job_group("main").new("update", type: :update, sets: :core)
|
10
10
|
|
11
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
11
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
12
12
|
|
13
13
|
entries.each.with_index do |entry, i|
|
14
14
|
person = people.find(entry, strict: strict_search)
|
@@ -18,7 +18,7 @@ module Eco
|
|
18
18
|
@cases.define("update", type: :sync) do |entries, people, session, options|
|
19
19
|
update = session.job_group("main").new("update", type: :update, sets: [:core, :details, :account])
|
20
20
|
|
21
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
21
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
22
22
|
pgs = session.policy_groups
|
23
23
|
|
24
24
|
entries.each.with_index do |entry, i|
|
@@ -8,7 +8,7 @@ module Eco
|
|
8
8
|
@cases.define("update-details", type: :sync) do |entries, people, session, options|
|
9
9
|
job = session.job_group("main").new("update", type: :update, sets: [:core, :details])
|
10
10
|
|
11
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
11
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
12
12
|
|
13
13
|
entries.each.with_index do |entry, i|
|
14
14
|
if person = people.find(entry, strict: strict_search)
|
@@ -10,7 +10,7 @@ module Eco
|
|
10
10
|
update = session.job_group("main").new("update", type: :update, sets: [:core, :details, :account])
|
11
11
|
supers = session.job_group("post").new("supers", type: :update, sets: :core)
|
12
12
|
|
13
|
-
strict_search = session.config.people.strict_search? || options.dig(:search, :strict)
|
13
|
+
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
|
14
14
|
pgs = session.policy_groups
|
15
15
|
|
16
16
|
entries.each.with_index do |entry, i|
|
data/lib/eco/scripting.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'scripting/args_helpers'
|
2
|
+
require_relative 'scripting/argument'
|
3
|
+
require_relative 'scripting/arguments'
|
2
4
|
|
3
5
|
module Eco
|
4
6
|
#TODO integrate Thor to build the CLI from bottom to top on load
|
5
7
|
class Scripting
|
6
|
-
include Scripting::
|
8
|
+
include Scripting::ArgsHelpers
|
7
9
|
|
8
10
|
def args_contain?(*values)
|
9
11
|
match?(ARGV, patterns, [:any, :or, :insensitive, :pattern])
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Eco
|
2
|
+
class Scripting
|
3
|
+
module ArgsHelpers
|
4
|
+
|
5
|
+
def is_modifier?(value)
|
6
|
+
value&.start_with?("-")
|
7
|
+
end
|
8
|
+
|
9
|
+
def arguments
|
10
|
+
@arguments ||= Arguments.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def stop_on_unknown!(exclude: [])
|
14
|
+
if arguments.any_unkown?(exclude: exclude)
|
15
|
+
raise "There are unkown options in your command line arguments: #{arguments.unknown(exclude: exclude)}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_arg(key, with_param: false, valid: true)
|
20
|
+
# track what a known option looks like
|
21
|
+
arguments.add(key, with_param: with_param)
|
22
|
+
return nil if !ARGV.include?(key)
|
23
|
+
value = true
|
24
|
+
if with_param
|
25
|
+
next_i = ARGV.index(key) + 1
|
26
|
+
value = ARGV[next_i]
|
27
|
+
#puts "modifier argument: #{value}"
|
28
|
+
value = nil if valid && is_modifier?(value)
|
29
|
+
end
|
30
|
+
return value
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_file(key, required: false, should_exist: true)
|
34
|
+
filename = get_arg(key, with_param: true)
|
35
|
+
if !filename
|
36
|
+
if required
|
37
|
+
puts "you need to specify a file '#{key} file'"
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
elsif !(File.exists?(filename) || File.exists?(File.expand_path(filename)))
|
41
|
+
if should_exist && required
|
42
|
+
puts "file doesn't exist #{filename}"
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
filename = File.expand_path(filename) if filename && should_exist
|
48
|
+
filename
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Eco
|
2
|
+
class Scripting
|
3
|
+
class Argument
|
4
|
+
|
5
|
+
attr_reader :key
|
6
|
+
|
7
|
+
def initialize(key, with_param: false)
|
8
|
+
@key = key
|
9
|
+
@with_param = !!with_param
|
10
|
+
end
|
11
|
+
|
12
|
+
def args_slice(*args)
|
13
|
+
#pp "known arg '#{key}' => included? #{args.include?(key)}"
|
14
|
+
return args unless args.include?(key)
|
15
|
+
i = args.index(key)
|
16
|
+
j = with_param?? i+1 : i
|
17
|
+
args - args.slice(i..j)
|
18
|
+
end
|
19
|
+
|
20
|
+
def with_param!
|
21
|
+
@with_param = true
|
22
|
+
end
|
23
|
+
|
24
|
+
def with_param?
|
25
|
+
@with_param
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,40 +1,68 @@
|
|
1
1
|
module Eco
|
2
2
|
class Scripting
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
3
|
+
class Arguments
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
attr_reader :args
|
7
|
+
|
8
|
+
def initialize(args = ARGV)
|
9
|
+
@args = args
|
10
|
+
@known = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def each(params: {}, &block)
|
14
|
+
return to_enum(:each) unless block
|
15
|
+
@known.values.each(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def add(key, with_param: false)
|
19
|
+
self << Argument.new(key, with_param: with_param)
|
20
|
+
end
|
21
|
+
|
22
|
+
def <<(arg)
|
23
|
+
raise "Expected Argument. Given #{arg.class}" unless arg.is_a?(Argument)
|
24
|
+
if karg = @known[arg.key]
|
25
|
+
#puts "Found already existent option #{arg.key} (with_param: arg.with_param?)"
|
26
|
+
karg.with_param! if arg.with_param?
|
27
|
+
else
|
28
|
+
#puts "Adding unexistent option #{arg.key}"
|
29
|
+
@known[arg.key] = arg
|
30
|
+
end
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def known?(value)
|
35
|
+
@known.key?(to_key(value))
|
36
|
+
end
|
37
|
+
|
38
|
+
def keys
|
39
|
+
@known.keys
|
40
|
+
end
|
41
|
+
|
42
|
+
def unknown(exclude: [])
|
43
|
+
reduce(args.dup - exclude) do |not_known, arg|
|
44
|
+
arg.args_slice(*not_known)
|
32
45
|
end
|
46
|
+
end
|
33
47
|
|
34
|
-
|
35
|
-
|
48
|
+
def any_unkown?(exclude: [])
|
49
|
+
unknown(exclude: exclude).length > 0
|
36
50
|
end
|
37
|
-
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def to_key(value)
|
55
|
+
case value
|
56
|
+
when String
|
57
|
+
value
|
58
|
+
when Argument
|
59
|
+
value.key
|
60
|
+
else
|
61
|
+
"Missuse: only able to transform to key a String or an Argument. Given #{value.class}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
38
66
|
end
|
39
67
|
end
|
40
68
|
end
|
data/lib/eco/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eco-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
@@ -405,6 +405,8 @@ files:
|
|
405
405
|
- lib/eco/language/values_at.rb
|
406
406
|
- lib/eco/scripting.rb
|
407
407
|
- lib/eco/scripting/README.md
|
408
|
+
- lib/eco/scripting/args_helpers.rb
|
409
|
+
- lib/eco/scripting/argument.rb
|
408
410
|
- lib/eco/scripting/arguments.rb
|
409
411
|
- lib/eco/tester.rb
|
410
412
|
- lib/eco/version.rb
|