clive 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +0,0 @@
1
- class Clive
2
-
3
- # A switch that takes an argument, with or without an equals
4
- # eg. wget --tries=10
5
- # wget -t 10
6
- #
7
- class Flag < Switch
8
-
9
- # Runs the block that was given with an argument
10
- #
11
- # @param [String] arg argument to pass to the block
12
- def run(arg)
13
- @block.call(arg)
14
- end
15
-
16
- end
17
- end
@@ -1,39 +0,0 @@
1
- class Clive
2
-
3
- # A string that takes no argument, beginning with one or two dashes
4
- # eg. ruby --version
5
- # ruby -v
6
- #
7
- class Switch
8
- attr_accessor :short, :long, :desc, :block
9
-
10
- def initialize(short, long, desc, &block)
11
- @short = short
12
- @long = long
13
- @desc = desc
14
- @block = block
15
- end
16
-
17
- # Runs the block that was given
18
- def run
19
- @block.call
20
- end
21
-
22
- # @return [String] summary for help
23
- def summary(width=30, prepend=5)
24
- a = ""
25
- a << "-#{@short}" if @short
26
- a << ", " if @short && @long
27
- a << "--#{@long}" if @long
28
- b = @desc
29
- s, p = '', ''
30
- # want at least one space between name and desc
31
- spaces = width-a.length < 0 ? 1 : width-a.length
32
- (0...spaces).each {s << ' '}
33
- (0...prepend).each {p << ' '}
34
- "#{p}#{a}#{s}#{b}"
35
- end
36
-
37
- end
38
-
39
- end