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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a2c5373e513f2c43cd593684e28011ce9b0646a4457e19c31a5590f5cac0d743
4
- data.tar.gz: d1985d695d0a8c390593a76f6cc65dbf8ebcbb584f6b1e6fd0032706be6c4299
3
+ metadata.gz: e4f70377026306ed8ee7e6bb8629bb765b92ea310b41a75dddb586cc398d5f5b
4
+ data.tar.gz: 2a25b0c4114c3b68943308e7475989a93cf8055ac59f9ff0e00173b02f2b3386
5
5
  SHA512:
6
- metadata.gz: 4101d84e2d20cdc95459277316177570af81d1fd9ef38aadba6f41d7df424a093d12619efaf4a811cc2374cb812235f86a3602ebf18b26ef8d33cfe469d5c89b
7
- data.tar.gz: 25b6df7e98d964fb7b53685fa98f31eb0983138b8a3754404d5dd5704669adf69fee0bbe91162eca35234b0fcf5b6af09b3d053c995e9470371b2d880758d2f9
6
+ metadata.gz: 62c5f462a9121215a5a7d45a084084b088c314544cba21dabeb0e15a4c386288b6b136a3c7bc7436f9974d84a5c3418df93803409d6637f17dde0bac8024ae27
7
+ data.tar.gz: 3e16c7ed28eeb72da9783cbbda1c4e44c3452aee7ee0eeb1c41855189f0d53f1d96dcf3caf68fc3e9eeefbd42ee9c5c63c84ee51e8b0c8e9e6c50d9d9bdcc8cb
@@ -141,7 +141,9 @@ module Eco
141
141
  end
142
142
 
143
143
  def entries(*args)
144
- @entry_factory.entries(*args)
144
+ @entry_factory.entries(*args).tap do |collection|
145
+ logger.info("Loaded #{collection.length} input entries.")
146
+ end
145
147
  end
146
148
 
147
149
  def export(*args)
@@ -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.send_invites = false if options.key?(:send_invites) && !options(:send_invites)
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|
@@ -1,9 +1,11 @@
1
- require_relative './scripting/arguments'
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::Lib
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
- module Lib
4
- def is_modifier?(value)
5
- value&.start_with?("-")
6
- end
7
-
8
- def get_arg(key, with_param: false, valid: true)
9
- return nil if !ARGV.include?(key)
10
- value = true
11
- if with_param
12
- next_i = ARGV.index(key) + 1
13
- value = ARGV[next_i]
14
- #puts "modifier argument: #{value}"
15
- value = nil if valid && is_modifier?(value)
16
- end
17
- return value
18
- end
19
-
20
- def get_file(key, required: false, should_exist: true)
21
- filename = get_arg(key, with_param: true)
22
- if !filename
23
- if required
24
- puts "you need to specify a file '#{key} file'"
25
- exit
26
- end
27
- elsif !(File.exists?(filename) || File.exists?(File.expand_path(filename)))
28
- if should_exist && required
29
- puts "file doesn't exist #{filename}"
30
- exit
31
- end
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
- filename = File.expand_path(filename) if filename && should_exist
35
- filename
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
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
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.1
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