opennebula-cli 7.1.80.pre → 7.2.1
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/bin/oneacct +1 -1
- data/bin/oneacl +1 -1
- data/bin/onebackupjob +1 -1
- data/bin/onecluster +1 -1
- data/bin/onedatastore +1 -1
- data/bin/oneflow +1 -1
- data/bin/oneflow-template +1 -1
- data/bin/oneform +1 -1
- data/bin/onegroup +1 -1
- data/bin/onehook +1 -1
- data/bin/onehost +1 -1
- data/bin/oneimage +1 -1
- data/bin/oneirb +1 -1
- data/bin/onelog +1 -1
- data/bin/onemarket +1 -1
- data/bin/onemarketapp +1 -1
- data/bin/onesecgroup +1 -1
- data/bin/oneshowback +1 -1
- data/bin/onetemplate +1 -1
- data/bin/oneuser +1 -1
- data/bin/onevdc +1 -1
- data/bin/onevm +2 -2
- data/bin/onevmgroup +1 -1
- data/bin/onevnet +1 -1
- data/bin/onevntemplate +1 -1
- data/bin/onevrouter +1 -1
- data/bin/onezone +1 -1
- data/lib/cli_helper.rb +1 -1
- data/lib/command_parser.rb +135 -126
- data/lib/load_opennebula_paths.rb +5 -0
- data/lib/ods_helper.rb +541 -0
- data/lib/one_helper/oneacct_helper.rb +117 -109
- data/lib/one_helper/oneacl_helper.rb +1 -1
- data/lib/one_helper/onebackupjob_helper.rb +1 -1
- data/lib/one_helper/onecluster_helper.rb +1 -1
- data/lib/one_helper/onedatastore_helper.rb +87 -80
- data/lib/one_helper/oneflow_helper.rb +1 -1
- data/lib/one_helper/oneflowtemplate_helper.rb +1 -1
- data/lib/one_helper/oneform_helper.rb +1 -1
- data/lib/one_helper/onegroup_helper.rb +1 -1
- data/lib/one_helper/onehook_helper.rb +1 -1
- data/lib/one_helper/onehost_helper.rb +1 -1
- data/lib/one_helper/oneimage_helper.rb +1 -1
- data/lib/one_helper/onemarket_helper.rb +59 -58
- data/lib/one_helper/onemarketapp_helper.rb +1 -1
- data/lib/one_helper/onequota_helper.rb +240 -190
- data/lib/one_helper/onesecgroup_helper.rb +87 -85
- data/lib/one_helper/onetemplate_helper.rb +64 -64
- data/lib/one_helper/oneuser_helper.rb +2 -2
- data/lib/one_helper/onevdc_helper.rb +45 -45
- data/lib/one_helper/onevm_helper.rb +6 -8
- data/lib/one_helper/onevmgroup_helper.rb +65 -63
- data/lib/one_helper/onevnet_helper.rb +1 -1
- data/lib/one_helper/onevntemplate_helper.rb +43 -40
- data/lib/one_helper/onevrouter_helper.rb +86 -87
- data/lib/one_helper/onezone_helper.rb +98 -101
- data/lib/one_helper.rb +90 -71
- data/share/schemas/xsd/acct.xsd +3 -104
- data/share/schemas/xsd/cluster.xsd +4 -21
- data/share/schemas/xsd/datastore.xsd +4 -29
- data/share/schemas/xsd/document.xsd +3 -25
- data/share/schemas/xsd/group.xsd +2 -14
- data/share/schemas/xsd/group_pool.xsd +2 -14
- data/share/schemas/xsd/hook.xsd +2 -0
- data/share/schemas/xsd/host.xsd +5 -7
- data/share/schemas/xsd/image.xsd +2 -25
- data/share/schemas/xsd/marketplace.xsd +3 -22
- data/share/schemas/xsd/marketplaceapp.xsd +3 -25
- data/share/schemas/xsd/opennebula_configuration.xsd +3 -2
- data/share/schemas/xsd/requirements.xsd +3 -21
- data/share/schemas/xsd/security_group.xsd +6 -43
- data/share/schemas/xsd/shared.xsd +3 -3
- data/share/schemas/xsd/vdc.xsd +2 -7
- data/share/schemas/xsd/vm_group.xsd +3 -25
- data/share/schemas/xsd/vm_pool.xsd +2 -0
- data/share/schemas/xsd/vmtemplate.xsd +3 -25
- data/share/schemas/xsd/vnet.xsd +9 -67
- data/share/schemas/xsd/vnet_pool.xsd +8 -57
- data/share/schemas/xsd/vntemplate.xsd +3 -25
- data/share/schemas/xsd/vrouter.xsd +4 -32
- metadata +8 -6
data/lib/command_parser.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -------------------------------------------------------------------------- #
|
|
2
|
-
# Copyright 2002-
|
|
2
|
+
# Copyright 2002-2026, OpenNebula Project, OpenNebula Systems #
|
|
3
3
|
# #
|
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
|
5
5
|
# not use this file except in compliance with the License. You may obtain #
|
|
@@ -17,54 +17,63 @@
|
|
|
17
17
|
require 'optparse'
|
|
18
18
|
require 'pp'
|
|
19
19
|
|
|
20
|
+
# String class extension to include unindent method
|
|
20
21
|
class String
|
|
21
|
-
|
|
22
|
+
|
|
23
|
+
# Unindent the string by removing leading spaces.
|
|
24
|
+
# @param [Integer] spaces to remove, if nil the size of the first match
|
|
25
|
+
# of leading spaces is used.
|
|
26
|
+
def unindent(spaces = nil)
|
|
22
27
|
unless spaces
|
|
23
|
-
m =
|
|
28
|
+
m = match(/^(\s*)/)
|
|
24
29
|
spaces = m[1].size
|
|
25
30
|
end
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
gsub!(/^ {#{spaces}}/, '')
|
|
28
33
|
end
|
|
34
|
+
|
|
29
35
|
end
|
|
30
36
|
|
|
31
37
|
module CommandParser
|
|
38
|
+
|
|
32
39
|
OPTIONS = [
|
|
33
40
|
VERBOSE={
|
|
34
|
-
:name =>
|
|
35
|
-
:short =>
|
|
36
|
-
:large =>
|
|
37
|
-
:description =>
|
|
41
|
+
:name => 'verbose',
|
|
42
|
+
:short => '-v',
|
|
43
|
+
:large => '--verbose',
|
|
44
|
+
:description => 'Verbose mode'
|
|
38
45
|
},
|
|
39
46
|
HELP={
|
|
40
|
-
:name =>
|
|
41
|
-
:short =>
|
|
42
|
-
:large =>
|
|
43
|
-
:description =>
|
|
47
|
+
:name => 'help',
|
|
48
|
+
:short => '-h',
|
|
49
|
+
:large => '--help',
|
|
50
|
+
:description => 'Show this message'
|
|
44
51
|
},
|
|
45
52
|
VERSION={
|
|
46
|
-
:name =>
|
|
47
|
-
:short =>
|
|
48
|
-
:large =>
|
|
49
|
-
:description =>
|
|
53
|
+
:name => 'version',
|
|
54
|
+
:short => '-V',
|
|
55
|
+
:large => '--version',
|
|
56
|
+
:description => 'Show version and copyright information'
|
|
50
57
|
}
|
|
51
58
|
]
|
|
52
59
|
|
|
60
|
+
# CmdParser class to handle command line arguments and options
|
|
53
61
|
class CmdParser
|
|
62
|
+
|
|
54
63
|
attr_reader :options, :args
|
|
55
64
|
|
|
56
|
-
def initialize(args=[], &block)
|
|
57
|
-
@available_options =
|
|
58
|
-
@commands =
|
|
59
|
-
@command_list =
|
|
60
|
-
@formats =
|
|
65
|
+
def initialize(args = [], &block)
|
|
66
|
+
@available_options = []
|
|
67
|
+
@commands = {}
|
|
68
|
+
@command_list = []
|
|
69
|
+
@formats = {}
|
|
61
70
|
|
|
62
71
|
@main = nil
|
|
63
72
|
|
|
64
73
|
@exit_code = nil
|
|
65
74
|
|
|
66
75
|
@args = args
|
|
67
|
-
@options =
|
|
76
|
+
@options = {}
|
|
68
77
|
|
|
69
78
|
@before_proc=nil
|
|
70
79
|
@comm_name=nil
|
|
@@ -73,22 +82,24 @@ module CommandParser
|
|
|
73
82
|
|
|
74
83
|
instance_eval(&block)
|
|
75
84
|
|
|
76
|
-
addons = Dir["#{OpenNebulaHelper::CLI_ADDONS_LOCATION}/#{File.basename($
|
|
77
|
-
if defined?(addons)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
addons = Dir["#{OpenNebulaHelper::CLI_ADDONS_LOCATION}/#{File.basename($PROGRAM_NAME)}/*"]
|
|
86
|
+
if defined?(addons) && !addons.nil?
|
|
87
|
+
addons.each do |addon_path|
|
|
88
|
+
addon_code = File.read(addon_path)
|
|
89
|
+
instance_eval(addon_code)
|
|
90
|
+
end
|
|
82
91
|
end
|
|
83
92
|
|
|
84
|
-
|
|
93
|
+
run
|
|
85
94
|
end
|
|
86
95
|
|
|
87
96
|
# Defines the usage information of the command
|
|
88
97
|
# @param [String] str
|
|
89
98
|
def usage(str)
|
|
90
99
|
@usage = str
|
|
100
|
+
# rubocop:disable Naming/MemoizedInstanceVariableName
|
|
91
101
|
@name ||= @usage.split(' ').first
|
|
102
|
+
# rubocop:enable Naming/MemoizedInstanceVariableName
|
|
92
103
|
end
|
|
93
104
|
|
|
94
105
|
# Defines the version the command
|
|
@@ -180,7 +191,7 @@ module CommandParser
|
|
|
180
191
|
#
|
|
181
192
|
def option(options)
|
|
182
193
|
if options.instance_of?(Array)
|
|
183
|
-
options.each {
|
|
194
|
+
options.each {|o| @available_options << o }
|
|
184
195
|
elsif options.instance_of?(Hash)
|
|
185
196
|
@available_options << options
|
|
186
197
|
end
|
|
@@ -192,7 +203,7 @@ module CommandParser
|
|
|
192
203
|
@exit_code = code
|
|
193
204
|
end
|
|
194
205
|
|
|
195
|
-
def exit_with_code(code, output=nil)
|
|
206
|
+
def exit_with_code(code, output = nil)
|
|
196
207
|
puts output if output
|
|
197
208
|
exit code
|
|
198
209
|
end
|
|
@@ -281,16 +292,16 @@ module CommandParser
|
|
|
281
292
|
# end
|
|
282
293
|
#
|
|
283
294
|
def command(name, desc, *args_format, &block)
|
|
284
|
-
if name.is_a?
|
|
285
|
-
name = name.join(
|
|
295
|
+
if name.is_a?(Array)
|
|
296
|
+
name = name.join(' ').to_sym
|
|
286
297
|
end
|
|
287
298
|
|
|
288
|
-
cmd =
|
|
299
|
+
cmd = {}
|
|
289
300
|
cmd[:desc] = desc
|
|
290
301
|
cmd[:arity] = 0
|
|
291
302
|
cmd[:options] = []
|
|
292
|
-
cmd[:args_format] =
|
|
293
|
-
args_format.each
|
|
303
|
+
cmd[:args_format] = []
|
|
304
|
+
args_format.each do |args|
|
|
294
305
|
if args.instance_of?(Array)
|
|
295
306
|
cmd[:arity]+=1 unless args.include?(nil)
|
|
296
307
|
cmd[:args_format] << args
|
|
@@ -305,14 +316,14 @@ module CommandParser
|
|
|
305
316
|
cmd[:arity]+=1
|
|
306
317
|
cmd[:args_format] << [args]
|
|
307
318
|
end
|
|
308
|
-
|
|
319
|
+
end
|
|
309
320
|
cmd[:proc] = block
|
|
310
321
|
@command_list << name.to_sym
|
|
311
322
|
@commands[name.to_sym] = cmd
|
|
312
323
|
end
|
|
313
324
|
|
|
314
325
|
def deprecated_command(name, new_command)
|
|
315
|
-
cmd = @commands[name.to_sym] ||
|
|
326
|
+
cmd = @commands[name.to_sym] || {}
|
|
316
327
|
cmd[:desc] += "\nDeprecated, use #{new_command} instead"
|
|
317
328
|
cmd[:deprecated] = new_command
|
|
318
329
|
|
|
@@ -399,10 +410,10 @@ module CommandParser
|
|
|
399
410
|
# end
|
|
400
411
|
#
|
|
401
412
|
def main(*args_format, &block)
|
|
402
|
-
@main=
|
|
413
|
+
@main={}
|
|
403
414
|
@main[:arity] = 0
|
|
404
|
-
@main[:args_format] =
|
|
405
|
-
args_format.collect
|
|
415
|
+
@main[:args_format] = []
|
|
416
|
+
args_format.collect do |args|
|
|
406
417
|
if args.instance_of?(Array)
|
|
407
418
|
@main[:arity]+=1 unless args.include?(nil)
|
|
408
419
|
@main[:args_format] << args
|
|
@@ -412,7 +423,7 @@ module CommandParser
|
|
|
412
423
|
@main[:arity]+=1
|
|
413
424
|
@main[:args_format] << [args]
|
|
414
425
|
end
|
|
415
|
-
|
|
426
|
+
end
|
|
416
427
|
|
|
417
428
|
@main[:proc] = block
|
|
418
429
|
end
|
|
@@ -427,26 +438,23 @@ module CommandParser
|
|
|
427
438
|
end
|
|
428
439
|
end
|
|
429
440
|
|
|
430
|
-
|
|
431
441
|
def run
|
|
432
|
-
comm_name=
|
|
442
|
+
comm_name=''
|
|
433
443
|
|
|
434
444
|
if @main
|
|
435
445
|
comm_name = @name
|
|
436
446
|
comm = @main
|
|
437
|
-
elsif
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
current = @args.shift
|
|
441
|
-
|
|
442
|
-
if comm_name.empty?
|
|
443
|
-
@comm_name = comm_name = "#{current}".to_sym
|
|
444
|
-
else
|
|
445
|
-
@comm_name = comm_name = "#{comm_name} #{current}".to_sym
|
|
446
|
-
end
|
|
447
|
+
elsif @args[0] && !@args[0].match(/^-/)
|
|
448
|
+
while comm.nil? && !@args.empty?
|
|
449
|
+
current = @args.shift
|
|
447
450
|
|
|
448
|
-
|
|
451
|
+
if comm_name.empty?
|
|
452
|
+
(@comm_name = (comm_name = current.to_s.to_sym))
|
|
453
|
+
else
|
|
454
|
+
(@comm_name = (comm_name = "#{comm_name} #{current}".to_sym))
|
|
449
455
|
end
|
|
456
|
+
|
|
457
|
+
comm = @commands[comm_name]
|
|
450
458
|
end
|
|
451
459
|
end
|
|
452
460
|
|
|
@@ -494,7 +502,7 @@ module CommandParser
|
|
|
494
502
|
private
|
|
495
503
|
|
|
496
504
|
def parse(extra_options)
|
|
497
|
-
with_proc=
|
|
505
|
+
with_proc=[]
|
|
498
506
|
|
|
499
507
|
@cmdparse=OptionParser.new do |opts|
|
|
500
508
|
merge = @available_options
|
|
@@ -512,10 +520,10 @@ module CommandParser
|
|
|
512
520
|
if e[:proc] && !e[:multiple]
|
|
513
521
|
@options[e[:name].to_sym]=o
|
|
514
522
|
with_proc<<e
|
|
515
|
-
elsif e[:name]==
|
|
523
|
+
elsif e[:name]=='help'
|
|
516
524
|
print_help
|
|
517
525
|
exit 0
|
|
518
|
-
elsif e[:name]==
|
|
526
|
+
elsif e[:name]=='version'
|
|
519
527
|
puts @version
|
|
520
528
|
exit 0
|
|
521
529
|
elsif !e[:multiple]
|
|
@@ -533,20 +541,20 @@ module CommandParser
|
|
|
533
541
|
|
|
534
542
|
begin
|
|
535
543
|
@cmdparse.parse!(@args)
|
|
536
|
-
rescue => e
|
|
544
|
+
rescue StandardError => e
|
|
537
545
|
STDERR.puts e.message
|
|
538
|
-
exit
|
|
546
|
+
exit(-1)
|
|
539
547
|
end
|
|
540
548
|
|
|
541
|
-
with_proc.each do |
|
|
542
|
-
rc =
|
|
549
|
+
with_proc.each do |proc_opt|
|
|
550
|
+
rc = proc_opt[:proc].call(@options[proc_opt[:name].to_sym], @options)
|
|
543
551
|
if rc.instance_of?(Array)
|
|
544
552
|
if rc[0] == 0
|
|
545
|
-
@options[
|
|
553
|
+
@options[proc_opt[:name].to_sym] = rc[1]
|
|
546
554
|
else
|
|
547
555
|
STDERR.puts rc[1]
|
|
548
|
-
STDERR.puts "option #{
|
|
549
|
-
exit
|
|
556
|
+
STDERR.puts "option #{proc_opt[:name]}: Parsing error"
|
|
557
|
+
exit(-1)
|
|
550
558
|
end
|
|
551
559
|
end
|
|
552
560
|
end
|
|
@@ -558,37 +566,37 @@ module CommandParser
|
|
|
558
566
|
if arity>1
|
|
559
567
|
STDERR.puts "#{args_format.length} parameters to run."
|
|
560
568
|
else
|
|
561
|
-
STDERR.puts
|
|
569
|
+
STDERR.puts 'one parameter to run'
|
|
562
570
|
end
|
|
563
571
|
|
|
564
572
|
print_command_help(name)
|
|
565
573
|
|
|
566
|
-
exit
|
|
574
|
+
exit(-1)
|
|
567
575
|
else
|
|
568
576
|
id=0
|
|
569
|
-
@args.collect!
|
|
570
|
-
unless
|
|
571
|
-
args_str=args_format.collect
|
|
577
|
+
@args.collect! do |arg|
|
|
578
|
+
unless args_format[id]
|
|
579
|
+
args_str=args_format.collect do |a|
|
|
572
580
|
if a.include?(nil)
|
|
573
|
-
"[#{a.compact.join(
|
|
581
|
+
"[#{a.compact.join('|')}]"
|
|
574
582
|
else
|
|
575
|
-
"<#{a.join(
|
|
583
|
+
"<#{a.join('|')}>"
|
|
576
584
|
end
|
|
577
|
-
|
|
585
|
+
end.join(' ')
|
|
578
586
|
|
|
579
|
-
STDERR.puts
|
|
587
|
+
STDERR.puts 'Wrong number of arguments'
|
|
580
588
|
if args_str.empty?
|
|
581
|
-
STDERR.puts
|
|
589
|
+
STDERR.puts 'No argument is required'
|
|
582
590
|
else
|
|
583
591
|
STDERR.puts "The arguments should be: #{args_str}"
|
|
584
592
|
end
|
|
585
|
-
exit
|
|
593
|
+
exit(-1)
|
|
586
594
|
end
|
|
587
595
|
|
|
588
596
|
format = args_format[id]
|
|
589
597
|
argument = nil
|
|
590
598
|
error_msg = nil
|
|
591
|
-
format.each
|
|
599
|
+
format.each do |f|
|
|
592
600
|
if @formats[f]
|
|
593
601
|
format_hash = @formats[f]
|
|
594
602
|
elsif f.nil?
|
|
@@ -606,20 +614,21 @@ module CommandParser
|
|
|
606
614
|
error_msg=rc[1]
|
|
607
615
|
next
|
|
608
616
|
end
|
|
609
|
-
|
|
617
|
+
end
|
|
610
618
|
|
|
611
619
|
unless argument
|
|
612
620
|
if error_msg
|
|
613
621
|
STDERR.puts error_msg
|
|
614
622
|
else
|
|
615
|
-
STDERR.puts "command #{name}: argument #{id} must
|
|
623
|
+
STDERR.puts "command #{name}: argument #{id} must " \
|
|
624
|
+
"be one of #{format.join(', ')}"
|
|
616
625
|
end
|
|
617
|
-
exit
|
|
626
|
+
exit(-1)
|
|
618
627
|
end
|
|
619
628
|
|
|
620
629
|
id+=1
|
|
621
630
|
argument
|
|
622
|
-
|
|
631
|
+
end
|
|
623
632
|
end
|
|
624
633
|
end
|
|
625
634
|
|
|
@@ -637,7 +646,7 @@ module CommandParser
|
|
|
637
646
|
|
|
638
647
|
def print_all_commands_help
|
|
639
648
|
if @usage
|
|
640
|
-
puts
|
|
649
|
+
puts '## SYNOPSIS'
|
|
641
650
|
puts
|
|
642
651
|
puts @usage
|
|
643
652
|
puts
|
|
@@ -651,7 +660,7 @@ module CommandParser
|
|
|
651
660
|
print_formatters
|
|
652
661
|
puts
|
|
653
662
|
if @version
|
|
654
|
-
puts
|
|
663
|
+
puts '## VERSION'
|
|
655
664
|
puts @version
|
|
656
665
|
end
|
|
657
666
|
end
|
|
@@ -664,11 +673,11 @@ module CommandParser
|
|
|
664
673
|
return print_all_commands_help
|
|
665
674
|
end
|
|
666
675
|
|
|
667
|
-
puts
|
|
676
|
+
puts '## USAGE'
|
|
668
677
|
print "#{name} "
|
|
669
678
|
print_command(@commands[name])
|
|
670
679
|
|
|
671
|
-
puts
|
|
680
|
+
puts '## OPTIONS'
|
|
672
681
|
command[:options].flatten.each do |o|
|
|
673
682
|
print_option(o)
|
|
674
683
|
end
|
|
@@ -679,7 +688,7 @@ module CommandParser
|
|
|
679
688
|
end
|
|
680
689
|
|
|
681
690
|
def print_options
|
|
682
|
-
puts
|
|
691
|
+
puts '## OPTIONS'
|
|
683
692
|
|
|
684
693
|
shown_opts = []
|
|
685
694
|
options = []
|
|
@@ -709,27 +718,27 @@ module CommandParser
|
|
|
709
718
|
def print_option(o)
|
|
710
719
|
opt_format = "#{' '*5}%-25s"
|
|
711
720
|
|
|
712
|
-
str =
|
|
721
|
+
str = ''
|
|
713
722
|
str << o[:short].split(' ').first << ', ' if o[:short]
|
|
714
723
|
str << o[:large]
|
|
715
724
|
|
|
716
|
-
params=
|
|
725
|
+
params = Kernel.format(opt_format, str)
|
|
717
726
|
|
|
718
727
|
first_line=80-params.length
|
|
719
728
|
|
|
720
|
-
description=word_wrap(80-32, o[:description], first_line)
|
|
721
|
-
|
|
729
|
+
description=word_wrap(80-32, o[:description], first_line)
|
|
730
|
+
.join("\n"+' '*31)
|
|
722
731
|
|
|
723
732
|
puts "#{params} #{description}"
|
|
724
733
|
end
|
|
725
734
|
|
|
726
735
|
def print_commands
|
|
727
|
-
cmd_format5 =
|
|
736
|
+
cmd_format5 = "#{' '*3}%s"
|
|
728
737
|
|
|
729
738
|
if @main
|
|
730
739
|
print_command(@main)
|
|
731
740
|
else
|
|
732
|
-
puts
|
|
741
|
+
puts '## COMMANDS'
|
|
733
742
|
|
|
734
743
|
@command_list.sort! if @command_list
|
|
735
744
|
|
|
@@ -743,27 +752,27 @@ module CommandParser
|
|
|
743
752
|
end
|
|
744
753
|
|
|
745
754
|
def print_command(command)
|
|
746
|
-
cmd_format10 =
|
|
755
|
+
cmd_format10 = "#{' '*8}%s"
|
|
747
756
|
|
|
748
|
-
args_str=command[:args_format].collect
|
|
757
|
+
args_str=command[:args_format].collect do |a|
|
|
749
758
|
if a.include?(nil)
|
|
750
|
-
"[<#{a.compact.join(
|
|
759
|
+
"[<#{a.compact.join('|')}>]"
|
|
751
760
|
else
|
|
752
|
-
"<#{a.join(
|
|
761
|
+
"<#{a.join('|')}>"
|
|
753
762
|
end
|
|
754
|
-
|
|
755
|
-
printf
|
|
763
|
+
end.join(' ')
|
|
764
|
+
printf args_str.to_s
|
|
756
765
|
puts
|
|
757
766
|
|
|
758
|
-
command[:desc].split("\n").each
|
|
767
|
+
command[:desc].split("\n").each do |l|
|
|
759
768
|
printf cmd_format10, l
|
|
760
769
|
puts
|
|
761
|
-
|
|
770
|
+
end if command[:desc]
|
|
762
771
|
|
|
763
772
|
if command[:options] && !command[:options].empty?
|
|
764
|
-
opts_str=command[:options].flatten.collect
|
|
773
|
+
opts_str=command[:options].flatten.collect do |o|
|
|
765
774
|
o[:name]
|
|
766
|
-
|
|
775
|
+
end.join(', ')
|
|
767
776
|
printf cmd_format10, "valid options: #{opts_str}"
|
|
768
777
|
puts
|
|
769
778
|
end
|
|
@@ -771,34 +780,34 @@ module CommandParser
|
|
|
771
780
|
end
|
|
772
781
|
|
|
773
782
|
def print_formatters
|
|
774
|
-
puts
|
|
783
|
+
puts '## ARGUMENT FORMATS'
|
|
775
784
|
|
|
776
|
-
cmd_format5 =
|
|
777
|
-
cmd_format10 =
|
|
785
|
+
cmd_format5 = "#{' '*3}%s"
|
|
786
|
+
cmd_format10 = "#{' '*8}%s"
|
|
778
787
|
|
|
779
788
|
@formats = @formats.sort_by {|key, _| key } if @formats
|
|
780
789
|
|
|
781
|
-
@formats.each
|
|
790
|
+
@formats.each do |key, value|
|
|
782
791
|
printf cmd_format5, "* #{key}"
|
|
783
792
|
puts
|
|
784
793
|
|
|
785
|
-
value[:desc].split("\n").each
|
|
794
|
+
value[:desc].split("\n").each do |l|
|
|
786
795
|
printf cmd_format10, l
|
|
787
796
|
puts
|
|
788
|
-
|
|
797
|
+
end
|
|
789
798
|
|
|
790
799
|
puts
|
|
791
|
-
|
|
800
|
+
end
|
|
792
801
|
end
|
|
793
802
|
|
|
794
803
|
def print_deprecated(new_command)
|
|
795
|
-
puts
|
|
796
|
-
puts " $ #{File.basename $
|
|
804
|
+
puts 'This command is deprecated, use instead:'
|
|
805
|
+
puts " $ #{File.basename $PROGRAM_NAME} #{new_command}"
|
|
797
806
|
end
|
|
798
807
|
|
|
799
|
-
def word_wrap(size, text, first_size=nil)
|
|
808
|
+
def word_wrap(size, text, first_size = nil)
|
|
800
809
|
output=[]
|
|
801
|
-
line=
|
|
810
|
+
line=''
|
|
802
811
|
if first_size
|
|
803
812
|
line_size=first_size
|
|
804
813
|
else
|
|
@@ -824,39 +833,39 @@ module CommandParser
|
|
|
824
833
|
# Default Formatters for arguments
|
|
825
834
|
########################################################################
|
|
826
835
|
def format_text(arg)
|
|
827
|
-
arg.instance_of?(String) ? [0,arg] : [-1]
|
|
836
|
+
arg.instance_of?(String) ? [0, arg] : [-1]
|
|
828
837
|
end
|
|
829
838
|
|
|
830
839
|
def format_int(arg)
|
|
831
|
-
arg.match(/^\d+$/) ? [0,arg] : [-1, "Argument '#{arg}' is not a valid ID"]
|
|
840
|
+
arg.match(/^\d+$/) ? [0, arg] : [-1, "Argument '#{arg}' is not a valid ID"]
|
|
832
841
|
end
|
|
833
842
|
|
|
834
843
|
def format_file(arg)
|
|
835
|
-
File.file?(arg) ? [0,arg] : [-1]
|
|
844
|
+
File.file?(arg) ? [0, arg] : [-1]
|
|
836
845
|
end
|
|
837
846
|
|
|
838
847
|
REG_RANGE=/^(?:(?:\d+\.\.\d+|\d+),)*(?:\d+\.\.\d+|\d+)$/
|
|
839
848
|
|
|
840
849
|
def format_range(arg)
|
|
841
|
-
arg_s = arg.gsub(
|
|
850
|
+
arg_s = arg.gsub(' ', '').to_s
|
|
842
851
|
return [-1] unless arg_s.match(REG_RANGE)
|
|
843
852
|
|
|
844
|
-
ids =
|
|
845
|
-
arg_s.split(',').each
|
|
853
|
+
ids = []
|
|
854
|
+
arg_s.split(',').each do |e|
|
|
846
855
|
if e.match(/^\d+$/)
|
|
847
856
|
ids << e.to_i
|
|
848
|
-
elsif m = e.match(/^(\d+)\.\.(\d+)$/)
|
|
857
|
+
elsif (m = e.match(/^(\d+)\.\.(\d+)$/))
|
|
849
858
|
ids += (m[1].to_i..m[2].to_i).to_a
|
|
850
859
|
else
|
|
851
860
|
return [-1]
|
|
852
861
|
end
|
|
853
|
-
|
|
862
|
+
end
|
|
854
863
|
|
|
855
|
-
return 0,ids.uniq
|
|
864
|
+
return 0, ids.uniq
|
|
856
865
|
end
|
|
857
866
|
|
|
858
867
|
def define_default_formats
|
|
859
|
-
format :file,
|
|
868
|
+
format :file, 'Path to a file' do |arg|
|
|
860
869
|
format_file(arg)
|
|
861
870
|
end
|
|
862
871
|
|
|
@@ -864,11 +873,11 @@ module CommandParser
|
|
|
864
873
|
format_range(arg)
|
|
865
874
|
end
|
|
866
875
|
|
|
867
|
-
format :text,
|
|
876
|
+
format :text, 'String' do |arg|
|
|
868
877
|
format_text(arg)
|
|
869
878
|
end
|
|
870
879
|
end
|
|
871
|
-
end
|
|
872
|
-
end
|
|
873
880
|
|
|
881
|
+
end
|
|
874
882
|
|
|
883
|
+
end
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Stub for RubyGems installations. When the CLI is installed via
|
|
2
|
+
# `gem install opennebula-cli`, RubyGems already configures the load paths
|
|
3
|
+
# through its binstub mechanism. This file satisfies the
|
|
4
|
+
# `require 'load_opennebula_paths'` present in every CLI script without
|
|
5
|
+
# overriding the gem-managed paths.
|