Class: GitLab::Exporter::CLI::GIT
- Inherits:
-
Object
- Object
- GitLab::Exporter::CLI::GIT
- Defined in:
- lib/gitlab_exporter/cli.rb
Overview
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
Constant Summary collapse
- COMMAND_NAME =
"git".freeze
Instance Attribute Summary collapse
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize(args) ⇒ GIT
constructor
A new instance of GIT.
- #options(args) ⇒ Object
- #run ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(args) ⇒ GIT
Returns a new instance of GIT.
57 58 59 60 61 62 63 |
# File 'lib/gitlab_exporter/cli.rb', line 57 def initialize(args) @options = (args) args = @options.parse! @source = args.shift @target = args.shift || STDOUT @labels ||= {} end |
Instance Attribute Details
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
55 56 57 |
# File 'lib/gitlab_exporter/cli.rb', line 55 def labels @labels end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
55 56 57 |
# File 'lib/gitlab_exporter/cli.rb', line 55 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
55 56 57 |
# File 'lib/gitlab_exporter/cli.rb', line 55 def target @target end |
Instance Method Details
#help ⇒ Object
84 85 86 |
# File 'lib/gitlab_exporter/cli.rb', line 84 def help @options.help end |
#options(args) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/gitlab_exporter/cli.rb', line 74 def (args) args. do |opts| opts. = "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 ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/gitlab_exporter/cli.rb', line 65 def run validate! ::GitLab::Exporter::GitProber.new(labels: labels, source: source) .probe_pull .probe_push .write_to(@target) end |
#validate! ⇒ Object
88 89 90 91 |
# File 'lib/gitlab_exporter/cli.rb', line 88 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 |