mercenary 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/History.markdown +51 -0
- data/README.md +15 -0
- data/lib/mercenary/command.rb +33 -0
- data/lib/mercenary/program.rb +1 -1
- data/lib/mercenary/version.rb +1 -1
- data/script/bootstrap +7 -0
- data/script/cibuild +3 -0
- data/spec/command_spec.rb +15 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87eebf74783259bf4e3c5cbc9e3afede61659dd4
|
4
|
+
data.tar.gz: ca77110aa931e23251435f575b14af771781932a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b8bf7ccc50c989fdd2a06bc088d8219254ba7eeb49d8dd42ccba83ceaf12b28f6ef74b5ca3a7cdf568a673da320242019fb0970821aafc95a37014dec2e06a6
|
7
|
+
data.tar.gz: 0f2f3400b7ee7ac5350084294689567132ce5f536b6c9114a403479cda32cffa0fb1ab9267528a3146dbb06ec99af0dad952d4abcef37047920b87bb86a48c02
|
data/.travis.yml
CHANGED
data/History.markdown
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
## HEAD
|
2
|
+
|
3
|
+
### Major Enhancements
|
4
|
+
|
5
|
+
### Minor Enhancements
|
6
|
+
|
7
|
+
### Bug Fixes
|
8
|
+
|
9
|
+
### Development Fixes
|
10
|
+
|
11
|
+
## 0.2.0 / 2013-11-30
|
12
|
+
|
13
|
+
### Major Enhancements
|
14
|
+
|
15
|
+
* Add `Command#default_command` to specify a default command if none is given
|
16
|
+
by the user at runtime (#7)
|
17
|
+
|
18
|
+
### Minor Enhancements
|
19
|
+
|
20
|
+
* Add `Command#execute` to execute the actions of a command (#6)
|
21
|
+
|
22
|
+
### Development Fixes
|
23
|
+
|
24
|
+
* Add standard GitHub bootstrap and cibuild scripts to `script/` (#2)
|
25
|
+
|
26
|
+
## 0.1.0 / 2013-11-08
|
27
|
+
|
28
|
+
### Major Enhancements
|
29
|
+
|
30
|
+
* It works!
|
31
|
+
|
32
|
+
### Minor Enhancements
|
33
|
+
|
34
|
+
* Add a logger to `Command`
|
35
|
+
* Add `--version` switch to all programs
|
36
|
+
|
37
|
+
### Bug Fixes
|
38
|
+
|
39
|
+
* Fix `Command#syntax` and `Command#description`'s handing of setting vs getting
|
40
|
+
* Fix load path problem in `lib/mercenary.rb`
|
41
|
+
|
42
|
+
### Development Fixes
|
43
|
+
|
44
|
+
* Add TomDoc to everything
|
45
|
+
* Add a couple starter specs
|
46
|
+
* Add TravisCI badge
|
47
|
+
* Add Travis configuration
|
48
|
+
|
49
|
+
## 0.0.1 / 2013-11-06
|
50
|
+
|
51
|
+
* Birthday!
|
data/README.md
CHANGED
@@ -34,6 +34,19 @@ Mercenary.program(:jekyll) do |p|
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
p.command(:build) do |c|
|
38
|
+
c.syntax "jekyll build [options]"
|
39
|
+
c.description "Builds your Jekyll site"
|
40
|
+
|
41
|
+
c.option 'safe', '--safe', 'Run in safe mode'
|
42
|
+
c.option 'source', '--source DIR', 'From where to collect the source files'
|
43
|
+
c.option 'destination', '--dest DIR', 'To where the compiled files should be written'
|
44
|
+
|
45
|
+
c.action do |_, options|
|
46
|
+
Jekyll::Commands::Build.process(options)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
37
50
|
p.command(:import) do |c|
|
38
51
|
c.syntax "jekyll import <platform> [options]"
|
39
52
|
c.description "Import your old blog to Jekyll"
|
@@ -51,6 +64,8 @@ Mercenary.program(:jekyll) do |p|
|
|
51
64
|
Jekyll::Commands::Import.process(args.first, options)
|
52
65
|
end
|
53
66
|
end
|
67
|
+
|
68
|
+
p.default_command(:build)
|
54
69
|
end
|
55
70
|
```
|
56
71
|
|
data/lib/mercenary/command.rb
CHANGED
@@ -45,6 +45,25 @@ module Mercenary
|
|
45
45
|
@description
|
46
46
|
end
|
47
47
|
|
48
|
+
# Public: Sets the default command
|
49
|
+
#
|
50
|
+
# command_name - the command name to be executed in the event no args are
|
51
|
+
# present
|
52
|
+
#
|
53
|
+
# Returns the default command if there is one, `nil` otherwise
|
54
|
+
def default_command(command_name = nil)
|
55
|
+
if command_name
|
56
|
+
if commands.has_key?(command_name)
|
57
|
+
@default_command = commands[command_name] if command_name
|
58
|
+
@default_command
|
59
|
+
else
|
60
|
+
raise ArgumentError.new("'#{command_name}' couldn't be found in this command's list of commands.")
|
61
|
+
end
|
62
|
+
else
|
63
|
+
@default_command
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
48
67
|
# Public: Adds an option switch
|
49
68
|
#
|
50
69
|
# sym - the variable key which is used to identify the value of the switch
|
@@ -141,6 +160,20 @@ module Mercenary
|
|
141
160
|
end
|
142
161
|
end
|
143
162
|
|
163
|
+
# Public: Execute all actions given the inputted args and options
|
164
|
+
#
|
165
|
+
# argv - (optional) command-line args (sans opts)
|
166
|
+
# config - (optional) the Hash configuration of string key to value
|
167
|
+
#
|
168
|
+
# Returns nothing
|
169
|
+
def execute(argv = [], config = {})
|
170
|
+
if actions.empty? && !default_command.nil?
|
171
|
+
default_command.execute
|
172
|
+
else
|
173
|
+
actions.each { |a| a.call(argv, config) }
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
144
177
|
# Public: Check if this command has a subcommand
|
145
178
|
#
|
146
179
|
# sub_command - the name of the subcommand
|
data/lib/mercenary/program.rb
CHANGED
data/lib/mercenary/version.rb
CHANGED
data/script/bootstrap
ADDED
data/script/cibuild
ADDED
data/spec/command_spec.rb
CHANGED
@@ -4,13 +4,18 @@ describe(Mercenary::Command) do
|
|
4
4
|
|
5
5
|
context "a basic command" do
|
6
6
|
let(:command) { Mercenary::Command.new(:my_name) }
|
7
|
+
let(:parent) { Mercenary::Command.new(:my_parent) }
|
8
|
+
let(:with_sub) do
|
9
|
+
c = Mercenary::Command.new(:i_have_subcommand)
|
10
|
+
add_sub.call(c)
|
11
|
+
c
|
12
|
+
end
|
7
13
|
let(:command_with_parent) do
|
8
14
|
Mercenary::Command.new(
|
9
15
|
:i_have_parent,
|
10
16
|
parent
|
11
17
|
)
|
12
18
|
end
|
13
|
-
let(:parent) { Mercenary::Command.new(:my_parent) }
|
14
19
|
let(:add_sub) do
|
15
20
|
Proc.new do |c|
|
16
21
|
c.command(:sub_command) { |p| }
|
@@ -50,6 +55,15 @@ describe(Mercenary::Command) do
|
|
50
55
|
expect(command.options).to eq([opt])
|
51
56
|
expect(command.map).to include({opt.first => name})
|
52
57
|
end
|
58
|
+
|
59
|
+
it "raises an ArgumentError if I specify a default_command that isn't there" do
|
60
|
+
c = command # some weird NameError with the block below?
|
61
|
+
expect { c.default_command(:nope) }.to raise_error(ArgumentError)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "sets the default_command" do
|
65
|
+
expect(with_sub.default_command(:sub_command).name).to eq(:sub_command)
|
66
|
+
end
|
53
67
|
end
|
54
68
|
|
55
69
|
end
|
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.
|
4
|
+
version: 0.2.0
|
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: 2013-
|
12
|
+
date: 2013-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- .rspec
|
66
66
|
- .travis.yml
|
67
67
|
- Gemfile
|
68
|
+
- History.markdown
|
68
69
|
- LICENSE.txt
|
69
70
|
- README.md
|
70
71
|
- Rakefile
|
@@ -73,6 +74,8 @@ files:
|
|
73
74
|
- lib/mercenary/program.rb
|
74
75
|
- lib/mercenary/version.rb
|
75
76
|
- mercenary.gemspec
|
77
|
+
- script/bootstrap
|
78
|
+
- script/cibuild
|
76
79
|
- spec/command_spec.rb
|
77
80
|
- spec/program_spec.rb
|
78
81
|
- spec/spec_helper.rb
|
@@ -96,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
99
|
version: '0'
|
97
100
|
requirements: []
|
98
101
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.0.
|
102
|
+
rubygems_version: 2.0.14
|
100
103
|
signing_key:
|
101
104
|
specification_version: 4
|
102
105
|
summary: Lightweight and flexible library for writing command-line apps in Ruby.
|