idonethis-cli 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7732c6eb7d9765b37d6cf669a2ce808b4d9563ca
4
- data.tar.gz: ad003f1a99ae40d0d74cae19545022ff184e1441
3
+ metadata.gz: 30f5aa9e1c0e1d380417d536f50ad961d469e10f
4
+ data.tar.gz: e2b4dc443c372988ef7cb77592cd585ba9d53d3b
5
5
  SHA512:
6
- metadata.gz: eb24e43e8bd7526d8c919c53d4114986f759dd9074a06faca053f6e38733177657abb807f7c65e44d69874d7a2fec8f972a3953b91d5856a4d6912891f8bf59c
7
- data.tar.gz: 7c3e268399456085c795284825636f64f5fced2f147a027d0a91ee0ebdca4b572d1ac8dfdeed88886860172799f10a65487aab358e80c747840521b0d1250b70
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(args).call "args: #{args}, command: #{command}, rest: #{rest}"
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 log(args={})
42
+ def choose_log(args={})
41
43
  args[:verbose] == true ? ->(msg){puts "[LOG] #{msg}"} : ->(_){}
42
44
  end
43
45
 
@@ -1,5 +1,5 @@
1
1
  module Idonethis
2
2
  module Cli
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -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
- dir = File.expand_path("..")
7
+ log.call args
8
8
 
9
- all_dirs = Dir.entries(dir).reject{|it| ["..", "."].include?(it) }.select{|it| File.directory?(File.join(dir, it))}.map{|it| File.join(dir, it)}
9
+ opts = args[:opts]
10
+
11
+ dir = opts.any? ? File.expand_path(opts.first) : File.expand_path(".")
10
12
 
11
- dirs_that_have_changed_today = all_dirs.select{|it| today?(File.mtime(it)) }
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
- puts "Scanning dir <#{dir}>, which has <#{dirs_that_have_changed_today.size}> repositories that have changed\n\n"
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
- dirs_that_have_changed_today.each do |dir|
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
- puts ""
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 today?(time)
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').take(10).map{|it| %Q{[#{it.date.strftime("%H:%M")}] #{it.message}}}
70
+ git.log.since('1am').map{|it| %Q{[#{it.date.strftime("%H:%M")}] #{it.message}}}
32
71
  end
33
72
  end
34
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idonethis-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Biddington