dtk-client 0.5.14 → 0.5.15
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 +5 -13
- data/lib/commands/common/thor/assembly_workspace.rb +95 -0
- data/lib/commands/common/thor/common.rb +7 -4
- data/lib/commands/common/thor/edit.rb +1 -1
- data/lib/commands/common/thor/inventory_parser.rb +78 -0
- data/lib/commands/common/thor/pull_from_remote.rb +14 -10
- data/lib/commands/common/thor/push_to_remote.rb +0 -21
- data/lib/commands/thor/account.rb +2 -2
- data/lib/commands/thor/component_module.rb +45 -42
- data/lib/commands/thor/library.rb +2 -1
- data/lib/commands/thor/provider.rb +42 -36
- data/lib/commands/thor/service.rb +39 -30
- data/lib/commands/thor/service_module.rb +59 -60
- data/lib/commands/thor/target.rb +85 -15
- data/lib/commands/thor/workspace.rb +1 -1
- data/lib/config/disk_cacher.rb +4 -1
- data/lib/configurator.rb +1 -8
- data/lib/core.rb +4 -2
- data/lib/domain/response.rb +13 -2
- data/lib/dtk-client/version.rb +1 -1
- data/lib/dtk_logger.rb +4 -4
- data/lib/shell/context.rb +96 -77
- data/lib/shell/help_monkey_patch.rb +19 -17
- data/lib/util/os_util.rb +12 -12
- data/lib/util/remote_dependency_util.rb +36 -0
- data/lib/util/ssh_util.rb +2 -1
- data/spec/component_module_spec.rb +34 -0
- data/spec/dtk_spec.rb +1 -1
- data/spec/node_template_spec.rb +0 -1
- data/spec/service_module_spec.rb +38 -0
- data/spec/service_spec.rb +20 -11
- metadata +12 -16
- data/spec/assembly_spec.rb +0 -50
- data/spec/assembly_template_spec.rb +0 -51
- data/spec/component_template_spec.rb +0 -40
- data/spec/module_spec.rb +0 -35
- data/spec/node_spec.rb +0 -43
data/lib/dtk_logger.rb
CHANGED
@@ -25,7 +25,7 @@ class DtkLogger
|
|
25
25
|
file = File.open(file_path(), "a")
|
26
26
|
file.sync = true
|
27
27
|
@logger = Logger.new(file, LOG_NUMBER_OF_OLD_FILES, LOG_MB_SIZE * 1024000)
|
28
|
-
|
28
|
+
|
29
29
|
@logger.formatter = proc do |severity, datetime, progname, msg|
|
30
30
|
"[#{datetime}] #{severity} -- : #{msg}\n"
|
31
31
|
end
|
@@ -63,14 +63,14 @@ class DtkLogger
|
|
63
63
|
|
64
64
|
def error_pp(message, backtrace, sttdout_out = true)
|
65
65
|
error(message, sttdout_out)
|
66
|
-
# we do not print this to STDOUT (will be overriden with DEVELOPMENT_MODE)
|
67
|
-
error(PP.pp(backtrace, ""), false) if backtrace
|
66
|
+
# we do not print this to STDOUT (will be overriden with DEVELOPMENT_MODE)s
|
67
|
+
error("#{message}\n" + PP.pp(backtrace, ""), false) if backtrace
|
68
68
|
end
|
69
69
|
|
70
70
|
def fatal_pp(message, backtrace, sttdout_out = true)
|
71
71
|
fatal(message, sttdout_out)
|
72
72
|
# we do not print this to STDOUT (will be overriden with DEVELOPMENT_MODE)
|
73
|
-
fatal(PP.pp(backtrace, ""), false) if backtrace
|
73
|
+
fatal("#{message}\n" + PP.pp(backtrace, ""), false) if backtrace
|
74
74
|
end
|
75
75
|
|
76
76
|
|
data/lib/shell/context.rb
CHANGED
@@ -7,7 +7,7 @@ module DTK
|
|
7
7
|
|
8
8
|
class Context
|
9
9
|
include DTK::Client::Auxiliary
|
10
|
-
|
10
|
+
|
11
11
|
# client commands
|
12
12
|
CLIENT_COMMANDS = ['cc','exit','clear','pushc','popc','dirs','help']
|
13
13
|
# CLIENT_COMMANDS = ['cc','exit','clear','help']
|
@@ -80,7 +80,7 @@ module DTK
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
entries
|
85
85
|
end
|
86
86
|
|
@@ -96,7 +96,7 @@ module DTK
|
|
96
96
|
init_context = context_list.first.name
|
97
97
|
command_clazz = Context.get_command_class(init_context)
|
98
98
|
invisible_context = command_clazz.respond_to?(:invisible_context) ? command_clazz.invisible_context() : {}
|
99
|
-
|
99
|
+
|
100
100
|
invisible_context.each do |ic|
|
101
101
|
path = path.gsub(/\/#{ic}\//,'/')
|
102
102
|
end
|
@@ -104,7 +104,7 @@ module DTK
|
|
104
104
|
|
105
105
|
path
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
# Validates and changes context
|
109
109
|
def change_context(args, cmd=[])
|
110
110
|
begin
|
@@ -123,7 +123,7 @@ module DTK
|
|
123
123
|
|
124
124
|
# jump to root
|
125
125
|
reset if args.join('').match(/^\//)
|
126
|
-
|
126
|
+
|
127
127
|
# begin
|
128
128
|
# hack: used just to avoid entering assembly/id/node or workspace/node context (remove when include this contexts again)
|
129
129
|
first_c, warning_message = nil, nil
|
@@ -163,34 +163,52 @@ module DTK
|
|
163
163
|
active_context_copy.clear if goes_from_root
|
164
164
|
# Invalid context is user leftover to be matched; i.e. 'cc /assembly/te' - 'te' is leftover
|
165
165
|
invalid_context = ""
|
166
|
-
|
166
|
+
|
167
167
|
# Validate and change context; skip step if user's input is empty or it is equal to '/'
|
168
168
|
active_context_copy, error_message, invalid_context = prepare_context_change([readline_input], active_context_copy, nil, line_buffer) unless (readline_input.empty? || readline_input == "/")
|
169
|
-
|
169
|
+
|
170
170
|
# using extended_context when we want to use autocomplete from other context
|
171
|
-
# e.g. we are in assembly/apache context and want to create-component we will use extended context to add
|
171
|
+
# e.g. we are in assembly/apache context and want to create-component we will use extended context to add
|
172
172
|
# component-templates to autocomplete
|
173
|
-
extended_candidates, new_context = {}, nil
|
173
|
+
extended_candidates, new_context, line_buffer_first = {}, nil, nil
|
174
174
|
command_clazz = Context.get_command_class(active_context_copy.last_command_name)
|
175
|
-
|
175
|
+
# require 'debugger'
|
176
|
+
# Debugger.start
|
177
|
+
# debugger
|
178
|
+
# unless (line_buffer.empty? || line_buffer.strip().empty?)
|
179
|
+
# line_buffer_last = line_buffer.split(' ').last
|
180
|
+
# line_buffer = line_buffer.split(' ').first
|
181
|
+
# line_buffer.gsub!('-','_') unless (line_buffer.nil? || line_buffer.empty?)
|
182
|
+
# end
|
183
|
+
|
176
184
|
unless (line_buffer.empty? || line_buffer.strip().empty?)
|
177
|
-
line_buffer = line_buffer.split(' ')
|
178
|
-
|
185
|
+
line_buffer = line_buffer.split(' ')
|
186
|
+
line_buffer_last = line_buffer.last
|
187
|
+
line_buffer_first = line_buffer.first
|
188
|
+
line_buffer_first.gsub!('-','_') unless (line_buffer_first.nil? || line_buffer_first.empty?)
|
179
189
|
end
|
180
190
|
|
181
191
|
unless command_clazz.nil?
|
182
192
|
extended_context = command_clazz.respond_to?(:extended_context) ? command_clazz.extended_context() : {}
|
183
|
-
|
193
|
+
|
184
194
|
unless extended_context.empty?
|
185
195
|
extended_context = extended_context[:context]
|
186
|
-
extended_context.reject!{|k,v| k.to_s!=line_buffer}
|
187
|
-
|
188
|
-
|
196
|
+
# extended_context.reject!{|k,v| k.to_s!=line_buffer}
|
197
|
+
# extended_context.select!{|k,v| k.to_s.eql?(line_buffer_first) || k.to_s.eql?(line_buffer_last)}
|
198
|
+
extended_context.select!{|k,v| line_buffer.include?(k.to_s)} if extended_context.respond_to?(:select!)
|
199
|
+
|
200
|
+
if (extended_context[line_buffer_last] && !line_buffer_first.eql?(line_buffer_last))
|
201
|
+
new_context = extended_context[line_buffer_last]
|
202
|
+
elsif (extended_context[line_buffer[line_buffer.size-2]] && !line_buffer_first.eql?(extended_context[line_buffer[line_buffer.size-2]]))
|
203
|
+
new_context = extended_context[line_buffer[line_buffer.size-2]]
|
204
|
+
else
|
205
|
+
new_context = extended_context[line_buffer_first.to_sym] unless line_buffer_first.nil? || line_buffer_first.empty?
|
206
|
+
end
|
189
207
|
active_context_copy.push_new_context(new_context, new_context) unless new_context.nil?
|
190
208
|
end
|
191
209
|
end
|
192
|
-
|
193
|
-
return get_ac_candidates(active_context_copy, readline_input, invalid_context, goes_from_root,
|
210
|
+
|
211
|
+
return get_ac_candidates(active_context_copy, readline_input, invalid_context, goes_from_root, line_buffer_first||{})
|
194
212
|
end
|
195
213
|
|
196
214
|
# TODO: this is hack used this to hide 'node' context and use just node_identifier
|
@@ -210,7 +228,7 @@ module DTK
|
|
210
228
|
command_from_args = goes_from_root ? args.first.split('/')[1] : args.first.split('/').first
|
211
229
|
clazz_from_args = DTK::Shell::Context.get_command_class(command_from_args) if command_from_args
|
212
230
|
end
|
213
|
-
|
231
|
+
|
214
232
|
if (command.eql?('cd') || command.eql?('cc') || command.eql?('popc') || command.eql?('pushc'))
|
215
233
|
if is_root
|
216
234
|
if entries.size >= 3
|
@@ -224,7 +242,7 @@ module DTK
|
|
224
242
|
end
|
225
243
|
else
|
226
244
|
double_dots_count = DTK::Shell::ContextAux.count_double_dots(entries)
|
227
|
-
|
245
|
+
|
228
246
|
unless double_dots_count > 0
|
229
247
|
if clazz.respond_to?(:invisible_context)
|
230
248
|
if current_context.is_command?
|
@@ -251,7 +269,7 @@ module DTK
|
|
251
269
|
end
|
252
270
|
|
253
271
|
end
|
254
|
-
|
272
|
+
|
255
273
|
entries
|
256
274
|
end
|
257
275
|
|
@@ -270,9 +288,9 @@ module DTK
|
|
270
288
|
current_context_clazz, error_message, current_index = nil, nil, 0
|
271
289
|
double_dots_count = DTK::Shell::ContextAux.count_double_dots(entries)
|
272
290
|
|
273
|
-
# we remove '..' from our entries
|
291
|
+
# we remove '..' from our entries
|
274
292
|
entries = entries.select { |e| !(e.empty? || DTK::Shell::ContextAux.is_double_dot?(e)) }
|
275
|
-
|
293
|
+
|
276
294
|
# we go back in context based on '..'
|
277
295
|
active_context_copy.pop_context(double_dots_count)
|
278
296
|
|
@@ -287,23 +305,23 @@ module DTK
|
|
287
305
|
count_workspaces = active_context_copy.name_list.inject(Hash.new(0)) {|h,i| h[i] += 1; h }
|
288
306
|
active_context_copy.pop_context(1) if count_workspaces['workspace']==1
|
289
307
|
end
|
290
|
-
|
308
|
+
|
291
309
|
# we add active commands array to begining, using dup to avoid change by ref.
|
292
310
|
context_name_list = active_context_copy.name_list
|
293
311
|
entries = context_name_list + entries
|
294
312
|
|
295
313
|
# we check the size of active commands
|
296
314
|
ac_size = context_name_list.size
|
297
|
-
|
315
|
+
|
298
316
|
invalid_context = ""
|
299
317
|
# check each par for command / value
|
300
318
|
(0..(entries.size-1)).step(2) do |i|
|
301
319
|
command = entries[i]
|
302
320
|
value = entries[i+1]
|
303
|
-
|
321
|
+
|
304
322
|
clazz = DTK::Shell::Context.get_command_class(command)
|
305
323
|
error_message, invalid_context = validate_command(clazz, current_context_clazz, command, active_context_copy)
|
306
|
-
|
324
|
+
|
307
325
|
break if error_message
|
308
326
|
# if we are dealing with new entries add them to active_context
|
309
327
|
active_context_copy.push_new_context(command, command) if (i >= ac_size)
|
@@ -319,7 +337,7 @@ module DTK
|
|
319
337
|
end
|
320
338
|
break
|
321
339
|
end
|
322
|
-
|
340
|
+
|
323
341
|
active_context_copy.push_new_context(context_hash_data[:name], command, context_hash_data[:identifier]) if ((i+1) >= ac_size)
|
324
342
|
end
|
325
343
|
end
|
@@ -336,7 +354,7 @@ module DTK
|
|
336
354
|
error_message = "Context for '#{command}' could not be loaded.";
|
337
355
|
invalid_context = command
|
338
356
|
end
|
339
|
-
|
357
|
+
|
340
358
|
# check if previous context support this one as a child
|
341
359
|
unless current_context_clazz.nil?
|
342
360
|
# valid child method is necessery to define parent-child relet.
|
@@ -346,10 +364,10 @@ module DTK
|
|
346
364
|
|
347
365
|
valid_all_children = (root_clazz != current_context_clazz) ? all_children.include?(command.to_sym) : true
|
348
366
|
unless (current_context_clazz.valid_child?(command) && valid_all_children)
|
349
|
-
|
367
|
+
|
350
368
|
error_message = "'#{command}' context is not valid."
|
351
369
|
invalid_context = command
|
352
|
-
|
370
|
+
|
353
371
|
if current_context_clazz.respond_to?(:invisible_context)
|
354
372
|
ic = current_context_clazz.invisible_context()
|
355
373
|
ic.each do |c|
|
@@ -374,7 +392,7 @@ module DTK
|
|
374
392
|
entries = args.first.split(/\//)
|
375
393
|
invalid_context = ["workspace/node", "service/node"]
|
376
394
|
double_dots_count = DTK::Shell::ContextAux.count_double_dots(entries)
|
377
|
-
only_double_dots = entries.select{|e| e.to_s
|
395
|
+
only_double_dots = entries.select{|e| !e.to_s.include?('..')}||[]
|
378
396
|
back_flag = false
|
379
397
|
|
380
398
|
last_from_current, message = nil, nil
|
@@ -384,7 +402,7 @@ module DTK
|
|
384
402
|
last_from_current = test_c.last_context_name
|
385
403
|
back_flag = true
|
386
404
|
end
|
387
|
-
|
405
|
+
|
388
406
|
unless args.empty?
|
389
407
|
first_c ||= entries.first
|
390
408
|
last_c = last_from_current||entries.last
|
@@ -400,14 +418,14 @@ module DTK
|
|
400
418
|
end
|
401
419
|
message = "'#{last_c}' context is not valid."
|
402
420
|
is_valid_id = check_for_id(first_c, last_c, tmp_active_context, args)
|
403
|
-
|
421
|
+
|
404
422
|
# if ../ to node context, add one more .. to go to previous context (assembly/id or workspace)
|
405
423
|
if back_flag
|
406
424
|
message = nil
|
407
425
|
entries << ".." if is_valid_id==false
|
408
426
|
else
|
409
427
|
if is_valid_id==false
|
410
|
-
entries.pop
|
428
|
+
entries.pop
|
411
429
|
else
|
412
430
|
message = nil
|
413
431
|
end
|
@@ -424,7 +442,7 @@ module DTK
|
|
424
442
|
end
|
425
443
|
end
|
426
444
|
end
|
427
|
-
|
445
|
+
|
428
446
|
return {:args => args, :message => message}
|
429
447
|
end
|
430
448
|
|
@@ -432,26 +450,26 @@ module DTK
|
|
432
450
|
command_clazz = Context.get_command_class(context)
|
433
451
|
invisible_context = command_clazz.respond_to?(:invisible_context) ? command_clazz.invisible_context.map { |e| e.to_s } : []
|
434
452
|
entries = args.first.split(/\//)
|
435
|
-
|
453
|
+
|
436
454
|
entries = Context.check_for_sym_link(entries) if root?
|
437
455
|
unless invisible_context.empty?
|
438
456
|
if root?
|
439
457
|
tmp_active_context.push_new_context(entries[0], entries[0])
|
440
458
|
context_hash_data, error_message, invalid_context = validate_value(entries[0], entries[1], tmp_active_context)
|
441
|
-
|
459
|
+
|
442
460
|
return if error_message
|
443
461
|
tmp_active_context.push_new_context(context_hash_data[:name], entries[0], context_hash_data[:identifier])
|
444
462
|
context_hash_data, error_message, invalid_context = validate_value(command, command, tmp_active_context)
|
445
|
-
|
463
|
+
|
446
464
|
return if error_message
|
447
465
|
tmp_active_context.push_new_context(context_hash_data[:name], command, context_hash_data[:identifier])
|
448
466
|
end
|
449
467
|
|
450
|
-
|
468
|
+
|
451
469
|
node_ids = get_command_identifiers(invisible_context.first.to_s, tmp_active_context)
|
452
470
|
node_names = node_ids ? node_ids.collect { |e| e[:name] } : []
|
453
471
|
end
|
454
|
-
|
472
|
+
|
455
473
|
return node_names.include?(command)
|
456
474
|
end
|
457
475
|
|
@@ -480,10 +498,10 @@ module DTK
|
|
480
498
|
# e.g. cc library/public, we are caching context under library_1, library_2
|
481
499
|
# so getting context for 'public' will not work and we use than library
|
482
500
|
command_name = root? ? 'dtk' : @active_context.last_command_name
|
483
|
-
|
501
|
+
|
484
502
|
# if there is no new context (current) we use old one
|
485
503
|
@current = current_context_task_names() || @current
|
486
|
-
|
504
|
+
|
487
505
|
client_commands = CLIENT_COMMANDS
|
488
506
|
client_commands.concat(DEV_COMMANDS) if DTK::Configuration.get(:development_mode)
|
489
507
|
|
@@ -495,7 +513,7 @@ module DTK
|
|
495
513
|
|
496
514
|
# we load thor command class identifiers for autocomplete context list
|
497
515
|
command_context = get_command_identifiers(command_name)
|
498
|
-
|
516
|
+
|
499
517
|
command_name_list = command_context ? command_context.collect { |e| e[:name] } : []
|
500
518
|
@context_commands.concat(command_name_list) if current_command?
|
501
519
|
|
@@ -538,7 +556,7 @@ module DTK
|
|
538
556
|
def root?
|
539
557
|
return @active_context.empty?
|
540
558
|
end
|
541
|
-
|
559
|
+
|
542
560
|
def current_command?
|
543
561
|
return @active_context.current_command?
|
544
562
|
end
|
@@ -557,7 +575,7 @@ module DTK
|
|
557
575
|
end
|
558
576
|
|
559
577
|
# checks if method name is valid in current context
|
560
|
-
def method_valid?(method_name)
|
578
|
+
def method_valid?(method_name)
|
561
579
|
# validate method, see if we support given method in current tasks
|
562
580
|
(current_context_task_names() + ['help']).include?(method_name)
|
563
581
|
end
|
@@ -575,15 +593,15 @@ module DTK
|
|
575
593
|
|
576
594
|
# calls 'valid_id?' method in Thor class to validate ID/NAME
|
577
595
|
def valid_id?(thor_command_name,value, override_context_params=nil, active_context_copy=nil)
|
578
|
-
|
596
|
+
|
579
597
|
command_clazz = Context.get_command_class(thor_command_name)
|
580
|
-
if command_clazz.list_method_supported?
|
598
|
+
if command_clazz.list_method_supported?
|
581
599
|
if override_context_params
|
582
600
|
context_params = override_context_params
|
583
601
|
else
|
584
602
|
context_params = get_command_parameters(thor_command_name, [], active_context_copy)[2]
|
585
603
|
end
|
586
|
-
|
604
|
+
|
587
605
|
tmp = command_clazz.valid_id?(value, @conn, context_params)
|
588
606
|
return tmp
|
589
607
|
end
|
@@ -597,13 +615,13 @@ module DTK
|
|
597
615
|
# input string segment used to filter results candidates
|
598
616
|
results_filter = (readline_input.match(/\/$/) && invalid_context.empty?) ? "" : readline_input.split("/").last
|
599
617
|
results_filter ||= ""
|
600
|
-
|
618
|
+
|
601
619
|
command_clazz = Context.get_command_class(active_context_copy.last_command_name)
|
602
620
|
extended_context_commands = nil
|
603
621
|
|
604
622
|
unless command_clazz.nil?
|
605
623
|
extended_context = command_clazz.respond_to?(:extended_context) ? command_clazz.extended_context() : {}
|
606
|
-
|
624
|
+
|
607
625
|
unless extended_context.empty?
|
608
626
|
extended_context = extended_context[:command]
|
609
627
|
extended_context.reject!{|k,v| k.to_s!=line_buffer} if extended_context
|
@@ -625,18 +643,18 @@ module DTK
|
|
625
643
|
context_candidates = get_ac_candidates_for_context(active_context_copy.last_context(), active_context_copy)
|
626
644
|
end
|
627
645
|
end
|
628
|
-
|
646
|
+
|
629
647
|
# checking if results will contain context candidates based on input string segment
|
630
648
|
context_candidates = context_candidates.grep( /^#{Regexp.escape(results_filter)}/ )
|
631
|
-
|
632
|
-
# Show all context tasks if active context orignal and it's copy are on same context, and are not on root,
|
649
|
+
|
650
|
+
# Show all context tasks if active context orignal and it's copy are on same context, and are not on root,
|
633
651
|
# and if readline has one split result indicating user is not going trough n-level, but possibly executing a task
|
634
652
|
task_candidates = []
|
635
653
|
|
636
654
|
#task_candidates = @context_commands if (active_context_copy.last_context_name() == @active_context.last_context_name() && !active_context_copy.empty?)
|
637
655
|
task_candidates = @context_commands if (active_context_copy.last_context_name() == @active_context.last_context_name() && !active_context_copy.empty? && readline_input.split("/").size <= 1)
|
638
|
-
|
639
|
-
# create results object filtered by user input segment (results_filter)
|
656
|
+
|
657
|
+
# create results object filtered by user input segment (results_filter)
|
640
658
|
task_candidates = task_candidates.grep( /^#{Regexp.escape(results_filter)}/ )
|
641
659
|
|
642
660
|
# autocomplete candidates are both context and task candidates; remove duplicates in results
|
@@ -653,7 +671,7 @@ module DTK
|
|
653
671
|
# remove duplicate context or task candidates
|
654
672
|
results.uniq!
|
655
673
|
|
656
|
-
# Send system beep if there are no candidates
|
674
|
+
# Send system beep if there are no candidates
|
657
675
|
if results.empty?
|
658
676
|
print "\a"
|
659
677
|
return []
|
@@ -662,7 +680,7 @@ module DTK
|
|
662
680
|
# default value of input user string
|
663
681
|
input_context_path = readline_input
|
664
682
|
|
665
|
-
# cut off last context if it is leftover (invalid_context),
|
683
|
+
# cut off last context if it is leftover (invalid_context),
|
666
684
|
# or if last context is not finished with '/' and it can have more than option for current context
|
667
685
|
# i.e. dtk> cc assembly - have 2 candidates: 'assembly' and 'assembly-template'
|
668
686
|
if !invalid_context.empty? || cutoff_forcely
|
@@ -681,7 +699,7 @@ module DTK
|
|
681
699
|
|
682
700
|
end
|
683
701
|
|
684
|
-
def get_ac_candidates_for_context(context, active_context_copy)
|
702
|
+
def get_ac_candidates_for_context(context, active_context_copy)
|
685
703
|
# If last context is command, load all identifiers, otherwise, load next possible context command; if no contexts, load root tasks
|
686
704
|
if context
|
687
705
|
if context.is_command?
|
@@ -695,11 +713,11 @@ module DTK
|
|
695
713
|
|
696
714
|
n_level_ac_candidates.select {|v| valid_all_children.include?(v.to_sym)} unless valid_all_children.empty?
|
697
715
|
invisible_context = command_clazz.respond_to?(:invisible_context) ? command_clazz.invisible_context.map { |e| e.to_s } : []
|
698
|
-
|
716
|
+
|
699
717
|
unless invisible_context.empty?
|
700
718
|
node_ids = get_command_identifiers(invisible_context.first.to_s, active_context_copy)
|
701
719
|
node_names = node_ids ? node_ids.collect { |e| e[:name] } : []
|
702
|
-
|
720
|
+
|
703
721
|
n_level_ac_candidates.concat(node_names)
|
704
722
|
end
|
705
723
|
|
@@ -714,13 +732,14 @@ module DTK
|
|
714
732
|
def get_command_identifiers(thor_command_name, active_context_copy=nil)
|
715
733
|
begin
|
716
734
|
command_clazz = Context.get_command_class(thor_command_name)
|
717
|
-
|
735
|
+
|
736
|
+
if command_clazz && command_clazz.list_method_supported?
|
718
737
|
# take just hashed arguemnts from multi return method
|
719
738
|
hashed_args = get_command_parameters(thor_command_name, [], active_context_copy)[2]
|
720
739
|
return command_clazz.get_identifiers(@conn, hashed_args)
|
721
740
|
end
|
722
741
|
rescue DTK::Client::DtkValidationError => e
|
723
|
-
# TODO Check if handling needed. Error should happen only when autocomplete ID search illigal
|
742
|
+
# TODO Check if handling needed. Error should happen only when autocomplete ID search illigal
|
724
743
|
end
|
725
744
|
|
726
745
|
return []
|
@@ -734,7 +753,7 @@ module DTK
|
|
734
753
|
endpoint = extended_context_commands[:endpoint]
|
735
754
|
url = extended_context_commands[:url]
|
736
755
|
opts = extended_context_commands[:opts]||{}
|
737
|
-
|
756
|
+
|
738
757
|
id_label = "#{endpoint}_id".to_sym
|
739
758
|
id = entity_name.identifier
|
740
759
|
opts[id_label] = id
|
@@ -750,7 +769,7 @@ module DTK
|
|
750
769
|
candidates
|
751
770
|
end
|
752
771
|
|
753
|
-
# changes command and argument if argument is plural of one of
|
772
|
+
# changes command and argument if argument is plural of one of
|
754
773
|
# the possible commands on tier1 e.g. libraries, assemblies
|
755
774
|
# return 2 values cmd, args
|
756
775
|
def reverse_commands(cmd, args)
|
@@ -786,8 +805,8 @@ module DTK
|
|
786
805
|
# if no method specified use help
|
787
806
|
method_name ||= 'help'
|
788
807
|
|
789
|
-
context_params.add_context_to_params(entity_name, entity_name)
|
790
|
-
|
808
|
+
context_params.add_context_to_params(entity_name, entity_name)
|
809
|
+
|
791
810
|
if entity_name_id
|
792
811
|
identifier_response = valid_id?(entity_name, entity_name_id, context_params)
|
793
812
|
if identifier_response
|
@@ -824,7 +843,7 @@ module DTK
|
|
824
843
|
entity_name, method_name, option_types = nil, nil, nil
|
825
844
|
|
826
845
|
context_params = ContextParams.new
|
827
|
-
|
846
|
+
|
828
847
|
if root? && !args.empty?
|
829
848
|
# this means that somebody is calling command with assembly/.. method_name
|
830
849
|
entity_name = cmd
|
@@ -842,11 +861,11 @@ module DTK
|
|
842
861
|
|
843
862
|
if ((current_context_command != entity_name) && !current_context_command.eql?("utils"))
|
844
863
|
current_context_clazz = Context.get_command_class(current_context_command)
|
845
|
-
options = Context.get_thor_options(current_context_clazz, cmd)
|
864
|
+
options = Context.get_thor_options(current_context_clazz, cmd) if current_context_clazz
|
846
865
|
else
|
847
|
-
options = Context.get_thor_options(clazz, cmd)
|
866
|
+
options = Context.get_thor_options(clazz, cmd) if clazz
|
848
867
|
end
|
849
|
-
|
868
|
+
|
850
869
|
# set rest of arguments as method options
|
851
870
|
args, thor_options, invalid_options = Context.parse_thor_options(args, options)
|
852
871
|
context_params.method_arguments = args
|
@@ -861,7 +880,7 @@ module DTK
|
|
861
880
|
#
|
862
881
|
def self.parse_thor_options(args, options=nil)
|
863
882
|
type, invalid_options = nil, []
|
864
|
-
|
883
|
+
|
865
884
|
# options to handle thor options -m MESSAGE and --list
|
866
885
|
options_param_args = []
|
867
886
|
args.each_with_index do |e,i|
|
@@ -889,13 +908,13 @@ module DTK
|
|
889
908
|
command = command.gsub('-','_')
|
890
909
|
options = nil
|
891
910
|
options = clazz.all_tasks[command].options.collect{|k,v|{:alias=>v.aliases,:name=>v.name,:type=>v.type,:switch=>v.switch_name}} unless clazz.all_tasks[command].nil?
|
892
|
-
|
911
|
+
|
893
912
|
return options
|
894
913
|
end
|
895
914
|
|
896
|
-
def self.get_option_type(options, option)
|
915
|
+
def self.get_option_type(options, option)
|
897
916
|
@ret = nil
|
898
|
-
|
917
|
+
|
899
918
|
options.each do |opt|
|
900
919
|
@ret = opt[:type] if(opt[:alias].first == option || opt[:switch] == option)
|
901
920
|
end
|
@@ -925,7 +944,7 @@ module DTK
|
|
925
944
|
puts "[INFO] History file is missing, shell history will be disabled. To enable it create file: '#{HISTORY_LOCATION}'"
|
926
945
|
return []
|
927
946
|
end
|
928
|
-
|
947
|
+
|
929
948
|
content = File.open(HISTORY_LOCATION,'r').read
|
930
949
|
return (content.empty? ? [] : JSON.parse(content))
|
931
950
|
end
|
@@ -937,7 +956,7 @@ module DTK
|
|
937
956
|
array_of_commands.each_with_index do |a,i|
|
938
957
|
filtered_commands << a if (a != array_of_commands[i+1] && is_allowed_command?(a))
|
939
958
|
end
|
940
|
-
|
959
|
+
|
941
960
|
# make sure we only save up to 'COMMAND_HISTORY_LIMIT' commands
|
942
961
|
if filtered_commands.size > COMMAND_HISTORY_LIMIT
|
943
962
|
filtered_commands = filtered_commands[-COMMAND_HISTORY_LIMIT,COMMAND_HISTORY_LIMIT+1]
|
@@ -80,10 +80,10 @@ class Thor
|
|
80
80
|
# alternative providers
|
81
81
|
alt_identifiers = get_alternative_identifiers(command)
|
82
82
|
|
83
|
-
|
83
|
+
|
84
84
|
filtered_list = []
|
85
85
|
|
86
|
-
# case when we are not on first level and it is not identifier we skip help
|
86
|
+
# case when we are not on first level and it is not identifier we skip help
|
87
87
|
# since it needs to be empty
|
88
88
|
# e.g. assembly/bootstrap1/node> ... HELP IS EMPTY FOR THIS
|
89
89
|
|
@@ -106,14 +106,14 @@ class Thor
|
|
106
106
|
|
107
107
|
list.each do |help_item|
|
108
108
|
help_item.first.gsub!("^^", '') if help_item.first.include?("^^")
|
109
|
-
|
110
|
-
# this will match entity_name (command) and alternative identifiers
|
109
|
+
|
110
|
+
# this will match entity_name (command) and alternative identifiers
|
111
111
|
identifers = [command] + alt_identifiers
|
112
112
|
|
113
113
|
# matches identifiers for ID/NAME
|
114
114
|
matched_data = help_item.first.match(/^\s\[?(#{identifers.join('|')}).?(NAME\/ID|ID\/NAME)\]?\s/)
|
115
115
|
alt_matched_data = help_item.first.match(/^\s\[?(#{alt_identifiers.join('|')}).?(NAME\/ID|ID\/NAME)\]?\s/)
|
116
|
-
|
116
|
+
|
117
117
|
if matched_data.nil?
|
118
118
|
# not found and tier 1 we add it to help list
|
119
119
|
filtered_list << overriden_help(override_tasks_obj, help_item, true) if @@shell_context.current_command?
|
@@ -156,17 +156,19 @@ class Thor
|
|
156
156
|
# we do not need first one, since above code takes care of that one
|
157
157
|
filtered_list = filtered_list.select do |filtered_help_item|
|
158
158
|
#next unless filtered_help_item
|
159
|
-
commands_that_have_identifiers
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
159
|
+
unless commands_that_have_identifiers.empty?
|
160
|
+
commands_that_have_identifiers[1..-1].each_with_index do |entity,i|
|
161
|
+
matched = match_help_item_changes(filtered_help_item, entity)
|
162
|
+
filtered_help_item = replace_if_matched!(filtered_help_item, matched)
|
163
|
+
|
164
|
+
# if it is last command, and there were changes
|
165
|
+
if (i == (commands_that_have_identifiers.size - 2) && matched)
|
166
|
+
n_filter_list << filtered_help_item
|
167
|
+
end
|
166
168
|
end
|
167
169
|
end
|
168
170
|
end
|
169
|
-
|
171
|
+
|
170
172
|
if override_tasks_obj && is_n_level_context
|
171
173
|
last_entity_name = active_context.last_context_entity_name.to_sym
|
172
174
|
|
@@ -184,7 +186,7 @@ class Thor
|
|
184
186
|
end
|
185
187
|
end
|
186
188
|
|
187
|
-
# we have just filtered those methods that have attribute for given entity
|
189
|
+
# we have just filtered those methods that have attribute for given entity
|
188
190
|
# and also are last in the list
|
189
191
|
filtered_list = n_filter_list
|
190
192
|
end
|
@@ -198,7 +200,7 @@ class Thor
|
|
198
200
|
|
199
201
|
#
|
200
202
|
# e.g.
|
201
|
-
# dtk assembly_template info
|
203
|
+
# dtk assembly_template info
|
202
204
|
# dtk assembly-template info
|
203
205
|
#
|
204
206
|
item[0] = item[0].gsub(/^dtk ([a-zA-Z]+)_([a-zA-Z]+) /,'dtk \1-\2 ')
|
@@ -208,7 +210,7 @@ class Thor
|
|
208
210
|
|
209
211
|
if list.empty?
|
210
212
|
shell.say ""
|
211
|
-
shell.say "No tasks for current context '#{@@shell_context.active_context.full_path}'."
|
213
|
+
shell.say "No tasks for current context '#{@@shell_context.active_context.full_path}'."
|
212
214
|
end
|
213
215
|
|
214
216
|
# remove helper 3. element in help item list
|
@@ -237,7 +239,7 @@ class Thor
|
|
237
239
|
end
|
238
240
|
|
239
241
|
unless sub_children.empty?
|
240
|
-
shell.say(" Change context (cc) to: #{sub_children.join(', ')}", :BOLD)
|
242
|
+
shell.say(" Change context (cc) to: #{sub_children.join(', ')}", :BOLD)
|
241
243
|
shell.say
|
242
244
|
end
|
243
245
|
end
|