super_docopt 0.0.1 → 0.1.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/README.md +59 -0
- data/lib/super_docopt/base.rb +32 -20
- data/lib/super_docopt/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b208dfe9dafa0e901eb87a96fa96a76c188fef825503cb5be5a8cb0965157e87
|
4
|
+
data.tar.gz: d4ea792a397b4e149ec38399af01a1120ebaf016f3a360cb658f7026a207b13b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd9c66bda7521ae87d621e5134bd3ed1b0d2545fddc9baf46b98ea2f646b392f5645e9cf7da8980d2b1350dc9643b17d5e29639e128c23fb7b5a20433de89dc9
|
7
|
+
data.tar.gz: fbf6f682020997cdf125f516977521c2f73071903e5e109cb4167385ac771bf250882a637b197c27f66ce4c4b7ef56c0383c67b3d226e8d8429825c9c478726b
|
data/README.md
CHANGED
@@ -1,2 +1,61 @@
|
|
1
1
|
Super Docopt
|
2
2
|
==================================================
|
3
|
+
|
4
|
+
[](https://rubygems.org/gems/super_docopt)
|
5
|
+
[](https://travis-ci.org/DannyBen/super_docopt)
|
6
|
+
[](https://codeclimate.com/github/DannyBen/super_docopt)
|
7
|
+
[](https://codeclimate.com/github/DannyBen/super_docopt)
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
Create command line utilities with ease.
|
12
|
+
*Super Docopt* is an extension that provides syntactic sugar to [Docopt][1]
|
13
|
+
|
14
|
+
---
|
15
|
+
|
16
|
+
Install
|
17
|
+
--------------------------------------------------
|
18
|
+
|
19
|
+
$ gem install runfile
|
20
|
+
|
21
|
+
|
22
|
+
Example
|
23
|
+
--------------------------------------------------
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# my_command_line.rb
|
27
|
+
require 'super_docopt'
|
28
|
+
|
29
|
+
class MyCommandLine < SuperDocopt::Base
|
30
|
+
version '1.0.0'
|
31
|
+
docopt 'docopt.txt'
|
32
|
+
subcommands ['download', 'upload']
|
33
|
+
|
34
|
+
def download(args)
|
35
|
+
puts "#download called with #{args}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def upload(args)
|
39
|
+
puts "#upload called"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
```plain
|
45
|
+
# docopt.txt
|
46
|
+
My Command Line
|
47
|
+
|
48
|
+
Usage:
|
49
|
+
mock download [--force]
|
50
|
+
mock upload
|
51
|
+
mock (-h|--help|--version)
|
52
|
+
```
|
53
|
+
|
54
|
+
Usage
|
55
|
+
--------------------------------------------------
|
56
|
+
|
57
|
+
Soon
|
58
|
+
|
59
|
+
---
|
60
|
+
|
61
|
+
[1]: http://docopt.org/
|
data/lib/super_docopt/base.rb
CHANGED
@@ -5,8 +5,7 @@ module SuperDocopt
|
|
5
5
|
class Base
|
6
6
|
include Singleton
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
attr_reader :args
|
10
9
|
attr_accessor :version, :docopt, :subcommands
|
11
10
|
|
12
11
|
def self.execute(argv=[])
|
@@ -24,12 +23,12 @@ module SuperDocopt
|
|
24
23
|
def self.subcommands(list)
|
25
24
|
instance.subcommands = list
|
26
25
|
end
|
27
|
-
|
26
|
+
|
28
27
|
def execute_cli(argv=[])
|
29
28
|
doc = File.read docopt
|
30
29
|
begin
|
31
|
-
args = Docopt::docopt(doc, argv: argv, version: version)
|
32
|
-
handle_subcommand
|
30
|
+
@args = Docopt::docopt(doc, argv: argv, version: version)
|
31
|
+
handle_subcommand
|
33
32
|
rescue Docopt::Exit => e
|
34
33
|
puts e.message
|
35
34
|
end
|
@@ -37,27 +36,40 @@ module SuperDocopt
|
|
37
36
|
|
38
37
|
private
|
39
38
|
|
40
|
-
def handle_subcommand
|
39
|
+
def handle_subcommand
|
41
40
|
subcommands.each do |subcommand|
|
42
|
-
|
43
|
-
method
|
41
|
+
input, method = translate_subcommand subcommand
|
42
|
+
return execute_subcommand input, method if args[input]
|
43
|
+
end
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
46
|
+
def execute_subcommand(input, method)
|
47
|
+
raise NotImplementedError,
|
48
|
+
"Please implement ##{method}" unless respond_to? method
|
49
49
|
|
50
|
-
|
51
|
-
|
50
|
+
before_execute
|
51
|
+
send method
|
52
|
+
after_execute
|
53
|
+
end
|
52
54
|
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
def translate_subcommand(subcommand)
|
56
|
+
input = subcommand.to_s
|
57
|
+
method = subcommand.to_s
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
if subcommand.is_a? Hash
|
60
|
+
input = subcommand.keys.first.to_s
|
61
|
+
method = subcommand.values.first.to_s
|
60
62
|
end
|
63
|
+
|
64
|
+
input = input.gsub '_', '-'
|
65
|
+
method = method.gsub '-', '_'
|
66
|
+
|
67
|
+
[input, method]
|
61
68
|
end
|
69
|
+
|
70
|
+
# Overridable Hooks
|
71
|
+
|
72
|
+
def before_execute; end
|
73
|
+
def after_execute; end
|
62
74
|
end
|
63
75
|
end
|
data/lib/super_docopt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super_docopt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: docopt
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '1.5'
|
125
|
-
description:
|
125
|
+
description: Extension to docopt for defining command line utilities with ease
|
126
126
|
email: db@dannyben.com
|
127
127
|
executables: []
|
128
128
|
extensions: []
|
@@ -155,5 +155,5 @@ rubyforge_project:
|
|
155
155
|
rubygems_version: 2.7.3
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
|
-
summary:
|
158
|
+
summary: docopt-based command line utility builder
|
159
159
|
test_files: []
|