Class: Gitrob::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/gitrob/cli.rb,
lib/gitrob/cli/command.rb,
lib/gitrob/cli/progress_bar.rb,
lib/gitrob/cli/commands/banner.rb,
lib/gitrob/cli/commands/server.rb,
lib/gitrob/cli/commands/analyze.rb,
lib/gitrob/cli/commands/configure.rb,
lib/gitrob/cli/commands/analyze/analysis.rb,
lib/gitrob/cli/commands/analyze/gathering.rb,
lib/gitrob/cli/commands/accept_terms_of_use.rb

Defined Under Namespace

Modules: Commands Classes: Command, ProgressBar

Constant Summary collapse

HELP_COMMANDS =
%w(help h --help -h)
DB_MIGRATIONS_PATH =
File.expand_path(
  "../../../db/migrations", __FILE__
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gitrob/cli.rb', line 45

def initialize(*args)
  super
  Hashie.logger = Logger.new(nil) # Disable warnings from Hashie
  self.class.enable_debugging if options[:debug]
  String.disable_colorization(!options[:color])
  return if help_command?
  banner
  configure unless configured?
  load_configuration
  prepare_database
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



12
13
14
# File 'lib/gitrob/cli.rb', line 12

def configuration
  @configuration
end

Class Method Details

.configurationObject



210
211
212
# File 'lib/gitrob/cli.rb', line 210

def self.configuration
  @config
end

.configuration=(config) ⇒ Object



206
207
208
# File 'lib/gitrob/cli.rb', line 206

def self.configuration=(config)
  @config = config
end

.debug(message) ⇒ Object



186
187
188
# File 'lib/gitrob/cli.rb', line 186

def self.debug(message)
  output "[#]".light_cyan + " #{message}\n" if debugging_enabled?
end

.debugging_enabled?Boolean

rubocop:disable Style/TrivialAccessors

Returns:

  • (Boolean)


202
203
204
# File 'lib/gitrob/cli.rb', line 202

def self.debugging_enabled? # rubocop:disable Style/TrivialAccessors
  @debugging_enabled
end

.disable_debuggingObject



198
199
200
# File 'lib/gitrob/cli.rb', line 198

def self.disable_debugging
  @debugging_enabled = false
end

.enable_debuggingObject



194
195
196
# File 'lib/gitrob/cli.rb', line 194

def self.enable_debugging
  @debugging_enabled = true
end

.error(message) ⇒ Object



177
178
179
# File 'lib/gitrob/cli.rb', line 177

def self.error(message)
  output "[!]".light_red + " #{message}\n"
end

.fatal(message) ⇒ Object



181
182
183
184
# File 'lib/gitrob/cli.rb', line 181

def self.fatal(message)
  output "[!]".light_white.on_red + " #{message}\n"
  exit(1)
end

.info(message) ⇒ Object



150
151
152
# File 'lib/gitrob/cli.rb', line 150

def self.info(message)
  output "[*]".light_blue + " #{message}\n"
end

.output(string) ⇒ Object



190
191
192
# File 'lib/gitrob/cli.rb', line 190

def self.output(string)
  print string
end

.output_failed_task(exception, fatal_error) ⇒ Object



163
164
165
166
167
168
169
170
171
# File 'lib/gitrob/cli.rb', line 163

def self.output_failed_task(exception, fatal_error)
  message = "#{exception.class}: #{exception.message}"
  debug exception.backtrace.join("\n")
  if fatal_error
    fatal message
  else
    error message
  end
end

.task(message, fatal_error = false, &block) ⇒ Object



154
155
156
157
158
159
160
161
# File 'lib/gitrob/cli.rb', line 154

def self.task(message, fatal_error=false, &block)
  output "[*]".light_blue + " #{message}"
  yield block
  output " done\n".light_green
rescue => e
  output " failed\n".light_red
  output_failed_task(e, fatal_error)
end

.warn(message) ⇒ Object



173
174
175
# File 'lib/gitrob/cli.rb', line 173

def self.warn(message)
  output "[!]".light_yellow + " #{message}\n"
end

Instance Method Details

#accept_tosObject



105
106
107
# File 'lib/gitrob/cli.rb', line 105

def accept_tos
  Gitrob::CLI::Commands::AcceptTermsOfUse.start(options)
end

#analyze(targets) ⇒ Object



83
84
85
86
# File 'lib/gitrob/cli.rb', line 83

def analyze(targets)
  accept_tos
  Gitrob::CLI::Commands::Analyze.start(targets, options)
end


100
101
102
# File 'lib/gitrob/cli.rb', line 100

def banner
  Gitrob::CLI::Commands::Banner.start(options)
end

#configureObject



95
96
97
# File 'lib/gitrob/cli.rb', line 95

def configure
  Gitrob::CLI::Commands::Configure.start(options)
end

#serverObject



89
90
91
92
# File 'lib/gitrob/cli.rb', line 89

def server
  accept_tos
  Gitrob::CLI::Commands::Server.start(options)
end