Class: Onceover::CodeQuality::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/onceover/codequality/cli.rb

Class Method Summary collapse

Class Method Details

.commandObject



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
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/onceover/codequality/cli.rb', line 12

def self.command
  @cmd ||= Cri::Command.define do
    name 'codequality'
    usage 'codequality [--no-syntax] [--no-lint] [--no-docs] [--html-docs] [--no-puppetfile]'
    summary "Code Quality checking for onceover"
    description <<-DESCRIPTION
      Check files in your Control Repository for Lint and Syntax errors
    DESCRIPTION
  
    flag nil, :no_lint, 'Do not check for lint errors', :argument => :optional
    flag nil, :no_puppetfile, 'Do not check Puppetfile for syntax errors', :argument => :optional
    flag nil, :no_syntax, 'Do not check for syntax errors', :argument => :optional
    flag nil, :no_docs, 'Do not generate documentation (puppet-strings) for local modules', :argument => :optional
    flag nil, :html_docs, 'Generate docs in HTML format instead of markdown', :argument => :optional

    run do |opts, args, cmd|
      no_lint = opts[:no_lint] || false
      no_syntax = opts[:no_syntax] || false
      no_docs = opts[:no_docs] || false
      no_puppetfile = opts[:no_puppetfile] || false
      html_docs = opts[:html_docs] || false
      status = true

      logger.info "Running Code Quality tests"

      if ! no_puppetfile
        status &= Onceover::CodeQuality::Puppetfile.puppetfile
      end

      if ! no_syntax
        status &= Onceover::CodeQuality::Syntax.puppet
      end

      if ! no_lint
        status &= Onceover::CodeQuality::Lint.puppet
      end

      if ! no_docs
        status &= Onceover::CodeQuality::Docs.puppet_strings(html_docs)
      end

      if status
        logger.info "Code Quality tests PASSED, have a nice day"
      else
        logger.error "Code Quality tests FAILED, see previous error(s)"
        exit 1
      end
    end
  end
end