eco-helpers 0.6.4 → 0.6.5
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/.yardopts +10 -0
- data/eco-helpers.gemspec +2 -2
- data/lib/eco/api/organization/tag_tree.rb +11 -11
- data/lib/eco/api/session/batch.rb +3 -8
- data/lib/eco/api/usecases/default_cases.rb +6 -2
- data/lib/eco/api/usecases/default_cases/create_case.rb +60 -0
- data/lib/eco/api/usecases/default_cases/switch_supervisor_case.rb +3 -4
- data/lib/eco/api/usecases/default_cases/update_case.rb +58 -0
- data/lib/eco/api/usecases/default_cases/upsert_case.rb +61 -0
- data/lib/eco/cli.rb +1 -2
- data/lib/eco/cli/api.rb +14 -0
- data/lib/eco/cli/root.rb +1 -0
- data/lib/eco/common.rb +1 -0
- data/lib/eco/common/base_cli.rb +6 -99
- data/lib/eco/common/base_cli_backup.rb +119 -0
- data/lib/eco/common/meta_thor.rb +111 -0
- data/lib/eco/common/meta_thor/command_group.rb +36 -0
- data/lib/eco/common/meta_thor/command_unit.rb +48 -0
- data/lib/eco/common/meta_thor/input_backup.rb +111 -0
- data/lib/eco/common/meta_thor/input_multi_backup.rb +139 -0
- data/lib/eco/common/meta_thor/pipe.rb +85 -0
- data/lib/eco/common/meta_thor/thor.rb +1 -0
- data/lib/eco/common/meta_thor/thor/command.rb +36 -0
- data/lib/eco/common/meta_thor/value.rb +54 -0
- data/lib/eco/version.rb +1 -1
- metadata +16 -4
- data/lib/eco/api/usecases/default_cases/upsert_account_case.rb +0 -35
- data/lib/eco/cli/input.rb +0 -109
- data/lib/eco/cli/input_multi.rb +0 -137
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa7eb2714d4b0510dcc62b6b42b50835d4f5db4c
|
4
|
+
data.tar.gz: 0d241a6411f68297029028633051e818e08b1d2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d8d8b78d842472624a89de3c4a78095417f83f42b89c797a0fdd1124aaea9718dc614a448d2391c99bc2ca0a5a2b91f491d6b8656e3f5306a37a191d542b49b
|
7
|
+
data.tar.gz: 66eda21ef4862e5cf470312e4dbec32540287c8a3a5b8be34b56cd0b92301f0bfd22732d2f41f5714cc0d19cdd795f419d6d07e13b21d6432f93d26243119874
|
data/.yardopts
ADDED
data/eco-helpers.gemspec
CHANGED
@@ -22,8 +22,8 @@ Gem::Specification.new do |s|
|
|
22
22
|
#s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
23
|
s.require_paths = ["lib"]
|
24
24
|
|
25
|
-
s.add_development_dependency "rspec",
|
26
|
-
s.add_development_dependency "yard",
|
25
|
+
s.add_development_dependency "rspec", "~> 3", ">= 3.8"
|
26
|
+
s.add_development_dependency "yard", "~> 0.9", ">= 0.9.18"
|
27
27
|
s.add_development_dependency "redcarpet", "~> 3.4", ">= 3.4.0"
|
28
28
|
|
29
29
|
s.add_dependency 'ecoportal-api', '~> 0.3', '>= 0.3.6'
|
@@ -13,7 +13,7 @@ module Eco
|
|
13
13
|
# [[Node], ...]
|
14
14
|
# @example Input format example:
|
15
15
|
# tree = [{"tag" => "AUSTRALIA", "nodes" => [
|
16
|
-
# {"tag" => "
|
16
|
+
# {"tag" => "SYDNEY", "nodes" => []}
|
17
17
|
# ]}]
|
18
18
|
# tree = TagTree.new(tree.to_json)
|
19
19
|
# @param tagtree [String] representation of the tagtree in json.
|
@@ -69,8 +69,8 @@ module Eco
|
|
69
69
|
list.select {|str| tag?(str)}
|
70
70
|
end
|
71
71
|
|
72
|
-
# Finds the path from a node `key` to
|
73
|
-
#
|
72
|
+
# Finds the path from a node `key` to its root node in the tree.
|
73
|
+
# If `key` is not specified, returns the path from current node to root.
|
74
74
|
# @note the `path` is not relative to the subtree, but absolute to the entire tree.
|
75
75
|
# @param key [String] tag to find the path to.
|
76
76
|
# @return [Array<String>]
|
@@ -84,18 +84,18 @@ module Eco
|
|
84
84
|
#
|
85
85
|
# @example Usage example:
|
86
86
|
# tree = [{"tag" => "Australia", "nodes" => [
|
87
|
-
# {"tag" => "
|
88
|
-
# {"tag" => "
|
87
|
+
# {"tag" => "SYDNEY", "nodes" => []},
|
88
|
+
# {"tag" => "MELBOURNE", "nodes" => []}
|
89
89
|
# ]}]
|
90
90
|
#
|
91
91
|
# tree = TagTree.new(tree.to_json)
|
92
|
-
# original = ["
|
93
|
-
# final = ["
|
92
|
+
# original = ["SYDNEY", "RISK"]
|
93
|
+
# final = ["MELBOURNE", "EVENT"]
|
94
94
|
#
|
95
|
-
# tree.user_tags(initial: original, final: final) # out: ["
|
96
|
-
# tree.user_tags(initial: original, final: final, preserve_custom: false) # out: ["
|
97
|
-
# tree.user_tags(initial: original, final: final, add_custom: true) # out: ["
|
98
|
-
# tree.user_tags(initial: original, final: final, preserve_custom: false, add_custom: true) # out: ["
|
95
|
+
# tree.user_tags(initial: original, final: final) # out: ["MELBOURNE", "RISK"]
|
96
|
+
# tree.user_tags(initial: original, final: final, preserve_custom: false) # out: ["MELBOURNE"]
|
97
|
+
# tree.user_tags(initial: original, final: final, add_custom: true) # out: ["MELBOURNE", "RISK", "EVENT"]
|
98
|
+
# tree.user_tags(initial: original, final: final, preserve_custom: false, add_custom: true) # out: ["MELBOURNE", "EVENT"]
|
99
99
|
#
|
100
100
|
# @param initial [Array<String>] original tags a person has in their account.
|
101
101
|
# @param final [Array<String>] target tags the person should have in their account afterwards.
|
@@ -24,15 +24,10 @@ module Eco
|
|
24
24
|
batch_from(people, method, api || self.api, params: params)
|
25
25
|
end
|
26
26
|
|
27
|
-
def valid_methods
|
28
|
-
VALID_METHODS
|
29
|
-
end
|
30
|
-
|
31
27
|
def valid_method?(value)
|
32
28
|
VALID_METHODS.include?(value)
|
33
29
|
end
|
34
30
|
|
35
|
-
|
36
31
|
private
|
37
32
|
|
38
33
|
def new_status(queue, method)
|
@@ -49,7 +44,7 @@ module Eco
|
|
49
44
|
params = {per_page: DEFAULT_BATCH_BLOCK}.merge(params)
|
50
45
|
client = people_api.client
|
51
46
|
people = [];
|
52
|
-
if
|
47
|
+
if page = params[:page]
|
53
48
|
res, response = get(client, params: params)
|
54
49
|
people +=res
|
55
50
|
logger.info("page number: #{page}, got num people #{people.length}")
|
@@ -79,7 +74,7 @@ module Eco
|
|
79
74
|
end
|
80
75
|
people = []
|
81
76
|
response.body["results"].each do |person_hash|
|
82
|
-
person =
|
77
|
+
person = Ecoportal::API::Internal::Person.new(person_hash)
|
83
78
|
yield person if block_given?
|
84
79
|
people.push(person)
|
85
80
|
end
|
@@ -102,7 +97,7 @@ module Eco
|
|
102
97
|
per_page = params.fetch(:per_page)
|
103
98
|
|
104
99
|
iteration = 1; done = 0
|
105
|
-
iterations = (people.length / per_page).ceil
|
100
|
+
iterations = (people.length.to_f / per_page).ceil
|
106
101
|
|
107
102
|
people.each_slice(per_page) do |slice|
|
108
103
|
msg = "starting batch '#{method}' iteration #{iteration}/#{iterations}, with #{slice.length} entries of #{people.length} -- #{done} done"
|
@@ -27,7 +27,9 @@ module Eco
|
|
27
27
|
RefreshPresets.new(self).process
|
28
28
|
ChangeEMailCase.new(self).process
|
29
29
|
SetDefaultTagCase.new(self).process
|
30
|
-
|
30
|
+
CreateCase.new(self).process
|
31
|
+
UpdateCase.new(self).process
|
32
|
+
UpsertCase.new(self).process
|
31
33
|
HrisCase.new(self).process
|
32
34
|
end
|
33
35
|
end
|
@@ -51,5 +53,7 @@ require_relative 'default_cases/remove_account_case'
|
|
51
53
|
require_relative 'default_cases/refresh_presets'
|
52
54
|
require_relative 'default_cases/change_email_case'
|
53
55
|
require_relative 'default_cases/set_default_tag_case'
|
54
|
-
require_relative 'default_cases/
|
56
|
+
require_relative 'default_cases/create_case'
|
57
|
+
require_relative 'default_cases/update_case'
|
58
|
+
require_relative 'default_cases/upsert_case'
|
55
59
|
require_relative 'default_cases/hris_case'
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class CreateCase < UseCases::BaseCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
@cases.define("create", type: :sync) do |entries, people, session, options|
|
9
|
+
creation = session.job_group("main").new("create", type: :create, sets: [:core, :details, :account])
|
10
|
+
|
11
|
+
pgs = session.policy_groups
|
12
|
+
|
13
|
+
entries.each.with_index do |entry, i|
|
14
|
+
if person = people.find(entry)
|
15
|
+
session.logger.error("Entry(#{i}) - this person (id: '#{person.id}') already exists: #{entry.to_s(:identify)}")
|
16
|
+
else
|
17
|
+
person = session.new_person
|
18
|
+
core_excluded = ["supervisor_id"]
|
19
|
+
entry.set_core(person, exclude: core_excluded)
|
20
|
+
entry.set_details(person) unless options.dig(:exclude, :details)
|
21
|
+
|
22
|
+
unless options.dig(:exclude, :account)
|
23
|
+
ini_pg_ids = person.account&.policy_group_ids || []
|
24
|
+
ini_tags = person.account&.filter_tags || []
|
25
|
+
entry.set_account(person)
|
26
|
+
|
27
|
+
person.account.send_invites = false if options.key?(:send_invites) && !options(:send_invites)
|
28
|
+
|
29
|
+
person.account.policy_group_ids = pgs.user_pg_ids(
|
30
|
+
initial: ini_pg_ids,
|
31
|
+
final: person.account.policy_group_ids
|
32
|
+
)
|
33
|
+
|
34
|
+
person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities)
|
35
|
+
|
36
|
+
if session.tagtree
|
37
|
+
person.account.filter_tags = session.tagtree.user_tags(
|
38
|
+
initial: ini_tags,
|
39
|
+
final: person.account.filter_tags,
|
40
|
+
preserve_custom: true,
|
41
|
+
add_custom: true
|
42
|
+
)
|
43
|
+
person.account.default_tag = session.tagtree.default_tag(*person.account.filter_tags)
|
44
|
+
else
|
45
|
+
tags = person.account.filter_tags
|
46
|
+
person.account.default_tag = tags.first unless tags.length > 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
creation.add(person)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -18,16 +18,15 @@ module Eco
|
|
18
18
|
exit
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
pp new_id = options.dig(:super, :new)
|
21
|
+
new_id = options.dig(:super, :new)
|
23
22
|
|
24
23
|
unless old_sup = people.person(id: old_id, external_id: old_id, email: old_id)
|
25
|
-
session.logger.error("Couldn't find any user with that id: '#{old_id}'. Aborting...")
|
24
|
+
session.logger.error("Couldn't find any user with that id (old-super): '#{old_id}'. Aborting...")
|
26
25
|
exit
|
27
26
|
end
|
28
27
|
|
29
28
|
unless new_sup = people.person(id: new_id, external_id: new_id, email: new_id)
|
30
|
-
session.logger.error("Couldn't find any user with that id: '#{new_id}'. Aborting...")
|
29
|
+
session.logger.error("Couldn't find any user with that id (new-super): '#{new_id}'. Aborting...")
|
31
30
|
exit
|
32
31
|
end
|
33
32
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class UpdateCase < BaseCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
@cases.define("update", type: :sync) do |entries, people, session, options|
|
9
|
+
update = session.job_group("main").new("update", type: :update, sets: [:core, :details, :account])
|
10
|
+
|
11
|
+
pgs = session.policy_groups
|
12
|
+
|
13
|
+
entries.each.with_index do |entry, i|
|
14
|
+
if person = people.find(entry)
|
15
|
+
core_excluded = ["supervisor_id"]
|
16
|
+
core_excluded.push("email") if options.dig(:exclude, :email)
|
17
|
+
entry.set_core(person, exclude: core_excluded) unless options.dig(:exclude, :core)
|
18
|
+
entry.set_details(person) unless options.dig(:exclude, :details)
|
19
|
+
|
20
|
+
unless options.dig(:exclude, :account)
|
21
|
+
ini_pg_ids = person.account&.policy_group_ids || []
|
22
|
+
ini_tags = person.account&.filter_tags || []
|
23
|
+
entry.set_account(person)
|
24
|
+
|
25
|
+
person.account.policy_group_ids = pgs.user_pg_ids(
|
26
|
+
initial: ini_pg_ids,
|
27
|
+
final: person.account.policy_group_ids
|
28
|
+
)
|
29
|
+
|
30
|
+
person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities)
|
31
|
+
|
32
|
+
if session.tagtree
|
33
|
+
person.account.filter_tags = session.tagtree.user_tags(
|
34
|
+
initial: ini_tags,
|
35
|
+
final: person.account.filter_tags,
|
36
|
+
preserve_custom: true,
|
37
|
+
add_custom: true
|
38
|
+
)
|
39
|
+
person.account.default_tag = session.tagtree.default_tag(*person.account.filter_tags)
|
40
|
+
else
|
41
|
+
tags = person.account.filter_tags
|
42
|
+
person.account.default_tag = tags.first unless tags.length > 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
update.add(person)
|
46
|
+
else
|
47
|
+
session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
module UseCases
|
4
|
+
class DefaultCases
|
5
|
+
class UpsertCase < BaseCase
|
6
|
+
|
7
|
+
def process
|
8
|
+
@cases.define("upsert", type: :sync) do |entries, people, session, options|
|
9
|
+
creation = session.job_group("main").new("create", type: :create, sets: [:core, :details, :account])
|
10
|
+
update = session.job_group("main").new("update", type: :update, sets: [:core, :details, :account])
|
11
|
+
|
12
|
+
pgs = session.policy_groups
|
13
|
+
|
14
|
+
entries.each.with_index do |entry, i|
|
15
|
+
create = ! (person = people.find(entry))
|
16
|
+
person = session.new_person if create
|
17
|
+
|
18
|
+
core_excluded = ["supervisor_id"]
|
19
|
+
core_excluded.push("email") if options.dig(:exclude, :email) && !create
|
20
|
+
entry.set_core(person, exclude: core_excluded) unless options.dig(:exclude, :core) && !create
|
21
|
+
entry.set_details(person) unless options.dig(:exclude, :details)
|
22
|
+
|
23
|
+
unless options.dig(:exclude, :account)
|
24
|
+
ini_pg_ids = person.account&.policy_group_ids || []
|
25
|
+
ini_tags = person.account&.filter_tags || []
|
26
|
+
entry.set_account(person)
|
27
|
+
|
28
|
+
person.account.send_invites = false if options.key?(:send_invites) && !options(:send_invites)
|
29
|
+
|
30
|
+
person.account.policy_group_ids = pgs.user_pg_ids(
|
31
|
+
initial: ini_pg_ids,
|
32
|
+
final: person.account.policy_group_ids
|
33
|
+
)
|
34
|
+
|
35
|
+
person.account.permissions_custom = session.new_preset(person) unless options.dig(:exclude, :abilities)
|
36
|
+
|
37
|
+
if session.tagtree
|
38
|
+
person.account.filter_tags = session.tagtree.user_tags(
|
39
|
+
initial: ini_tags,
|
40
|
+
final: person.account.filter_tags,
|
41
|
+
preserve_custom: true,
|
42
|
+
add_custom: true
|
43
|
+
)
|
44
|
+
person.account.default_tag = session.tagtree.default_tag(*person.account.filter_tags)
|
45
|
+
else
|
46
|
+
tags = person.account.filter_tags
|
47
|
+
person.account.default_tag = tags.first unless tags.length > 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
creation.add(person) if create
|
52
|
+
update.add(person) unless create
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/eco/cli.rb
CHANGED
data/lib/eco/cli/api.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Eco
|
2
|
+
module CLI
|
3
|
+
class API < Eco::Common::BaseCLI
|
4
|
+
class_option :csv_in, :type => :string, :banner => "FILE", :desc => "CSV input file"
|
5
|
+
class_option :csv_out, :type => :string, :banner => "FILE", :desc => "CSV output file"
|
6
|
+
class_option :json_in, :type => :string, :banner => "FILE", :desc => "CSV input file"
|
7
|
+
class_option :json_out, :type => :string, :banner => "FILE", :desc => "CSV input file"
|
8
|
+
|
9
|
+
class_option :config_file, :aliases => "o", :type => :string,
|
10
|
+
:banner => "FILE", :desc => "specifes the session configuration file"
|
11
|
+
#class_option :csv_in, :alisaes =>
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/eco/cli/root.rb
CHANGED
data/lib/eco/common.rb
CHANGED
data/lib/eco/common/base_cli.rb
CHANGED
@@ -1,114 +1,21 @@
|
|
1
|
-
require 'thor'
|
2
|
-
|
3
1
|
module Eco
|
4
2
|
module Common
|
5
|
-
class BaseCLI <
|
6
|
-
PIPE = "!"
|
3
|
+
class BaseCLI < MetaThor
|
7
4
|
CUSTOM_HELP_MAPPINGS = ["?", "help"]
|
8
5
|
ALL_HELP_MAPPINGS = Thor::HELP_MAPPINGS + CUSTOM_HELP_MAPPINGS
|
9
6
|
|
10
7
|
class_option :simulate, type: :boolean, aliases: :s, desc: "do not launch updates or rewrite files"
|
11
|
-
class_option :verbosity, type: :numeric, default: 0, desc: "defines the level of verbosity to show feedback"
|
12
|
-
|
13
|
-
class_option :input, type: :hash, default: {}, required: false, desc: "--input=json:STRING"
|
14
|
-
|
15
|
-
def self.start(given_args = ARGV, config = {})
|
16
|
-
#given_args = splat_namespaces(given_args)
|
17
|
-
given_args = BaseCLI.parse_help(given_args)
|
18
|
-
super(given_args, config)
|
19
|
-
end
|
20
|
-
|
21
|
-
# incompatible with options / arguments of Hash type
|
22
|
-
# see: parse_hash here: https://github.com/erikhuda/thor/blob/master/lib/thor/parser/arguments.rb
|
23
|
-
def self.splat_namespaces(args)
|
24
|
-
args.reduce([]) do |done, arg|
|
25
|
-
done.concat(arg.split(":"))
|
26
|
-
end
|
27
|
-
end
|
8
|
+
#class_option :verbosity, type: :numeric, default: 0, desc: "defines the level of verbosity to show feedback"
|
28
9
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
if args.length > 1 && help?(last)
|
33
|
-
# switch last and second last position
|
34
|
-
last = "help" if custom_help?(last)
|
35
|
-
args.insert(args.length - 2, last).pop
|
36
|
-
puts "> #{args.join(" ")}"
|
10
|
+
class << self
|
11
|
+
def start(given_args = ARGV, config = {})
|
12
|
+
super(given_args, config)
|
37
13
|
end
|
38
|
-
args
|
39
14
|
end
|
40
|
-
|
41
|
-
def self.help?(value)
|
42
|
-
case value
|
43
|
-
when String
|
44
|
-
ALL_HELP_MAPPINGS.include?(value)
|
45
|
-
when Symbol
|
46
|
-
help?(value.to_s)
|
47
|
-
when Array
|
48
|
-
value.any? { |v| help?(v) }
|
49
|
-
when Hash
|
50
|
-
value.keys.any { |k| help?(v) }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.custom_help?(value)
|
55
|
-
CUSTOM_HELP_MAPPINGS.include?(value)
|
56
|
-
end
|
57
|
-
|
15
|
+
|
58
16
|
protected
|
59
17
|
|
60
18
|
no_commands do
|
61
|
-
def input?(options)
|
62
|
-
options&.key?("input") || options&.key?(:input)
|
63
|
-
end
|
64
|
-
|
65
|
-
def input_object(input)
|
66
|
-
Eco::CLI::Input.new(input)
|
67
|
-
end
|
68
|
-
|
69
|
-
def input(value)
|
70
|
-
case
|
71
|
-
when value.is_a?(Eco::CLI::Input)
|
72
|
-
value.value
|
73
|
-
when value.is_a?(Eco::CLI::MultiInput)
|
74
|
-
value.to_h
|
75
|
-
when value.is_a?(String)
|
76
|
-
input(JSON.parse(value))
|
77
|
-
when value&.key?("input")
|
78
|
-
input(value["input"])
|
79
|
-
when value&.key?(:input)
|
80
|
-
input(value[:input])
|
81
|
-
when value&.key?("json")
|
82
|
-
JSON.parse(value["json"])
|
83
|
-
when value&.key?(:json)
|
84
|
-
JSON.parse(value[:json])
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def pipe(input, args)
|
89
|
-
command, args, pipe = parse_pipe(args)
|
90
|
-
invoke command, args, {input: input_object(input)} if pipe
|
91
|
-
pipe
|
92
|
-
end
|
93
|
-
|
94
|
-
def parse_pipe(args)
|
95
|
-
args.shift if pipe = (args.first == PIPE)
|
96
|
-
subcommand = ""
|
97
|
-
if pipe
|
98
|
-
raise "Error: bad usage of pipe ('|'). Expected: '| command' " unless subcommand = args.slice!(0)
|
99
|
-
if help?(subcommand)
|
100
|
-
# Idea adapted from: https://stackoverflow.com/a/46167300/4352306
|
101
|
-
self.class.command_help(Thor::Base.shell.new, args.first)
|
102
|
-
exit
|
103
|
-
end
|
104
|
-
end
|
105
|
-
[subcommand, args, pipe]
|
106
|
-
end
|
107
|
-
|
108
|
-
def help?(value)
|
109
|
-
BaseCLI.help?(value)
|
110
|
-
end
|
111
|
-
|
112
19
|
end
|
113
20
|
|
114
21
|
end
|