Permalink
Browse files

Fixed examples in README. Also fixed erroneous argument descriptions …

…in `--help` argument.
  • Loading branch information...
1 parent 0f4e153 commit 5b1ba6ef5e35553a6854699027e93c97ee6157d9 @osterman committed Nov 12, 2013
Showing with 48 additions and 30 deletions.
  1. +22 −8 README.md
  2. +11 −11 lib/copyright_header/command_line.rb
  3. +15 −11 lib/copyright_header/parser.rb
View
@@ -16,6 +16,7 @@ Caveats
-------
* Will only remove headers to files that have exactly the same header as the one we added
* Will only add headers to files which do not contain the case-sensitive pattern `/[Cc]opyright|[Lc]icense/` in the first `N` lines
+* Will not properly format arguments that contain new-line ("`\n`") characters.
Requirements
------------
@@ -35,17 +36,17 @@ Usage
Full list of supported arguments:
- Usage: bin/copyright-header options [file]
+ Usage: copyright-header options [file]
-n, --dry-run Output the parsed files to STDOUT
-o, --output-dir DIR Use DIR as output directory
--license-file FILE Use FILE as header (instead of using --license argument)
- --license [AGPL3|BSD-2-CLAUSE|BSD-3-CLAUSE|BSD-4-CLAUSE|GPL3|MIT]
+ --license [AGPL3|ASL2|BSD-2-CLAUSE|BSD-3-CLAUSE|BSD-4-CLAUSE|GPL3|MIT]
Use LICENSE as header
--copyright-software NAME The common name for this piece of software (e.g. "Copyright Header")
--copyright-software-description DESC
- The common name for this piece of software (e.g. "A utility to manipulate copyright headers on source code files")
- --copyright-holder NAME The common name for this piece of software (e.g. "Erik Osterman <e@osterman.com>"). Repeat argument for multiple names.
- --copyright-year YEAR The common name for this piece of software (e.g. "2012"). Repeat argument for multiple years.
+ The detailed description for this piece of software (e.g. "A utility to manipulate copyright headers on source code files")
+ --copyright-holder NAME The legal owner of the copyright for the software. (e.g. "Erik Osterman <e@osterman.com>"). Repeat argument for multiple names.
+ --copyright-year YEAR The years for which the copyright exists (e.g. "2012"). Repeat argument for multiple years.
-w, --word-wrap LEN Maximum number of characters per line for license (default: 80)
-a, --add-path PATH Recursively insert header in all files found in path (allows multiple paths separated by platform path-separator ":")
-r, --remove-path PATH Recursively remove header in all files found in path (allows multiple paths separated by platform path-separator ":")
@@ -54,7 +55,6 @@ Full list of supported arguments:
-V, --version Display version information
-h, --help Display this screen
-
Examples
--------
@@ -64,11 +64,25 @@ Discover available parameters by passing the `--help` argument
Add a GPL3 License header to a file:
- copyright-header --add-path /tmp/test.rb --license GPL3 --dry-run
+ copyright-header --add-path /tmp/test.rb \
+ --license GPL3 \
+ --copyright-holder 'Joe Shmoe' \
+ --copyright-software 'Example Software' \
+ --copyright-software-description "This is the description of the software." \
+ --copyright-year 2012 \
+ --output-dir /tmp \
+ --dry-run
Remove the header created in the previous step (without --dry-run argument):
- copyright-header --remove-path /tmp/test.rb --license GPL3 --dry-run
+ copyright-header --remove-path /tmp/test.rb \
+ --license GPL3 \
+ --copyright-holder 'Joe Shmoe' \
+ --copyright-software 'Example Software' \
+ --copyright-software-description 'This is the description of the software.' \
+ --copyright-year 2012 \
+ --output-dir /tmp \
+ --dry-run
Command used to generate copyright headers for this script:
@@ -38,7 +38,7 @@ def initialize(options = {})
end
opts.on( '-o', '--output-dir DIR', 'Use DIR as output directory') do |dir|
- @options[:output_dir] = dir + '/'
+ @options[:output_dir] = dir.gsub(/\/+$/, '')
end
opts.on( '--license-file FILE', 'Use FILE as header (instead of using --license argument)' ) do|file|
@@ -53,17 +53,17 @@ def initialize(options = {})
@options[:copyright_software] = name
end
- opts.on( '--copyright-software-description DESC', 'The common name for this piece of software (e.g. "A utility to manipulate copyright headers on source code files")' ) do|desc|
+ opts.on( '--copyright-software-description DESC', 'The detailed description for this piece of software (e.g. "A utility to manipulate copyright headers on source code files")' ) do|desc|
@options[:copyright_software_description] = desc
end
@options[:copyright_holders] ||= []
- opts.on( '--copyright-holder NAME', 'The common name for this piece of software (e.g. "Erik Osterman <e@osterman.com>"). Repeat argument for multiple names.' ) do|name|
+ opts.on( '--copyright-holder NAME', 'The legal owner of the copyright for the software. (e.g. "Erik Osterman <e@osterman.com>"). Repeat argument for multiple names.' ) do|name|
@options[:copyright_holders] << name
end
@options[:copyright_years] ||= []
- opts.on( '--copyright-year YEAR', 'The common name for this piece of software (e.g. "2012"). Repeat argument for multiple years.' ) do|year|
+ opts.on( '--copyright-year YEAR', 'The years for which the copyright exists (e.g. "2012"). Repeat argument for multiple years.' ) do|year|
@options[:copyright_years] << year
end
@@ -91,11 +91,11 @@ def initialize(options = {})
end
opts.on( '-V', '--version', 'Display version information' ) do
- puts "CopyrightHeader #{CopyrightHeader::VERSION}"
- puts "Copyright (C) 2012 Erik Osterman <e@osterman.com>"
- puts "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>"
- puts "This is free software: you are free to change and redistribute it."
- puts "There is NO WARRANTY, to the extent permitted by law."
+ STDERR.puts "CopyrightHeader #{CopyrightHeader::VERSION}",
+ "Copyright (C) 2012 Erik Osterman <e@osterman.com>",
+ "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>",
+ "This is free software: you are free to change and redistribute it.",
+ "There is NO WARRANTY, to the extent permitted by law."
exit
end
@@ -130,13 +130,13 @@ def initialize(options = {})
raise MissingArgumentException.new("Missing --copyright-year argument") unless @options[:copyright_years].length > 0
end
rescue MissingArgumentException => e
- puts e.message
- puts @optparse
+ STDERR.puts e.message, @optparse
exit (1)
end
end
def execute
+ STDERR.puts "-- DRY RUN --" if @options[:dry_run]
@parser = CopyrightHeader::Parser.new(@options)
@parser.execute
end
@@ -82,7 +82,7 @@ def add(license)
copyright = self.format(license)
if copyright.nil?
- puts "Copyright is nil"
+ STDERR.puts "Copyright is nil"
return nil
end
@@ -121,7 +121,7 @@ def remove(license)
@contents.gsub!(/#{Regexp.escape(text)}/, '')
@contents
else
- puts "SKIP #{@file}; copyright not detected"
+ STDERR.puts "SKIP #{@file}; copyright not detected"
return nil
end
end
@@ -206,27 +206,27 @@ def transform(method, path)
begin
if File.file?(path)
if @exclude.include? File.basename(path)
- puts "SKIP #{path}; excluded"
+ STDERR.puts "SKIP #{path}; excluded"
next
end
else
- puts "SKIP #{path}; not file"
+ STDERR.puts "SKIP #{path}; not file"
next
end
if @syntax.supported?(path)
header = @syntax.header(path)
contents = header.send(method, @license)
if contents.nil?
- puts "SKIP #{path}; failed to generate license"
+ STDERR.puts "SKIP #{path}; failed to generate license"
else
write(path, contents)
end
else
- puts "SKIP #{path}; unsupported"
+ STDERR.puts "SKIP #{path}; unsupported"
end
rescue Exception => e
- puts "SKIP #{path}; #{e.message}"
+ STDERR.puts "SKIP #{path}; #{e.message}"
end
end
end
@@ -242,11 +242,15 @@ def remove(dir)
end
def write(file, contents)
- puts "UPDATE #{file}"
- if @options[:dry_run] || @options[:output_dir].nil?
- puts contents
+ if @options[:dry_run]
+ STDERR.puts "UPDATE #{file} [dry-run]"
+ STDERR.puts contents
+ elsif @options[:output_dir].nil?
+ STDERR.puts "UPDATE #{file} [no output-dir]"
+ STDERR.puts contents
else
- dir = "#{@options[:output_dir]}/#{File.dirname(file)}"
+ dir = "#{@options[:output_dir]}/#{File.dirname(file).gsub(/^\/+/, '')}"
+ STDERR.puts "UPDATE #{file} [output-dir #{dir}]"
FileUtils.mkpath dir unless File.directory?(dir)
output_path = @options[:output_dir] + file
f =File.new(output_path, 'w')

0 comments on commit 5b1ba6e

Please sign in to comment.