Class: Git::Copilot::CLI

Inherits:
Thor
  • Object
show all
Includes:
Configuration
Defined in:
lib/git/copilot/cli.rb,
lib/git/copilot/cli/user.rb

Defined Under Namespace

Classes: User

Instance Method Summary collapse

Instance Method Details

#initObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/git/copilot/cli.rb', line 12

def init
  if File.exist?(config_file_path) && !options[:force]
    return say_status "ERROR", "Configuration file already exists", :red
  end

  say "Writing configuration file to #{config_file_path}"
  File.write(config_file_path, empty_configuration)

  if yes?("Set up a global git alias? (This will allow you to run `git copilot`)")
    system("git config --global alias.copilot '\!git-copilot'")
  end

  solo
end

#pair(*usernames) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/git/copilot/cli.rb', line 37

def pair(*usernames)
  authors = usernames.map do |username|
    users.fetch(username) do
      say_status "WARNING", "Unknown user #{username}", :yellow
      next
    end
  end.compact

  if authors.empty?
    return say_status "ERROR", "No users to pair with. " \
      "Did you mean to run git-copilot solo?", :red
  end

  self.current_pairs = authors
  commit_config
  write_template
  set_git_commit_template

  status
end

#soloObject



28
29
30
31
32
33
34
# File 'lib/git/copilot/cli.rb', line 28

def solo
  clear_pairs
  commit_config
  write_template
  set_git_commit_template
  status
end

#statusObject



59
60
61
62
63
64
65
66
67
68
# File 'lib/git/copilot/cli.rb', line 59

def status
  if current_pairs.empty?
    say "Now working solo", :green
  else
    say "Now working with #{pluralize_pairs(current_pairs.length)}:"
    current_pairs.each do |author|
      say format("%{name} <%{email}>", name: author.name, email: author.email), :green
    end
  end
end