Class: Mistilteinn::Cli::SelfCheck

Inherits:
Command
  • Object
show all
Defined in:
lib/mistilteinn/cli/self_check.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #config, #its

Instance Method Summary collapse

Methods inherited from Command

commands, desc, inherited, #initialize, name, #run

Constructor Details

This class inherits a constructor from Mistilteinn::Cli::Command

Instance Method Details

#actionObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mistilteinn/cli/self_check.rb', line 6

def action
  section "ticket source"
  check("source type") {
    its.class rescue error("'#{config.ticket.source}' is not valid.")
  }
  check(its.class){ its.check }

  section "git"
  check_if("inside work tree?") { Mistilteinn::Git.work_tree? }
  check_if("git-now subcommand") { Mistilteinn::Git.command? 'now' }
  check_if("git-master subcommand") { Mistilteinn::Git.command? 'master' }
  check_if("git-hooks subcommand") { Mistilteinn::Git.command? 'hooks' }

  puts '','Works! Have a good programming!!'
rescue => e
  puts <<END
#{e.message}

Oh, Mistilteinn does not work.
Please check your system or configure file.
END
  exit 1
end

#check(title, &f) ⇒ Object



43
44
45
46
47
# File 'lib/mistilteinn/cli/self_check.rb', line 43

def check(title, &f)
  print title, " => "
  STDOUT.flush
  puts f.call
end

#check_if(title, &p) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/mistilteinn/cli/self_check.rb', line 49

def check_if(title, &p)
  check(title) {
    if p[] then
      "ok"
    else
      error("error")
    end
  }
end

#error(msg) ⇒ Object

Raises:

  • (StandardError)


30
31
32
# File 'lib/mistilteinn/cli/self_check.rb', line 30

def error(msg)
  raise StandardError.new(msg)
end

#section(title) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/mistilteinn/cli/self_check.rb', line 34

def section(title)
  puts <<END

------------------------------
#{title}
------------------------------
END
end