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.
- data/README.md +11 -5
- data/VERSION +1 -1
- data/clive.gemspec +10 -6
- data/lib/clive.rb +9 -50
- data/lib/clive/bool.rb +64 -0
- data/lib/clive/command.rb +288 -0
- data/lib/clive/exceptions.rb +48 -0
- data/lib/clive/ext.rb +3 -12
- data/lib/clive/flag.rb +71 -0
- data/lib/clive/option.rb +77 -0
- data/lib/clive/switch.rb +40 -0
- data/lib/clive/tokens.rb +4 -4
- data/test/bin_test +20 -4
- data/test/test_boolean.rb +13 -6
- data/test/test_clive.rb +36 -3
- data/test/test_command.rb +44 -0
- data/test/test_flag.rb +40 -1
- data/test/test_token.rb +22 -9
- metadata +12 -8
- data/lib/clive/booleans.rb +0 -37
- data/lib/clive/commands.rb +0 -317
- data/lib/clive/flags.rb +0 -17
- data/lib/clive/switches.rb +0 -39
data/lib/clive/flags.rb
DELETED
@@ -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
|
data/lib/clive/switches.rb
DELETED
@@ -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
|