mercenary 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/mercenary.rb +18 -0
- data/lib/mercenary/command.rb +82 -0
- data/lib/mercenary/program.rb +39 -0
- data/lib/mercenary/version.rb +3 -0
- data/mercenary.gemspec +23 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 467dae27c989bd4d07318b1965e6e28930f90aeb
|
4
|
+
data.tar.gz: be71811e5f88c21cc07105822a0d77874893617f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf722d831a506ee191a2609b3420e132f50ddd4d00f87cc3686376767321a77af4310c0f71e481c1138d610b0780395e6b73fda297829b9a8ad8d3846e4160cc
|
7
|
+
data.tar.gz: c9080a9dbcdda0da115f5d22b511bb20d6e7ce1fe08611076c81c007f69dcd72b96c8a2d6fde4b5694c6ee76c9878cba30f23b9507e1528e8a44a48965c4f9e0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Parker Moore
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Mercenary
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mercenary'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mercenary
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/mercenary.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "mercenary/version"
|
2
|
+
require "optparse"
|
3
|
+
|
4
|
+
module Mercenary
|
5
|
+
autoload :Command, "mercenary/command"
|
6
|
+
autoload :Program, "mercenary/program"
|
7
|
+
|
8
|
+
# Public: Instantiate a new program and execute.
|
9
|
+
#
|
10
|
+
# name - the name of your program
|
11
|
+
#
|
12
|
+
# Returns nothing.
|
13
|
+
def self.program(name)
|
14
|
+
program = Program.new(name)
|
15
|
+
yield program
|
16
|
+
program.go(ARGV)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Mercenary
|
2
|
+
class Command
|
3
|
+
attr_reader :name
|
4
|
+
attr_reader :description
|
5
|
+
attr_reader :syntax
|
6
|
+
attr_accessor :options
|
7
|
+
attr_accessor :commands
|
8
|
+
attr_accessor :actions
|
9
|
+
attr_reader :map
|
10
|
+
attr_accessor :parent
|
11
|
+
|
12
|
+
def initialize(name, parent = nil)
|
13
|
+
@name = name
|
14
|
+
@options = []
|
15
|
+
@commands = {}
|
16
|
+
@actions = []
|
17
|
+
@map = {}
|
18
|
+
@parent = parent
|
19
|
+
end
|
20
|
+
|
21
|
+
def syntax(syntax)
|
22
|
+
@syntax = syntax
|
23
|
+
end
|
24
|
+
|
25
|
+
def description(desc)
|
26
|
+
@description = desc
|
27
|
+
end
|
28
|
+
|
29
|
+
def option(sym, *options)
|
30
|
+
@options << options
|
31
|
+
@map[options[0]] = sym
|
32
|
+
end
|
33
|
+
|
34
|
+
def command(cmd_name)
|
35
|
+
cmd = Command.new(cmd_name, self)
|
36
|
+
yield cmd
|
37
|
+
@commands[cmd_name] = cmd
|
38
|
+
end
|
39
|
+
|
40
|
+
def alias(cmd_name)
|
41
|
+
@parent.commands[cmd_name] = self
|
42
|
+
end
|
43
|
+
|
44
|
+
def action(&block)
|
45
|
+
@actions << block
|
46
|
+
end
|
47
|
+
|
48
|
+
def go(argv, opts, config)
|
49
|
+
process_options(opts, config)
|
50
|
+
|
51
|
+
if argv[0] && cmd = commands[argv[0].to_sym]
|
52
|
+
puts "Found #{cmd.name}"
|
53
|
+
argv.shift
|
54
|
+
cmd.go(argv, opts, config)
|
55
|
+
else
|
56
|
+
puts "No additional command found, time to exec"
|
57
|
+
self
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def process_options(opts, config)
|
62
|
+
options.each do |o|
|
63
|
+
opts.on(*o) do |x|
|
64
|
+
config[map[o[0]]] = x
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def ident
|
70
|
+
"<Command name=#{name}>"
|
71
|
+
end
|
72
|
+
|
73
|
+
def inspect
|
74
|
+
msg = ''
|
75
|
+
msg += "Command #{name}\n"
|
76
|
+
options.each { |o| msg += " " + o.inspect + "\n"}
|
77
|
+
msg += "\n"
|
78
|
+
commands.each { |k, v| msg += commands[k].inspect }
|
79
|
+
msg
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Mercenary
|
2
|
+
class Program < Command
|
3
|
+
attr_reader :version
|
4
|
+
attr_reader :description
|
5
|
+
attr_reader :optparse
|
6
|
+
attr_reader :config
|
7
|
+
|
8
|
+
def initialize(name)
|
9
|
+
@config = {}
|
10
|
+
super(name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def version(version)
|
14
|
+
@version = version
|
15
|
+
end
|
16
|
+
|
17
|
+
def description(description)
|
18
|
+
@description = description
|
19
|
+
end
|
20
|
+
|
21
|
+
def go(argv)
|
22
|
+
p argv
|
23
|
+
puts
|
24
|
+
p self
|
25
|
+
|
26
|
+
cmd = nil
|
27
|
+
|
28
|
+
@optparse = OptionParser.new do |opts|
|
29
|
+
cmd = super(argv, opts, @config)
|
30
|
+
end
|
31
|
+
|
32
|
+
@optparse.parse!(argv)
|
33
|
+
|
34
|
+
p @config
|
35
|
+
|
36
|
+
cmd.actions.each { |a| a.call(argv, @config) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/mercenary.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mercenary/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mercenary"
|
8
|
+
spec.version = Mercenary::VERSION
|
9
|
+
spec.authors = ["Parker Moore", "Tom Preston-Werner"]
|
10
|
+
spec.email = ["parkrmoore@gmail.com", "tom@mojombo.com"]
|
11
|
+
spec.description = %q{Write better command-line apps.}
|
12
|
+
spec.summary = %q{Write better command-line apps.}
|
13
|
+
spec.homepage = "http://github.com/jekyll/mercenary"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mercenary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Parker Moore
|
8
|
+
- Tom Preston-Werner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
description: Write better command-line apps.
|
43
|
+
email:
|
44
|
+
- parkrmoore@gmail.com
|
45
|
+
- tom@mojombo.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- .gitignore
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/mercenary.rb
|
56
|
+
- lib/mercenary/command.rb
|
57
|
+
- lib/mercenary/program.rb
|
58
|
+
- lib/mercenary/version.rb
|
59
|
+
- mercenary.gemspec
|
60
|
+
homepage: http://github.com/jekyll/mercenary
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.0.3
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Write better command-line apps.
|
84
|
+
test_files: []
|