Class: Gitlab::Lint::Client::Args
- Inherits:
-
Object
- Object
- Gitlab::Lint::Client::Args
- Defined in:
- lib/gitlab/lint/client/args.rb
Constant Summary collapse
- API_PATH =
"/api/v4/ci/lint"
Instance Attribute Summary collapse
-
#baseUrl ⇒ Object
readonly
Returns the value of attribute baseUrl.
-
#pathToYamlFile ⇒ Object
readonly
Returns the value of attribute pathToYamlFile.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #get(args) ⇒ Object
-
#initialize ⇒ Args
constructor
A new instance of Args.
- #validateUrl!(url) ⇒ Object
- #validateYamlFile!(path) ⇒ Object
- #version ⇒ Object
Constructor Details
Instance Attribute Details
#baseUrl ⇒ Object (readonly)
Returns the value of attribute baseUrl.
13 14 15 |
# File 'lib/gitlab/lint/client/args.rb', line 13 def baseUrl @baseUrl end |
#pathToYamlFile ⇒ Object (readonly)
Returns the value of attribute pathToYamlFile.
14 15 16 |
# File 'lib/gitlab/lint/client/args.rb', line 14 def pathToYamlFile @pathToYamlFile end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
15 16 17 |
# File 'lib/gitlab/lint/client/args.rb', line 15 def timeout @timeout end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
16 17 18 |
# File 'lib/gitlab/lint/client/args.rb', line 16 def url @url end |
Instance Method Details
#get(args) ⇒ Object
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 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gitlab/lint/client/args.rb', line 22 def get(args) = {} optparse = OptionParser.new do|opt| opt. = 'Usage: validate-gitlab-ci [options]' opt.on('-f', '--yaml=YAML-PATH', 'Path to .gitlab-ci.yml') { |o| [:yamlFile] = o } opt.on('-u', '--base-url=BASE_URL', 'GitLab API url') { |o| [:baseUrl] = o } [:timeout] = 10 opt.on('-t', '--timeout[=TIMEOUT]', Integer, 'Api timeout in seconds') { |o| [:timeout] = o } opt.on('-v', '--version', 'Program version') { |o| [:version] = version() } end begin optparse.parse!(args) if [:version].nil? mandatory = [:yamlFile, :baseUrl] missing = mandatory.select{ |param| [param].nil? } if not missing.empty? STDERR.puts "Required options #{missing[0]} are missing: #{missing.join(", ")}" puts optparse.help abort("Exiting due to error encountered while parsing arguments") end end rescue OptionParser::InvalidOption, OptionParser::MissingArgument => error STDERR.puts error puts optparse abort("Exiting due to error encountered while parsing arguments...") end self.validateUrl!([:baseUrl]) self.validateYamlFile!([:yamlFile]) @baseUrl = [:baseUrl] @url = [:baseUrl] + API_PATH @pathToYamlFile = [:yamlFile] @timeout = [:timeout] end |
#validateUrl!(url) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/gitlab/lint/client/args.rb', line 64 def validateUrl!(url) uri = URI.parse(url) valid = uri.is_a?(URI::HTTPS) && !uri.host.nil? raise URI::InvalidURIError unless valid end |
#validateYamlFile!(path) ⇒ Object
71 72 73 74 75 |
# File 'lib/gitlab/lint/client/args.rb', line 71 def validateYamlFile!(path) raise ArgumentError unless path.chars.last(4).join == ".yml" or path.chars.last(5).join == ".yaml" raise IOError unless ::File.exist?(path) raise RuntimeError unless ::File.readable?(path) end |
#version ⇒ Object
77 78 79 80 81 |
# File 'lib/gitlab/lint/client/args.rb', line 77 def version() string = "GitLab Lint Client Version: #{@version}" puts string exit 0 end |