class Unlearn::CLI

Public Instance Methods

run() click to toggle source
# File lib/unlearn/cli.rb, line 3
def run
  get_token

  get_repos
end

Private Instance Methods

confirm_delete(repos) click to toggle source
# File lib/unlearn/cli.rb, line 48
def confirm_delete(repos)
  puts "#{repos.length} matching repos found. Delete? (y/n)"

  response = gets.strip

  if ['y', 'Y', 'yes', 'Yes', 'YES'].include? response
    puts "\nWorking...\n\n"

    if Unlearn::RepoDeleter.new repos
      puts "#{repos.length} repositories deleted. Goodbye!"
    else
      puts "Sorry, something went wrong. Please try again later."
      puts "Goodbye!"
    end

    exit

  elsif ['n', 'N', 'no', 'No', 'NO'].include? response
    puts "Goodbye!"

    exit
  else
    confirm_delete(repos)
  end
end
get_repos() click to toggle source
# File lib/unlearn/cli.rb, line 34
def get_repos
  puts "\nWorking...\n\n"

  repos = Unlearn::Runner.new.run

  if repos.length == 0
    puts "No matching repos found. Goodbye!"

    exit
  else
    confirm_delete repos
  end
end
get_token() click to toggle source
# File lib/unlearn/cli.rb, line 11
def get_token
  puts "Go to github.com/settings/tokens/new and create a new personal"
  puts "access token with the 'delete_repo' scope checked."
  puts ""
  puts "Then, copy the created token and paste it in here:"

  token = gets.strip

  until Unlearn::GitHubAPI::Token.is_valid? token
    if ['exit', 'Exit', 'EXIT'].include? token
      puts "Goodbye!"

      exit
    end

    puts "Please enter a valid token or 'exit' to quit:"

    token = gets.strip
  end

  Unlearn::GitHubAPI::Token.set token
end