class CaptainHoog::Cli::Hoog

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 10
def self.exit_on_failure?
  true
end
hookin_repo() click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 18
def self.hookin_repo
  "git@github.com:RSCSCybersecurity/hookins.git"
end
source_root() click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 14
def self.source_root
  File.join(File.dirname(__FILE__), "templates")
end

Public Instance Methods

__print_version() click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 69
def __print_version
  puts CaptainHoog::VERSION
end
init() click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 75
def init
  home_dir = options[:home]
  init_environment(home_dir: home_dir)
end
install(*_args) click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 31
def install(*_args)
  check_if_git_present
  check_if_option_present("plugins_dir")
  init_environment(home_dir: Dir.home,
                  silence: options[:silence],
                  skip_hookins: options[:skip_hookins])
  install_hook({ as: options[:type],
                 context: {
                   root_dir: Dir.getwd,
                   plugins_dir: options[:plugins_dir],
                   project_dir: options[:project_dir]
                 }
              })
  puts "Installed hook as #{options[:type]} hook".green
end
move(*_args) click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 57
def move(*_args)
  check_if_git_present
  if options[:from] == options[:to]
    puts "--from and --to arguments are the same".red
    raise Thor::Error
  else
    move_hook(options)
    puts "The #{options[:from]} hook is moved to #{options[:to]} hook.".green
  end
end
remove(*_args) click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 48
def remove(*_args)
  check_if_git_present
  remove_hook(as: options[:type])
  puts "The #{options[:type]} hook is removed.".green
end

Private Instance Methods

check_if_option_present(type) click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 103
def check_if_option_present(type)
  unless options.has_key?(type)
    puts "No value provided for required options '--#{type}'".red
    raise Thor::Error
  end
end
copy_config_file(opts={}) click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 110
def copy_config_file(opts={})
  template('hoogfile.erb', git_dir.join('hoogfile.yml'), opts)
end
init_environment(home_dir: Dir.home, silence: false, skip_hookins: false) click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 114
def init_environment(home_dir: Dir.home, 
                     silence: false,
                     skip_hookins: false)
  environment_dir = File.join(home_dir, '.hoog')
  treasury_dir = File.join(environment_dir, 'treasury')
  if File.exist?(treasury_dir)
    puts "Treasury already exists. Skipping.".yellow unless silence
  else
    puts "Initializing treasury".green unless silence
    FileUtils.mkdir_p(treasury_dir)
  end
  pull_and_clone(self.class.hookin_repo, treasury_dir) unless skip_hookins
end
install_hook(config) click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 85
def install_hook(config)
  opts        = config[:context]
  opts[:type] = config[:as]
  copy_config_file(opts)
  template("install.erb",File.join(hooks_dir, config[:as]), opts)
  FileUtils.chmod(0755,File.join(hooks_dir, config[:as]))
end
move_hook(config) click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 97
def move_hook(config)
  from = File.join(hooks_dir, config[:from])
  to   = File.join(hooks_dir, config[:to])
  FileUtils.mv(from, to)
end
remove_hook(config) click to toggle source
# File lib/captain_hoog/cli/hoog.rb, line 93
def remove_hook(config)
  FileUtils.rm_rf(File.join(hooks_dir, config[:as]))
end