Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Keeping command-line utility templates consistent.

  • Loading branch information...
commit bd6932879a0ab32795c42466b37ee2d0d5d8529d 1 parent 92d41cc
John Barnette authored

Showing 2 changed files with 9 additions and 13 deletions. Show diff stats Hide diff stats

  1. +6 8 bin/pastejour
  2. +3 5 lib/pastejour/cli.rb
14 bin/pastejour
@@ -2,19 +2,17 @@
2 2
3 3 require "pastejour/cli"
4 4
5   -opts = Pastejour::Cli.new STDOUT, ARGV
6   -
7   -if opts.run?
8   - if opts.list?
  5 +Pastejour::Cli.new STDOUT, ARGV do |cli|
  6 + if cli.list?
9 7 Pastejour.list
10 8 elsif $stdin.tty?
11   - name = /#{ENV["USER"]}$/ if opts.name.nil? || opts.name.empty?
  9 + name = /#{ENV["USER"]}$/ if cli.name.nil? || cli.name.empty?
12 10 $stdout.write Pastejour.get(name)
13 11 $stdout.flush
14 12 else
15   - name = [ENV["USER"], opts.name].compact.join "-"
  13 + name = [ENV["USER"], cli.name].compact.join "-"
16 14 contents = $stdin.read
17   - Pastejour.serve name, opts.multiple?, contents
18   - $stdout.puts contents if opts.tee?
  15 + Pastejour.serve name, cli.multiple?, contents
  16 + $stdout.puts contents if cli.tee?
19 17 end
20 18 end
8 lib/pastejour/cli.rb
@@ -39,9 +39,11 @@ def initialize out, args
39 39 end
40 40
41 41 opts.separator ""
42   -
43 42 opts.parse! args
  43 +
44 44 @name = args.shift
  45 +
  46 + yield self if @run && block_given?
45 47 end
46 48 end
47 49
@@ -53,10 +55,6 @@ def multiple?
53 55 @multiple
54 56 end
55 57
56   - def run?
57   - @run
58   - end
59   -
60 58 def tee?
61 59 @tee
62 60 end

0 comments on commit bd69328

Please sign in to comment.
Something went wrong with that request. Please try again.