class GitLab::Exporter::CLI::GIT
Git
runner.
Takes something that behaves like ARGV with optparse included as an argument.
It will take 2 positional arguments once parsed, the first one for the repository location, the optional second one is an IO like object to write to
Constants
- COMMAND_NAME
Attributes
labels[R]
source[R]
target[R]
Public Class Methods
new(args)
click to toggle source
# File lib/gitlab_exporter/cli.rb, line 41 def initialize(args) @options = options(args) args = @options.parse! @source = args.shift @target = args.shift || STDOUT @labels ||= {} end
Public Instance Methods
help()
click to toggle source
# File lib/gitlab_exporter/cli.rb, line 68 def help @options.help end
options(args)
click to toggle source
# File lib/gitlab_exporter/cli.rb, line 58 def options(args) args.options do |opts| opts.banner = "Usage: #{EXECUTABLE_NAME} #{COMMAND_NAME} [options] repository_path [target_file]" opts.on("-l", "--labels=key=value,key2=value2", "Labels to append to the metrics") do |val| @labels = val.split(",").map { |value| value.split("=").tap { |aa| aa[0] = aa[0].to_sym } }.to_h end opts end end
run()
click to toggle source
# File lib/gitlab_exporter/cli.rb, line 49 def run validate! ::GitLab::Exporter::GitProber.new(labels: labels, source: source) .probe_pull .probe_push .write_to(@target) end
validate!()
click to toggle source
# File lib/gitlab_exporter/cli.rb, line 72 def validate! fail InvalidCLICommand.new(help) if @source.nil? fail InvalidCLICommand.new("Can't find repository #{@source}\n\n#{help}") unless File.directory? @source end