class Profile::CLI
Public Class Methods
exit_on_failure?()
click to toggle source
# File lib/git/profile.rb, line 55 def self.exit_on_failure? true end
Public Instance Methods
add()
click to toggle source
# File lib/git/profile.rb, line 60 def add profiles = File.join(Dir.home, "/.git-profile/profiles.yml") profile_directory = File.join(Dir.home, ".git-profile") username, email = fetch_user_data if File.exist?(profiles) save(username, email) else Dir.mkdir(profile_directory) unless Dir.exist?(profile_directory) create_file "#{File.join(Dir.home, ".git-profile/profiles.yml")}" username, email = fetch_user_data save(username, email) end end
delete(username)
click to toggle source
# File lib/git/profile.rb, line 107 def delete(username) profiles = File.join(Dir.home, "/.git-profile/profiles.yml") if File.exist?(profiles) && !File.zero?(profiles) users = YAML.load(File.read(profiles)) user = users[:users].filter { |user| user[:username] == username } unless user.empty? users[:users].delete(user.first) say("User #{user.first[:username]} <#{user.first[:email].to_s}> has been deleted!") if users[:users].empty? File.open(profiles, 'w') {|file| file.truncate(0) } else File.open(profiles, "w") { |file| file.write(users.to_yaml) } end else say("No git profiles with username #{username} was found. You can see all available profiles with `$git-profile list` command .") end else say("No git profiles found. You can add a git profile with `$git-profile add` command .") end end
list()
click to toggle source
# File lib/git/profile.rb, line 76 def list profiles = File.join(Dir.home, "/.git-profile/profiles.yml") if File.exist?(profiles) && !File.zero?(profiles) users = YAML.load(File.read(profiles)) users[:users].each_with_index { |user, index| say("#{index + 1}. #{user[:username]} <#{user[:email]}>") } else say("No git profiles found. You can add a git profile with `$git-profile add` command .") end end
reset()
click to toggle source
# File lib/git/profile.rb, line 131 def reset profiles = File.join(Dir.home, "/.git-profile/profiles.yml") config_path = File.join(Dir.home, ".gitconfig") File.open(profiles, 'w') {|file| file.truncate(0) } if File.exist?(profiles) && !File.zero?(profiles) File.open(config_path, 'w') {|file| file.truncate(0) } if File.exist?(config_path) say("reset successfull!") end
use(username)
click to toggle source
# File lib/git/profile.rb, line 87 def use(username) profiles = File.join(Dir.home, "/.git-profile/profiles.yml") config_path = File.join(Dir.home, ".gitconfig") if File.exist?(profiles) && !File.zero?(profiles) users = YAML.load(File.read(profiles)) user = users[:users].filter { |user| user[:username] == username } unless user.empty? File.open(config_path, 'w') {|file| file.truncate(0) } if File.exist?(config_path) run("git config --global user.name #{user.first[:username]}") run("git config --global user.email #{user.first[:email]}") say("git credentials has been updated.") else say("No git profiles with username #{username} was found. See all available profiles with `$git-profile list` command .") end else say("No git profiles with username #{username} was found. See all available profiles with `$git-profile list` command .") end end
whoami()
click to toggle source
# File lib/git/profile.rb, line 140 def whoami config_path = File.join(Dir.home, ".gitconfig") if File.exist?(config_path) && !File.zero?(config_path) print("username: ") username = run("git config user.name", config = {:verbose => false}) print("email: ") email = run("git config user.email", config = {:verbose => false}) else say("No git profiles found. You can add a git profile with `$git-profile use` command .") end end