Skip to content

Commit

Permalink
added ANSI coloured output messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodacious committed Jan 28, 2012
1 parent e51d05a commit 0de5355
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 14 deletions.
57 changes: 55 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,55 @@
Files in this directory are used to replace those that are stamped in specs so we start
each test with fresh, unstamped files.
# Katana Code's Copyright Stamper

This gem is used internally by Katana Code. Feel free to fork it and modify for your
own organisation.

## Usage:

$ katana_stamp

adds **(c) Copyright 2012 Katana Code Ltd. All Rights Reserved.** to the end of every Ruby file under app/ and lib/.

See options below for configuration

## Options

### --include-dirs (-i)

Include these dir patterns in stamp list
e.g.
$ katana_stamp -i vendor/**/*.rb # will also stamp files matching vendor/**/*.rb

### --exclude-dirs (-x)

Don't include these dir patterns in stamp list
e.g.

$ katana_stamp -x app/controllers/application_controller.rb # will not stamp files matching app/controllers/application_controller.rb

### --year (-y)

Change the year of the Copyright
e.g.

$ katana_stamp -y 1999


### --owner (-o)

Change the owner of the Copyright
e.g.

$ katana_stamp -o "Ace Rimmer!"


### --message (-m)

Overwrite the entire message for the stamp.
e.g.

$ katana_stamp -m "Released under the MIT license"

## Known Issues

At the moment there's no way to reverse this... make sure you commit any changes before you
run this!
3 changes: 2 additions & 1 deletion app/models/test_model_one.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class TestModelOne

end
end
# (c) Copyright 2012 Katana Code Ltd. All Rights Reserved.
3 changes: 2 additions & 1 deletion app/models/test_model_two.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class TestModelTwo

end
end
# (c) Copyright 2012 Katana Code Ltd. All Rights Reserved.
4 changes: 2 additions & 2 deletions bin/katana_stamp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require 'optparse'
options = {}

OptionParser.new do |opts|
opts.banner = File.read('README.md')
opts.banner = "Katana Stamp Usage:"

opts.on("-i", "--include-dirs x,y,x", Array,
"Include these dir patterns in stamp list") do |v|
Expand All @@ -35,4 +35,4 @@ OptionParser.new do |opts|

end.parse!

KatanaStamp.run!(options)
exit(KatanaStamp.run!(options))
24 changes: 20 additions & 4 deletions lib/katana_stamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@ def run!(options={})
Dir.glob(main_dir).each do |path|
next if options[:exclude_paths].detect { |pattern| File.fnmatch(pattern, path) }
custom_file = StampFile.new(path, options)
custom_file.stamp unless custom_file.has_stamp?
if custom_file.has_stamp?
print_colour("#{path} already stamped!", :yellow)
else
print_colour("#{path} stamped!", :green)
custom_file.stamp
end
end
end
true # return true
end


def self.print_colour(message, colour)
colour_id =
case colour
when :yellow then 33
when :green then 32
else
37 # white
end
puts "\033[0;#{colour_id}m#{message}\033[0m"
end

module_function :run!

end
# (c) Copyright 2012 Katana Code Ltd. All Rights Reserved.
end
3 changes: 1 addition & 2 deletions lib/katana_stamp/stamp_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ def last_line
end

end
end
# (c) Copyright 2012 Katana Code Ltd. All Rights Reserved.
end
3 changes: 1 addition & 2 deletions lib/katana_stamp/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
module KatanaStamp
VERSION = "0.1.0"
end
# (c) Copyright 2012 Katana Code Ltd. All Rights Reserved.
end

0 comments on commit 0de5355

Please sign in to comment.