Project

Profile

Help

How to connect?
Download (3.56 KB) Statistics View on GitHub Reload from mirrored respository
| Branch: | Tag: | Revision:

root / mdbci @ master

1
#!/usr/bin/env ruby
2

    
3
require 'getoptlong'
4

    
5
require_relative 'core/help'
6
require_relative 'core/generator'
7
require_relative 'core/session'
8
require_relative 'core/node_product'
9
require_relative 'core/out'
10
require_relative 'core/exception_handler'
11

    
12
#Reading options
13
opts = GetoptLong.new(
14
    ['--help', '-h', GetoptLong::NO_ARGUMENT],
15
    ['--template', '-t', GetoptLong::REQUIRED_ARGUMENT],
16
    ['--command', '-c', GetoptLong::REQUIRED_ARGUMENT],
17
    ['--boxes', '-b', GetoptLong::REQUIRED_ARGUMENT],
18
    ['--box-name', '-n', GetoptLong::REQUIRED_ARGUMENT],
19
    ['--field', '-f', GetoptLong::REQUIRED_ARGUMENT],
20
    ['--override', '-w', GetoptLong::NO_ARGUMENT],
21
    ['--silent', '-s', GetoptLong::NO_ARGUMENT],
22
    ['--repo-dir','-r',GetoptLong::REQUIRED_ARGUMENT],
23
    ['--attempts','-a',GetoptLong::REQUIRED_ARGUMENT],
24
    ['--product','-p',GetoptLong::REQUIRED_ARGUMENT],
25
    ['--product-version','-v',GetoptLong::REQUIRED_ARGUMENT],
26
    ['--key','-k',GetoptLong::REQUIRED_ARGUMENT],
27
    ['--platform','-o',GetoptLong::REQUIRED_ARGUMENT],
28
    ['--platform-version','-i',GetoptLong::REQUIRED_ARGUMENT],
29
    ['--path-to-nodes', GetoptLong::REQUIRED_ARGUMENT],
30
    ['--node-name', GetoptLong::REQUIRED_ARGUMENT],
31
    ['--snapshot-name', GetoptLong::REQUIRED_ARGUMENT]
32
)
33

    
34
$session = Session.new
35
$session.configFile='instance.json'
36
$session.boxesFile='boxes.json'
37
$session.awsConfigFile='aws-config.yml'
38
$exception_handler = ExceptionHandler.new
39

    
40
$out = Out.new
41

    
42
begin
43
  opts.each do |opt, arg|
44
    case opt
45
      when '--silent'
46
        $session.isSilent = true
47

    
48
      when '--template'
49
        if arg != ''; $session.configFile = arg; end
50
  #      $out.info 'Using template name '+$session.configFile
51

    
52
      when '--boxes'
53
        if arg != ''; $session.boxesFile = arg; end
54
  #      $out.info 'Using boxes name '+$session.boxesFile
55

    
56
      when '--box-name'
57
        if arg != ''; $session.boxName = arg; end
58
  #      $out.info 'Using boxes name '+ $session.boxName
59

    
60
      when '--field'
61
        if arg != ''; $session.field = arg; end
62
  #      $out.info 'Using boxes field '+$session.field
63

    
64
      when '--help'
65
        Help.display
66
        exit
67

    
68
      when '--override'
69
        $session.isOverride = true
70

    
71
      when '--command'
72
        $session.command = arg
73

    
74
      when '--repo-dir'
75
        $session.repoDir = arg
76

    
77
      when '--attempts'
78
        $session.attempts = arg
79

    
80
      when '--product'
81
        if arg != ''; $session.nodeProduct = arg; end
82

    
83
      when '--product-version'
84
        if arg != ''; $session.productVersion = arg; end
85

    
86
      when '--key'
87
        if arg != ''; $session.keyFile = arg; end
88
  #      $out.info 'Using keyfile '+$session.keyFile
89

    
90
      when '--platform'
91
        if arg != ''; $session.boxPlatform = arg; end
92

    
93
      when '--platform-version'
94
        if arg != ''; $session.boxPlatformVersion = arg; end
95

    
96
      when '--path-to-nodes'
97
        $session.path_to_nodes = arg
98

    
99
      when '--node-name'
100
        $session.node_name = arg
101

    
102
      when '--snapshot-name'
103
        $session.snapshot_name = arg
104

    
105
      else
106
        $out.error 'Option is not supported: '+opt
107
    end
108
  end
109
  rescue GetoptLong::MissingArgument => error
110
    $out.error error.backtrace.join("\n")
111
    $out.error error.to_s
112
    exit 1
113
end
114
#Hello message
115
$out.info 'MariaDb CI CLI'
116
$out.info 'mdbci called with: '+ARGV.to_s
117

    
118
=begin
119
  run command (create config only for now)
120
=end
121

    
122
$session.checkConfig
123
$session.loadCollections
124

    
125
# run commands and return 0 for success, 1 for error
126

    
127
begin
128
  exit_code = $session.commands
129
rescue Exception => error
130
  $out.error error.backtrace.join("\n")
131
  $out.error error.to_s
132
  exit_code =  1
133
end
134

    
135
exit exit_code
(7-7/8)