-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoctopus.rb
50 lines (43 loc) · 1.62 KB
/
octopus.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true
require 'byebug'
require_relative 'lib/clients/bitbucket'
require_relative 'lib/clients/github'
require_relative 'lib/commands/fetch'
require_relative 'lib/commands/update'
require_relative 'lib/options'
require_relative 'lib/vcs/repository'
$VERBOSE = nil
unless RUBY_VERSION.to_f >= 2.5
puts 'Octopus requires Ruby 2.5.0 and above'
exit 1
end
options_parser = Octopus::Options.new
unless options_parser.valid?
puts options_parser.errors.values.join("\n")
exit 1
end
options = options_parser.options
vcs_client = case options[:scm_provider].downcase
when 'bitbucket'
Octopus::Clients::Bitbucket.new(options[:base_url], options[:username], options[:password])
when 'github'
Octopus::Clients::GitHub.new(options[:base_url], options[:password])
else
puts "Unknown SCM provider #{options[:scm_provider]}. Available values are: " \
"#{Octopus::Options::SCM_PROVIDERS.join(', ')}."
exit 1
end
command = case options[:command]
when Octopus::Options::COMMAND_FETCH
Octopus::Commands::Fetch.new(options[:files], options[:directory], vcs_client, options[:thread_count],
options[:branch], options[:projects])
when Octopus::Options::COMMAND_UPDATE
Octopus::Commands::Update.new(options[:files], options[:directory], vcs_client, options_parser.pr_options,
options[:thread_count])
end
begin
command.run
rescue StandardError => e
puts e.message
exit 1
end