mercenary 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.markdown +11 -0
- data/README.md +18 -19
- data/lib/mercenary/command.rb +1 -0
- data/lib/mercenary/option.rb +28 -21
- data/lib/mercenary/version.rb +1 -1
- data/spec/command_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c649528973138a967d8f6cafe92e65ae25a4a95
|
4
|
+
data.tar.gz: 3a7b3477db81d199a956536247c0c0e6bd44fda9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 906d1c04846f347c39bed714774527ccc7173b80e15799a69852368003b3d720da0e3dd0134a6069d7e353fa1c77205ca3e29cec731d0172b44377157b664bee
|
7
|
+
data.tar.gz: 6158035bcfa8721c4494498daba38e346d653484b20d29574bda9913dd8fd2f98cfee754227aa28c806a955a627582e3036b2df99819640784dff354152cee9b
|
data/History.markdown
CHANGED
@@ -8,6 +8,17 @@
|
|
8
8
|
|
9
9
|
### Development Fixes
|
10
10
|
|
11
|
+
## 0.3.1 / 2014-02-21
|
12
|
+
|
13
|
+
### Minor Enhancements
|
14
|
+
|
15
|
+
* Add `-t/--trace` to list of options in help message (#19)
|
16
|
+
|
17
|
+
### Bug Fixes
|
18
|
+
|
19
|
+
* `Mercenary::Option` now accepts return values in the form of Class constants
|
20
|
+
(#22)
|
21
|
+
|
11
22
|
## 0.3.0 / 2014-02-20
|
12
23
|
|
13
24
|
### Major Enhancements
|
data/README.md
CHANGED
@@ -22,22 +22,26 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
+
Creating programs and commands with Mercenary is easy:
|
26
|
+
|
25
27
|
```ruby
|
26
28
|
Mercenary.program(:jekyll) do |p|
|
27
29
|
p.version Jekyll::VERSION
|
28
30
|
p.description 'Jekyll is a blog-aware, static site generator in Ruby'
|
31
|
+
p.syntax "jekyll <subcommand> [options]"
|
29
32
|
|
30
33
|
p.command(:new) do |c|
|
31
|
-
c.syntax "
|
34
|
+
c.syntax "new PATH" # do not include the program name or super commands
|
32
35
|
c.description "Creates a new Jekyll site scaffold in PATH"
|
36
|
+
c.option 'blank', '--blank', 'Initialize the new site without any content.'
|
33
37
|
|
34
38
|
c.action do |args, options|
|
35
|
-
Jekyll::Commands::New.process(args)
|
39
|
+
Jekyll::Commands::New.process(args, blank: options['blank'])
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
39
43
|
p.command(:build) do |c|
|
40
|
-
c.syntax "
|
44
|
+
c.syntax "build [options]"
|
41
45
|
c.description "Builds your Jekyll site"
|
42
46
|
|
43
47
|
c.option 'safe', '--safe', 'Run in safe mode'
|
@@ -49,28 +53,23 @@ Mercenary.program(:jekyll) do |p|
|
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
begin
|
58
|
-
require "jekyll-import"
|
59
|
-
rescue
|
60
|
-
msg = "You must install the 'jekyll-import' gem before continuing.\n"
|
61
|
-
msg += "* Do this by running `gem install jekyll-import`.\n"
|
62
|
-
msg += "* Or if you need root privileges, run `sudo gem install jekyll-import`."
|
63
|
-
abort msg
|
64
|
-
end
|
65
|
-
|
66
|
-
Jekyll::Commands::Import.process(args.first, options)
|
67
|
-
end
|
56
|
+
# Bring in command bundled in external gem
|
57
|
+
begin
|
58
|
+
require "jekyll-import"
|
59
|
+
JekyllImport.init_with_program(p)
|
60
|
+
rescue LoadError
|
68
61
|
end
|
69
62
|
|
70
63
|
p.default_command(:build)
|
71
64
|
end
|
72
65
|
```
|
73
66
|
|
67
|
+
All commands have the following default options:
|
68
|
+
|
69
|
+
- `-h/--help` - show a help message
|
70
|
+
- `-v/--version` - show the program version
|
71
|
+
- `-t/--trace` - show the full backtrace when an error occurs
|
72
|
+
|
74
73
|
## Contributing
|
75
74
|
|
76
75
|
1. Fork it
|
data/lib/mercenary/command.rb
CHANGED
@@ -188,6 +188,7 @@ module Mercenary
|
|
188
188
|
def add_default_options(opts)
|
189
189
|
option 'show_help', '-h', '--help', 'Show this message'
|
190
190
|
option 'show_version', '-v', '--version', 'Print the name and version'
|
191
|
+
option 'show_backtrace', '-t', '--trace', 'Show the full backtrace when an error occurs'
|
191
192
|
opts.on("-v", "--version", "Print the version") do
|
192
193
|
puts "#{name} #{version}"
|
193
194
|
abort
|
data/lib/mercenary/option.rb
CHANGED
@@ -1,24 +1,40 @@
|
|
1
1
|
module Mercenary
|
2
2
|
class Option
|
3
|
-
attr_reader :config_key, :description, :
|
3
|
+
attr_reader :config_key, :description, :short, :long, :return_type
|
4
4
|
|
5
5
|
# Public: Create a new Option
|
6
6
|
#
|
7
|
-
# config_key - the key in the config hash to which the value of this option
|
8
|
-
#
|
7
|
+
# config_key - the key in the config hash to which the value of this option
|
8
|
+
# will map
|
9
|
+
# info - an array containing first the switches, then an optional
|
10
|
+
# return type (e.g. Array), then a description of the option
|
9
11
|
#
|
10
12
|
# Returns nothing
|
11
13
|
def initialize(config_key, info)
|
12
|
-
@config_key
|
13
|
-
|
14
|
-
|
14
|
+
@config_key = config_key
|
15
|
+
while arg = info.shift
|
16
|
+
begin
|
17
|
+
@return_type = Object.const_get("#{arg}")
|
18
|
+
next
|
19
|
+
rescue NameError
|
20
|
+
end
|
21
|
+
if arg.start_with?("-")
|
22
|
+
if arg.start_with?("--")
|
23
|
+
@long = arg
|
24
|
+
else
|
25
|
+
@short = arg
|
26
|
+
end
|
27
|
+
next
|
28
|
+
end
|
29
|
+
@description = arg
|
30
|
+
end
|
15
31
|
end
|
16
32
|
|
17
33
|
# Public: Fetch the array containing the info OptionParser is interested in
|
18
34
|
#
|
19
35
|
# Returns the array which OptionParser#on wants
|
20
36
|
def for_option_parser
|
21
|
-
[
|
37
|
+
[short, long, return_type, description].flatten.reject{ |o| o.to_s.empty? }
|
22
38
|
end
|
23
39
|
|
24
40
|
# Public: Build a string representation of this option including the
|
@@ -59,21 +75,12 @@ module Mercenary
|
|
59
75
|
end.all?
|
60
76
|
end
|
61
77
|
|
62
|
-
|
63
|
-
|
64
|
-
# Private: Set the full switches array, ensuring the first element is the
|
65
|
-
# short switch and the second element is the long switch
|
78
|
+
# Public: Fetch an array of switches, including the short and long versions
|
66
79
|
#
|
67
|
-
# Returns
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
switches.unshift ""
|
72
|
-
else
|
73
|
-
switches << ""
|
74
|
-
end
|
75
|
-
end
|
76
|
-
@switches = switches
|
80
|
+
# Returns an array of two strings. An empty string represents no switch in
|
81
|
+
# that position.
|
82
|
+
def switches
|
83
|
+
[short, long].map(&:to_s)
|
77
84
|
end
|
78
85
|
|
79
86
|
end
|
data/lib/mercenary/version.rb
CHANGED
data/spec/command_spec.rb
CHANGED
@@ -60,7 +60,7 @@ describe(Mercenary::Command) do
|
|
60
60
|
option = Mercenary::Option.new(name, opts)
|
61
61
|
command.option name, *opts
|
62
62
|
expect(command.options).to eql([option])
|
63
|
-
expect(command.map).to include(
|
63
|
+
expect(command.map.values).to include(name)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "knows its full name" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mercenary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Preston-Werner
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|