Class: Ding::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/ding/cli.rb

Instance Method Summary collapse

Instance Method Details

#key_genObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ding/cli.rb', line 77

def key_gen
  key_name = options[:name] || "#{options[:host]}_#{options[:type]}"
  say "\nDing ding ding: let's create and configure a new ssh key #{key_name}...\n\n", :green

  Ding::Ssh.new(options).tap do |s|
    if s.ssh_key_exists?(key_name)
      if yes?("Do you want me to replace the existing key?", :yellow)
        say "> Removing existing key #{key_name}...", :cyan
        s.delete_ssh_key key_name
        say "> Creating the replacement ssh key pair...", :cyan
        s.create_ssh_key key_name, ENV['USER']
      else
        say "> Using existing key #{key_name}...", :cyan
      end
    else
      say "> Creating the new ssh key pair...", :green
      s.create_ssh_key key_name, ENV['USER']
    end
    say "> Adding the private key to the ssh config...", :green
    s.update_config options[:host], key_name
    say "> Copying the public key to the clipboard...", :green
    copy_file_to_clipboard s.ssh_public_key_file(key_name)
  end

rescue => e
  show_error e
else
  say "\n  --> I'm finished: ding ding ding!\n\n", :green
end

#key_showObject



108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/ding/cli.rb', line 108

def key_show
  say "\nDing ding ding: let's copy a public key to the clipboard...\n\n", :green

  Ding::Ssh.new(options).tap do |s|
    key_name = ask_which_item(s.list_ssh_keys, 'Which key do you want to copy?')
    say "\n> Copying the public key to the clipboard...", :green
    copy_file_to_clipboard s.ssh_public_key_file(key_name)
  end

rescue => e
  show_error e
else
  say "\n  --> You can now Command-v to paste that key: ding ding ding!\n\n", :green
end

#testObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ding/cli.rb', line 14

def test
  develop_branch, testing_branch = Ding::DEVELOP_BRANCH.dup, Ding::TESTING_BRANCH.dup
  say "\nDing ding ding: let's merge one or more feature branches to #{testing_branch}...\n\n", :green

  repo = Ding::Git.new(options).tap do |r|
    say "> Synchronising with the remote...", :green
    r.checkout develop_branch
    r.update
  end

  branches = repo.branches(options[:pattern])
  if branches.empty?
    say "\n --> No feature branches available to test, I'm out of here!\n\n", :red
    exit 1
  end

  feature_branches = ask_which_item(branches, 'Which feature branch should I use?', :multiple)

  repo.tap do |r|
    say "\n> Deleting #{testing_branch}...", :green
    r.delete_branch(testing_branch)

    say "> Checking out #{develop_branch}...", :green
    r.checkout(develop_branch)

    say "> Creating #{testing_branch}...", :green
    r.create_branch(testing_branch)

    say "> Checking out #{testing_branch}...", :green
    r.checkout(testing_branch)

    say "> Merging in selected feature #{feature_branches.count == 1 ? 'branch' : 'branches'}...", :green
    merge_errors = false
    feature_branches.each do |branch|
      if r.merge_branch(branch)
        say "   ✓  #{branch}", :green
      else
        say "   ✗  #{branch}", :red
        merge_errors = true
      end
    end

    unless merge_errors
      say "> Pushing #{testing_branch} to the remote...", :green
      r.push(testing_branch)
    else
      say "\n  --> There were merge errors, ding dang it!\n\n", :red
      exit 1
    end
  end

rescue => e
  show_error e
else
  say "\n  --> I'm finished: ding ding ding!\n\n", :green
end