class DeepCover::CLI
Public Class Methods
build_option(arg, options, scope)
click to toggle source
Consider defaults only for display
Calls superclass method
# File lib/deep_cover/cli.rb, line 15 def self.build_option(arg, options, scope) default = options.delete(:default) options[:desc] = "#{options[:desc]} (default: #{default})" if default super(arg, options, scope) end
exit_on_failure?()
click to toggle source
exit_code should be non-zero when the parsing fails
# File lib/deep_cover/cli.rb, line 44 def self.exit_on_failure? true end
help(shell, subcommand = false)
click to toggle source
# File lib/deep_cover/cli/commands/help.rb, line 10 def self.help(shell, subcommand = false) list = printable_commands(true, subcommand) Thor::Util.thor_classes_in(self).each do |klass| list += klass.printable_commands(false) end list.sort! { |a, b| a[0] <=> b[0] } main_commands, list = Tools.extract_commands_for_help(list, :exec, :clone) shell.say 'Main commands:' shell.print_table(main_commands, indent: 2, truncate: true) lower_level_commands, list = Tools.extract_commands_for_help(list, :gather, :report, :clear, :merge) shell.say shell.say 'Lower-level commands:' shell.print_table(lower_level_commands, indent: 2, truncate: true) shell.say shell.say 'Misc commands:' shell.print_table(list, indent: 2, truncate: true) shell.say class_options_help(shell) end
short_help(shell)
click to toggle source
# File lib/deep_cover/cli/commands/short_help.rb, line 10 def self.short_help(shell) list = printable_commands(true, false) Thor::Util.thor_classes_in(self).each do |klass| list += klass.printable_commands(false) end main_commands, _ignored = Tools.extract_commands_for_help(list, :exec, :clone) shell.say 'Main commands:' shell.print_table(main_commands, indent: 2, truncate: true) shell.say shell.say 'More commands:' shell.say ' deep-cover help [COMMAND] # Full help with a list of lower-level commands and all options' end
Public Instance Methods
clear()
click to toggle source
# File lib/deep_cover/cli/commands/clear.rb, line 6 def clear DeepCover.persistence.clear_directory end
clone(*command_parts)
click to toggle source
# File lib/deep_cover/cli/commands/clone.rb, line 13 def clone(*command_parts) if command_parts.empty? command_parts = CLI_DEFAULTS[:command] puts "No command specified, using default of: #{command_parts.join(' ')}" end require_relative '../../instrumented_clone_reporter' InstrumentedCloneReporter.new(**processed_options.merge(command: command_parts)).run end
exec(*command_parts)
click to toggle source
# File lib/deep_cover/cli/commands/exec.rb, line 17 def exec(*command_parts) if command_parts.empty? command_parts = CLI_DEFAULTS[:command] puts "No command specified, using default of: #{command_parts.join(' ')}" end DeepCover.config.set(**processed_options.slice(*DEFAULTS.keys)) require 'yaml' env_var = {'DEEP_COVER' => 'gather', 'DEEP_COVER_OPTIONS' => YAML.dump(DeepCover.config.to_hash_for_serialize), } DeepCover.delete_trackers exit_code = Tools.run_command_or_exit(shell, env_var, *command_parts) coverage = Coverage.load puts coverage.report(**DeepCover.config) exit(exit_code) end
gather(*command_parts)
click to toggle source
# File lib/deep_cover/cli/commands/gather.rb, line 12 def gather(*command_parts) if command_parts.empty? warn set_color('`gather` needs a command to run', :red) exit(1) end require 'yaml' env_var = {'DEEP_COVER' => 'gather', 'DEEP_COVER_OPTIONS' => YAML.dump(processed_options.slice(*DEFAULTS.keys)), } exit_code = Tools.run_command_or_exit(shell, env_var, *command_parts) exit(exit_code) end
invoke_command(*args)
click to toggle source
Before we actually execute any of the commands, we want to change directory if that option was given. And then we want to setup the configuration
Calls superclass method
# File lib/deep_cover/cli.rb, line 63 def invoke_command(*args) if options[:change_directory] root_path = File.expand_path(options[:change_directory]) unless File.exist?(root_path) warn set_color(DeepCover::Tools.strip_heredoc(<<-MSG), :red) bad value for option --change-directory: #{root_path.inspect} is not a valid directory MSG exit(1) end Dir.chdir(root_path) # TODO: We need way to turn on DEBUG # warn "(in #{root_path})" end # We need to wait until now to setup the configuration, because it will store absolute paths # in ENV['DEEP_COVER_OPTIONS'], so we must wait until the change_directory was applied. require 'deep_cover/setup/deep_cover_config' super end
merge()
click to toggle source
# File lib/deep_cover/cli/commands/merge.rb, line 6 def merge DeepCover.persistence.merge_persisted_trackers end
processed_options()
click to toggle source
We have some special handling for some of the options We do this here, methods just need to call processed_options
instead of options.
# File lib/deep_cover/cli.rb, line 51 def processed_options @processed_options ||= nil return @processed_options if @processed_options new_options = options.dup new_options[:output] = false if ['false', 'f', ''].include?(new_options[:output]) @processed_options = new_options.transform_keys(&:to_sym) end
report()
click to toggle source
# File lib/deep_cover/cli/commands/report.rb, line 10 def report coverage = Coverage.load puts coverage.report(**processed_options) overall_coverage = coverage.analysis.overall minimum_coverage = processed_options[:'minimum-coverage'].to_f if overall_coverage < minimum_coverage puts "Overall coverage #{format('%.2f', overall_coverage)} is less than minimum #{format('%.2f', minimum_coverage)}" exit 1 end end
run_expression(expression = nil)
click to toggle source
# File lib/deep_cover/cli/commands/run_expression.rb, line 8 def run_expression(expression = nil) require_relative '../../expression_debugger' expression ||= STDIN.read.tap { STDIN.reopen('/dev/tty') } ExpressionDebugger.new(expression, **options.transform_keys(&:to_sym)).show end
short_help()
click to toggle source
# File lib/deep_cover/cli/commands/short_help.rb, line 6 def short_help self.class.short_help(shell) end
version()
click to toggle source
# File lib/deep_cover/cli/commands/version.rb, line 10 def version require 'deep_cover/version' puts "deep-cover version #{DeepCover::VERSION}" end