Permalink
Browse files

Keeping command-line utility templates consistent.

  • Loading branch information...
1 parent 92d41cc commit bd6932879a0ab32795c42466b37ee2d0d5d8529d @jbarnette committed Mar 2, 2009
Showing with 9 additions and 13 deletions.
  1. +6 −8 bin/pastejour
  2. +3 −5 lib/pastejour/cli.rb
View
@@ -2,19 +2,17 @@
require "pastejour/cli"
-opts = Pastejour::Cli.new STDOUT, ARGV
-
-if opts.run?
- if opts.list?
+Pastejour::Cli.new STDOUT, ARGV do |cli|
+ if cli.list?
Pastejour.list
elsif $stdin.tty?
- name = /#{ENV["USER"]}$/ if opts.name.nil? || opts.name.empty?
+ name = /#{ENV["USER"]}$/ if cli.name.nil? || cli.name.empty?
$stdout.write Pastejour.get(name)
$stdout.flush
else
- name = [ENV["USER"], opts.name].compact.join "-"
+ name = [ENV["USER"], cli.name].compact.join "-"
contents = $stdin.read
- Pastejour.serve name, opts.multiple?, contents
- $stdout.puts contents if opts.tee?
+ Pastejour.serve name, cli.multiple?, contents
+ $stdout.puts contents if cli.tee?
end
end
@@ -39,9 +39,11 @@ def initialize out, args
end
opts.separator ""
-
opts.parse! args
+
@name = args.shift
+
+ yield self if @run && block_given?
end
end
@@ -53,10 +55,6 @@ def multiple?
@multiple
end
- def run?
- @run
- end
-
def tee?
@tee
end

0 comments on commit bd69328

Please sign in to comment.