idonethis-cli 0.5.0 → 0.6.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 +4 -4
- data/lib/adapters/cli.rb +4 -2
- data/lib/idonethis/cli/version.rb +1 -1
- data/lib/idonethis/use_cases/git.rb +48 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30f5aa9e1c0e1d380417d536f50ad961d469e10f
|
4
|
+
data.tar.gz: e2b4dc443c372988ef7cb77592cd585ba9d53d3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 365a7684422c9e41c01b181137878b236db31042d192ef7605b2d42f8ecbf7d21ed9657680124481c1b190d2088e412d4db642b5ec0393fc3546106552c4ba8f
|
7
|
+
data.tar.gz: e824be3315ea9ca705c0f3dceb59e7107338d7761f2dd508c559548d354b6d7d5e47dc9dcdf4e9b9c6de65718c186897d7750645cf1ac4cfd4a081fb1daf6927
|
data/lib/adapters/cli.rb
CHANGED
@@ -11,11 +11,13 @@ module Idonethis::Adapters
|
|
11
11
|
args = parse(argv)
|
12
12
|
|
13
13
|
command,*rest = argv
|
14
|
+
|
15
|
+
log = choose_log(args)
|
14
16
|
|
15
17
|
args.merge!({ opts: rest, log: log, internet: Idonethis::Adapters::Internet, view: Idonethis::Adapters::Views::Cli::List.method(:apply)})
|
16
18
|
credential = Settings.credential
|
17
19
|
|
18
|
-
log
|
20
|
+
log.call "args: #{args}, command: #{command}, rest: #{rest}"
|
19
21
|
|
20
22
|
use_cases = {
|
21
23
|
list: Idonethis::UseCases::List.method(:apply),
|
@@ -37,7 +39,7 @@ module Idonethis::Adapters
|
|
37
39
|
|
38
40
|
private
|
39
41
|
|
40
|
-
def
|
42
|
+
def choose_log(args={})
|
41
43
|
args[:verbose] == true ? ->(msg){puts "[LOG] #{msg}"} : ->(_){}
|
42
44
|
end
|
43
45
|
|
@@ -4,31 +4,70 @@ module Idonethis::UseCases
|
|
4
4
|
def apply(credential, args={})
|
5
5
|
log = args[:log] || fail("You need to supply :log adapter")
|
6
6
|
|
7
|
-
|
7
|
+
log.call args
|
8
8
|
|
9
|
-
|
9
|
+
opts = args[:opts]
|
10
|
+
|
11
|
+
dir = opts.any? ? File.expand_path(opts.first) : File.expand_path(".")
|
10
12
|
|
11
|
-
|
13
|
+
if opts.any?
|
14
|
+
all_dirs = directories_in(dir)
|
15
|
+
|
16
|
+
log.call("All directories in <#{dir}>: #{all_dirs}")
|
17
|
+
|
18
|
+
dirs_that_have_changed_today = all_dirs.select{|it| modified_today?(it, log) }
|
12
19
|
|
13
|
-
|
20
|
+
puts "Scanning dir <#{dir}>, which has <#{dirs_that_have_changed_today.size}> repositories that have changed today\n\n"
|
21
|
+
|
22
|
+
summarise *dirs_that_have_changed_today
|
23
|
+
|
24
|
+
puts ""
|
25
|
+
else
|
26
|
+
puts "Scanning the current directory <#{dir}>\n\n"
|
27
|
+
summarise dir
|
28
|
+
end
|
29
|
+
end
|
14
30
|
|
15
|
-
|
31
|
+
def summarise(*dirs)
|
32
|
+
dirs.each do |dir|
|
16
33
|
summary = commit_summary(dir)
|
17
|
-
puts %Q{#{Pathname.new(dir).basename} (#{summary.size}):\n-- #{summary.join("\n-- ")}
|
34
|
+
puts %Q{#{Pathname.new(dir).basename} (#{summary.size}):\n-- #{summary.join("\n-- ")}}
|
18
35
|
end
|
36
|
+
end
|
19
37
|
|
20
|
-
|
38
|
+
def directories_in(dir)
|
39
|
+
Dir.entries(dir).
|
40
|
+
reject{|it| ["..", "."].include?(it) }.
|
41
|
+
select{|it| File.directory?(File.join(dir, it))}.
|
42
|
+
map{ |it| File.expand_path(File.join(dir, it))}
|
21
43
|
end
|
22
44
|
|
23
|
-
def
|
45
|
+
def modified_today?(dir, log)
|
46
|
+
time = File.ctime(dir)
|
24
47
|
now = Time.now
|
48
|
+
|
49
|
+
any_file_changed_today?(dir, time, now, log).tap do |result|
|
50
|
+
log.call "[#{dir}] Comparing mtime <#{time}> to today <#{now}>. Today? <#{result}>"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def any_file_changed_today?(dir, time, now, log)
|
55
|
+
Dir["#{dir}/**/**"].select do |file|
|
56
|
+
mtime = File.ctime(file)
|
57
|
+
log.call "File <#{file}> has mtime <#{mtime}>"
|
58
|
+
return true if today?(mtime, now)
|
59
|
+
end
|
60
|
+
return false
|
61
|
+
end
|
62
|
+
|
63
|
+
def today?(time, now)
|
25
64
|
time.year == now.year && time.month == now.month && time.day == now.day
|
26
65
|
end
|
27
66
|
|
28
67
|
def commit_summary(dir)
|
29
68
|
require 'git'
|
30
69
|
git = ::Git.open(dir)
|
31
|
-
git.log.since('1am').
|
70
|
+
git.log.since('1am').map{|it| %Q{[#{it.date.strftime("%H:%M")}] #{it.message}}}
|
32
71
|
end
|
33
72
|
end
|
34
73
|
end
|