electric_monk 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0eca1985ed6f721ba7fadd3aeadeb1dc4ca91b8c
4
- data.tar.gz: 80aff1f5707dc05e6ca2d7b919a34a9b1ad08479
3
+ metadata.gz: 5fdfdaae4c92e5e8022a74520096288cb223d15a
4
+ data.tar.gz: '05250191c08281ba24c7ed36ab47741d3bcbebbf'
5
5
  SHA512:
6
- metadata.gz: 3f5a7204eecb4c4cbed24ce4266df0312c6f061aac1d38d680b91f4b7dee510a55340558e42394441cd0599bbcf761eb434199f381912b0b84c76c1a3192741b
7
- data.tar.gz: 35d8c63a5a670b6ce6a089c7cdae131fb679ecd9bb297b1b3d97a80863794343dfc4c6caec37a33f35edbd49d3fc1bf206497816c328497ad642ad2098e44d32
6
+ metadata.gz: e0aa2604ed8edf53aaf82013f52c58f23ce54379f7930c902ef3f10b03d0d52c476b76eceb47ef75f1f0e66f01c1b35600507665533b9b34cb9c4faf126ae0b6
7
+ data.tar.gz: e099cbc0b6a154aa1b7bf54397179bf9b50ee3af11b7ffe759081daa05622a64c9ba8091c440681bbf7a144926efd6745781ae64f4aab67c23642a3818673f69
data/lib/electric_monk.rb CHANGED
@@ -6,22 +6,34 @@ require "singleton"
6
6
  module ElectricMonk
7
7
  class CLI
8
8
  attr_reader :config
9
+ attr_reader :reporter
9
10
 
10
11
  def initialize(config_path:, reporter: Reporter.instance)
11
- @config = Config.new(config_path, reporter)
12
+ @reporter = reporter
13
+ @config = Config.new(config_path)
12
14
  end
13
15
 
14
16
  def run
15
17
  config.projects.each do |project|
16
- project.ensure_existence
18
+ reporter.start(project.name)
19
+
20
+ unless project.exists?
21
+ reporter.update_progress("Cloning #{project.name}")
22
+ project.clone_project
23
+ end
24
+
25
+ if project.valid?
26
+ reporter.fail(project.failures)
27
+ else
28
+ reporter.succeed(project.name)
29
+ end
17
30
  end
18
31
  end
19
32
  end
20
33
 
21
34
  class Config
22
- def initialize(path, reporter)
35
+ def initialize(path)
23
36
  @config = TomlRB.load_file(path)
24
- @reporter = reporter
25
37
  end
26
38
 
27
39
  def root
@@ -33,8 +45,7 @@ module ElectricMonk
33
45
  Project.new(
34
46
  root: root,
35
47
  name: name,
36
- origin: attributes.fetch("origin"),
37
- reporter: @reporter
48
+ origin: attributes.fetch("origin")
38
49
  )
39
50
  end
40
51
  end
@@ -44,35 +55,32 @@ module ElectricMonk
44
55
  attr_reader :root
45
56
  attr_reader :name
46
57
  attr_reader :origin
47
- attr_reader :reporter
58
+ attr_reader :failures
48
59
 
49
- def initialize(root:, name:, origin:, reporter:)
60
+ def initialize(root:, name:, origin:)
50
61
  @root = root
51
62
  @name = name
52
63
  @origin = origin
53
- @reporter = reporter
54
64
  end
55
65
 
56
- def ensure_existence
57
- if exists?
58
- if remote_correct?
59
- if dirty_files?
60
- reporter.warn("#{name}: #{dirty_files} dirty files")
61
- elsif unpushed_commits?
62
- reporter.warn("#{name}: #{unpushed_commits} unpushed commits")
63
- else
64
- reporter.info(name)
65
- end
66
- else
67
- reporter.warn("#{name}: Wrong remote '#{current_remote}'")
66
+ def valid?
67
+ if remote_correct?
68
+ if dirty_files? || unpushed_commits?
69
+ @failures = "#{name}: #{dirty_files} dirty files and #{unpushed_commits} unpushed commits"
68
70
  end
69
71
  else
70
- reporter.wait("Cloning #{name}", name) do
71
- clone_project
72
- end
72
+ @failures = "#{name}: Wrong remote '#{current_remote}'"
73
73
  end
74
74
  end
75
75
 
76
+ def exists?
77
+ File.exist?(path)
78
+ end
79
+
80
+ def clone_project
81
+ execute("git clone #{origin} #{name}", chdir: root)
82
+ end
83
+
76
84
  private
77
85
 
78
86
  def dirty_files?
@@ -95,18 +103,10 @@ module ElectricMonk
95
103
  execute("git remote get-url origin", chdir: path)
96
104
  end
97
105
 
98
- def clone_project
99
- execute("git clone #{origin} #{name}", chdir: root)
100
- end
101
-
102
106
  def remote_correct?
103
107
  origin == current_remote
104
108
  end
105
109
 
106
- def exists?
107
- File.exist?(path)
108
- end
109
-
110
110
  def path
111
111
  File.join(root, name)
112
112
  end
@@ -119,32 +119,34 @@ module ElectricMonk
119
119
  class Reporter
120
120
  include Singleton
121
121
 
122
- def info(msg)
123
- puts "✓ #{msg}"
124
- end
125
-
126
- def warn(msg)
127
- puts "✗ #{msg}"
128
- end
122
+ def start(task_name)
123
+ @task_name = task_name
124
+ @final_message = nil
129
125
 
130
- def wait(waiting_msg, done_msg)
131
- chars = %w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].cycle
132
- show_spinner = true
133
-
134
- spinner = Thread.new do
135
- while show_spinner do
136
- print "#{chars.next} #{waiting_msg}"
126
+ @spinner = Thread.new do
127
+ chars = %w[⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏].cycle
128
+ until @final_message do
129
+ current_task_name = @task_name
130
+ print "#{chars.next} #{current_task_name}"
137
131
  sleep 0.1
138
- print "\b" * (waiting_msg.length + 2)
132
+ print "\b \b" * (current_task_name.length + 2)
139
133
  end
140
- padding = waiting_msg.length > done_msg.length ? " " * (waiting_msg.length - done_msg.length) : ""
141
- info(done_msg + padding)
134
+ puts @final_message
142
135
  end
136
+ end
137
+
138
+ def update_progress(task_name)
139
+ @task_name = task_name
140
+ end
141
+
142
+ def succeed(msg)
143
+ @final_message = "✓ #{msg}"
144
+ @spinner.join
145
+ end
143
146
 
144
- yield.tap {
145
- show_spinner = false
146
- spinner.join
147
- }
147
+ def fail(msg)
148
+ @final_message = "✗ #{msg}"
149
+ @spinner.join
148
150
  end
149
151
  end
150
152
  end
@@ -1,3 +1,3 @@
1
1
  module ElectricMonk
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: electric_monk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Dohmen