lib/papers/cli.rb in papers-2.4.1 vs lib/papers/cli.rb in papers-2.4.2
- old
+ new
@@ -3,50 +3,52 @@
module Papers
class CLI
def run
- if options[:generate]
- begin
- Papers::ManifestGenerator.new.generate!
- rescue Papers::FileExistsError => e
- warn "Error: 'papers_manifest.yml' already exists at '#{e.message}'. Aborting..."
- end
- end
+ options.parse!
- if options[:update]
+ case @command
+ when :generate
+ Papers::ManifestGenerator.new.generate!
+ when :update
Papers::ManifestUpdater.new.update!
+ when :help
+ emit_help ""
+ else
+ emit_help "Unrecognized command."
end
+ rescue Papers::FileExistsError => e
+ warn "Error: 'papers_manifest.yml' already exists at '#{e.message}'. Aborting..."
+ rescue OptionParser::ParseError => e
+ emit_help "Problem parsing options: #{e.message}"
end
private
def options
- @options ||= parse_options
- end
+ @options ||= OptionParser.new do |opts|
+ opts.banner = 'Usage: papers [options]'
- def parse_options
- options = {}
- OptionParser.new do |opts|
- opts.banner = "Usage: papers [options]"
-
- opts.on("-g", "--generate", "Generate papers_manifest.yml") do |v|
- options[:generate] = v
+ opts.on('-g', '--generate', 'Generate papers_manifest.yml') do |v|
+ @command = :generate
end
opts.on("-u", "--update", "Update papers_manifest.yml for Rubygems") do |v|
- options[:update] = v
+ @command = :update
end
- opts.on_tail( '-h', '--help', 'Display this screen' ) do |v|
- p opts
- exit
+ opts.on('-h', '--help', 'Display this screen') do
+ @command = :help
end
- @avail_opts = opts
- end.parse!
+ end
+ end
- p @avail_opts if options.empty?
-
- return options
+ def emit_help(header)
+ unless header.empty?
+ puts header
+ puts
+ end
+ puts options
end
end
end