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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 474289f2c16f5a9c803217ab32273e9e98cf926c600c34564ced2eed2eb827ea
4
- data.tar.gz: 62f74ba90e03a7d247696515a6ef8f221155a6f149c53f0c8aa7de687778444e
3
+ metadata.gz: b208dfe9dafa0e901eb87a96fa96a76c188fef825503cb5be5a8cb0965157e87
4
+ data.tar.gz: d4ea792a397b4e149ec38399af01a1120ebaf016f3a360cb658f7026a207b13b
5
5
  SHA512:
6
- metadata.gz: fe882885ec596994f74ff2b2f1eb5137524c46348ce29ef9f2ee38005c03e7f624b351d4bd58341ecbf9be11d8d3c3fffc61bc730aaaf53de6973b5fc6cbcade
7
- data.tar.gz: ed0777d6c669a0194baa20ac26bb3e2ea4fd450346e997ca30e70b1a8da8472a6340af4c1bfaec776b693eacbac3a63abfbd0ed4e8e2b3a51260fc378d7f1480
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
+ [![Gem](https://img.shields.io/gem/v/super_docopt.svg?style=flat-square)](https://rubygems.org/gems/super_docopt)
5
+ [![Build](https://img.shields.io/travis/DannyBen/super_docopt.svg?style=flat-square)](https://travis-ci.org/DannyBen/super_docopt)
6
+ [![Maintainability](https://img.shields.io/codeclimate/maintainability/DannyBen/super_docopt.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/super_docopt)
7
+ [![Issues](https://img.shields.io/codeclimate/issues/github/DannyBen/super_docopt.svg?style=flat-square)](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/
@@ -5,8 +5,7 @@ module SuperDocopt
5
5
  class Base
6
6
  include Singleton
7
7
 
8
- VERSION = '0.0.1'
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 args
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(args)
39
+ def handle_subcommand
41
40
  subcommands.each do |subcommand|
42
- command = subcommand.to_s
43
- method = subcommand.to_s
41
+ input, method = translate_subcommand subcommand
42
+ return execute_subcommand input, method if args[input]
43
+ end
44
+ end
44
45
 
45
- if subcommand.is_a? Hash
46
- command = subcommand.keys.first.to_s
47
- method = subcommand.values.first.to_s
48
- end
46
+ def execute_subcommand(input, method)
47
+ raise NotImplementedError,
48
+ "Please implement ##{method}" unless respond_to? method
49
49
 
50
- command = command.gsub '_', '-'
51
- method = method.gsub '-', '_'
50
+ before_execute
51
+ send method
52
+ after_execute
53
+ end
52
54
 
53
- if args[command]
54
- raise NotImplementedError,
55
- "Please implement ##{method}" unless respond_to? method
55
+ def translate_subcommand(subcommand)
56
+ input = subcommand.to_s
57
+ method = subcommand.to_s
56
58
 
57
- send method, args
58
- return
59
- end
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
@@ -1,3 +1,3 @@
1
1
  module SuperDocopt
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
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.1
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-09 00:00:00.000000000 Z
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: Create command line applications with docopt
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: Docopt extension for easy command line applications
158
+ summary: docopt-based command line utility builder
159
159
  test_files: []