Skip to content

Commit

Permalink
Keeping command-line utility templates consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarnette committed Mar 2, 2009
1 parent 92d41cc commit bd69328
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 6 additions & 8 deletions bin/pastejour
Expand Up @@ -2,19 +2,17 @@


require "pastejour/cli" require "pastejour/cli"


opts = Pastejour::Cli.new STDOUT, ARGV Pastejour::Cli.new STDOUT, ARGV do |cli|

if cli.list?
if opts.run?
if opts.list?
Pastejour.list Pastejour.list
elsif $stdin.tty? 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.write Pastejour.get(name)
$stdout.flush $stdout.flush
else else
name = [ENV["USER"], opts.name].compact.join "-" name = [ENV["USER"], cli.name].compact.join "-"
contents = $stdin.read contents = $stdin.read
Pastejour.serve name, opts.multiple?, contents Pastejour.serve name, cli.multiple?, contents
$stdout.puts contents if opts.tee? $stdout.puts contents if cli.tee?
end end
end end
8 changes: 3 additions & 5 deletions lib/pastejour/cli.rb
Expand Up @@ -39,9 +39,11 @@ def initialize out, args
end end


opts.separator "" opts.separator ""

opts.parse! args opts.parse! args

@name = args.shift @name = args.shift

yield self if @run && block_given?
end end
end end


Expand All @@ -53,10 +55,6 @@ def multiple?
@multiple @multiple
end end


def run?
@run
end

def tee? def tee?
@tee @tee
end end
Expand Down

0 comments on commit bd69328

Please sign in to comment.