Permalink
Browse files

check for LOLCOMMITS_DELAY environment variable to address issue #12

  • Loading branch information...
1 parent d6e965d commit 86a48e8ae25e74b7a777b2e23776766286328ffb @mroth committed Mar 31, 2012
Showing with 9 additions and 6 deletions.
  1. +2 −1 CHANGELOG
  2. +5 −3 bin/lolcommits
  3. +2 −2 lib/lolcommits.rb
View
@@ -1,5 +1,6 @@
0.0.2 (in development)
- * add --delay option to delay image capture (thx JohanB)
+ * add --delay option to delay image capture (thx JohanB), can be
+ persistently set via LOLCOMMITS_DELAY environment variable.
* add --last option to view most recent lolcommit for a repo
0.0.1 (29 March 2012)
View
@@ -77,11 +77,13 @@ end
# IF --CAPTURE, DO CAPTURE
#
def do_capture
+ capture_delay = Choice.choices[:delay] || ENV['LOLCOMMITS_DELAY'] || 0
+
if Choice.choices[:test]
puts "*** capturing in test mode"
- Lolcommits.capture(true, Choice.choices[:msg], Choice.choices[:sha])
+ Lolcommits.capture(capture_delay, true, Choice.choices[:msg], Choice.choices[:sha])
else
- Lolcommits.capture
+ Lolcommits.capture(capture_delay)
end
end
@@ -137,7 +139,7 @@ Choice.options do
desc "delay taking of the snapshot by n seconds"
cast Integer
short '-d'
- default 0
+ #default 0
@mroth

mroth Mar 31, 2012

Owner

This was removed so that it would be nil if not manually set, that way we can determine at runtime whether the user is trying to give a specific command at execute time (which should always be respected), if not, we'll fall back to checking environment variable elsewhere in the code before dropping down to zero.

end
end
View
@@ -26,7 +26,7 @@ def parse_git(dir='.')
return loldir, commit_sha, commit_msg
end
- def capture(is_test=false, test_msg=nil, test_sha=nil)
+ def capture(capture_delay=0, is_test=false, test_msg=nil, test_sha=nil)
#
# Read the git repo information from the current working directory
#
@@ -55,7 +55,7 @@ def capture(is_test=false, test_msg=nil, test_sha=nil)
#
puts "*** Preserving this moment in history."
snapshot_loc = "#{loldir}/tmp_snapshot.jpg"
- system("imagesnap -q #{snapshot_loc} -w #{Choice.choices[:delay]}")
+ system("imagesnap -q #{snapshot_loc} -w #{capture_delay}")
#

3 comments on commit 86a48e8

Contributor

johanb replied Mar 31, 2012

Although not the most elegant of solutions (in my opinion) it works great and will do for now. Personally I think it would be nicest to have the delay passed into the post-commit hook call:

doc = "#!/bin/sh\nlolcommits --capture --delay #{delay}\n"

Although I haven't figured out yet how to pass the delay variable in there. But for now this will do I guess :)

Owner

mroth replied Mar 31, 2012

Ah, the reason I didn't pass it in there is it would basically be impossible to modify later then -- say you want to change the delay, you'd have to track down every single repo you installed it in and modify the stub hook file manually.

Also since the stub files are outside of the gem codebase, I'm trying to keep all logic out of them (hence, stubs), since they can't be upgraded over time along with gem update as the codebase evolves.

Contributor

johanb replied Mar 31, 2012

You're right. Let's leave it like this. I initially thought you might want to have different delays for different projects but I guess that's not really a use case at all.. I only started this delay feature because the pictures it took on an old iMac were dark/black.

Please sign in to comment.