class Lolcommits::Init
Public Class Methods
enable_for_all_projects()
click to toggle source
# File lib/lolcommits/init.rb, line 69 def self.enable_for_all_projects projs = git_projects puts projs puts 'Do you want to enable snapgit for all those repos? (y/n)' abort unless STDIN.getch.strip == 'y' projs.each do |current| enable_for_project(current) end puts "Successfully enabled snapgit for #{projs.count} projects 🎉" end
enable_for_local_folder()
click to toggle source
# File lib/lolcommits/init.rb, line 64 def self.enable_for_local_folder enable_for_project('.') puts "Successfully enabled snapgit 🎉" end
enable_for_project(path)
click to toggle source
# File lib/lolcommits/init.rb, line 81 def self.enable_for_project(path) puts "Enabling snapgit for '#{File.expand_path(path)}'..." Dir.chdir(path) do # Add the `lolcommits --capture` to the post-hook Lolcommits::Installation.do_enable # Copy the config.yml to the ~/.lolcommits/[project] folder to_path = Lolcommits::Configuration.new.loldir # this will use the current dir by default # rubocop:disable Lint/HandleExceptions begin FileUtils.cp(@config_path, to_path) rescue ArgumentError # if the file is the same end # rubocop:enable Lint/HandleExceptions end end
git_projects()
click to toggle source
# File lib/lolcommits/init.rb, line 98 def self.git_projects puts 'Searching for git repos' # We're using README.md assuming that every repo has one # This is due to Spotlight not finding hidden files (.git) potential = `mdfind -name "README.md" -onlyin ~`.split("\n") # After we have all README.md we look for a .git folder in # each of those potential.collect do |current| path = File.expand_path('..', current) path if File.directory?(File.join(path, '.git')) end.delete_if(&:nil?) end
request_auth_tokens()
click to toggle source
@return (success or not)
# File lib/lolcommits/init.rb, line 59 def self.request_auth_tokens $stdout.sync = true Configuration.new.do_configure!('snapgit') end
run_setup(lolcommits_binary)
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/lolcommits/init.rb, line 8 def self.run_setup(lolcommits_binary) require 'io/console' @lolcommits_binary = lolcommits_binary set_lolcommits_env_config puts 'This setup will run through the necessary steps to get you up and running' puts 'Please follow the wizard to authenticate Twitter and Gravatar' puts "If you don't want to use Gravatar, just don't provide any values" puts 'Confirm with Enter' STDIN.getch Dir.mktmpdir do |_tmp_dir| `git init` # just to make lolcommits believe we're in a git folder result = request_auth_tokens if result == false puts 'Setup failed - please try again' abort end @config_path = result end puts '-' puts 'Successfully generated keys... now setting up your git projects:' puts '-' puts 'Do you want snapgit to automatically enable itself for all local git repositories? (y/n)' if STDIN.getch.strip == 'y' enable_for_all_projects elsif File.directory?('.git') puts 'Do you want to enable snapgit just for the local directory? (y/n)' if STDIN.getch.strip == 'y' enable_for_local_folder return end else puts '-' puts 'Please navigate to the project you want to enable snapgit for' puts 'and run `snapgit init`' abort end end
set_lolcommits_env_config()
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/lolcommits/init.rb, line 52 def self.set_lolcommits_env_config ENV['LOLCOMMITS_INIT_PARAMS'] = ' --delay 1' # this is required to actually work on a Mac ENV['LOLCOMMITS_INIT_PARAMS'] += ' --stealth' # we don't want any output ENV['LOLCOMMITS_INIT_PARAMS'] += ' &' # this way the delay is not noticable end