thor-levenshtein 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jiunn Haur Lim
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.
@@ -0,0 +1,31 @@
1
+ # Thor::Levenshtein
2
+ [![Build Status](https://travis-ci.org/jimjh/thor-levenshtein.png?branch=master)](https://travis-ci.org/jimjh/thor-levenshtein)
3
+
4
+ ## Usage
5
+ To use, just add `thor-levenshtein` to your Gemfile and require it as follows:
6
+
7
+ ```ruby
8
+ require 'thor/levenshtein'
9
+
10
+ class A < Thor
11
+ desc "describe NAME", "say that someone is amazing"
12
+ method_options :forcefully => :boolean
13
+ def describe(name, opts)
14
+ ret = "#{name} is amazing"
15
+ puts opts["forcefully"] ? ret.upcase : ret
16
+ end
17
+ desc 'protect', 'declare loyalty to Asgard'
18
+ def protect(name, opts)
19
+ puts 'I live to protect Asgard.'
20
+ end
21
+ end
22
+ ```
23
+
24
+ #### Output
25
+ ```sh
26
+ $> ./a.rb dscribe
27
+ Could not find task "dscribe".
28
+
29
+ Did you mean this?
30
+ describe
31
+ ```
@@ -0,0 +1,30 @@
1
+ # ~*~ encoding: utf-8 ~*~
2
+ require 'levenshtein'
3
+
4
+ class Thor
5
+ module Base
6
+
7
+ module ClassMethods
8
+
9
+ def handle_no_task_error(task, has_namespace = $thor_runner) #:nodoc:
10
+ if has_namespace
11
+ message = "Could not find task #{task.inspect} in #{namespace.inspect} namespace."
12
+ else
13
+ message = "Could not find task #{task.inspect}."
14
+ end
15
+ suggestion = find_suggestion task
16
+ message += "\n\nDid you mean this?\n\t#{suggestion}" if suggestion
17
+ raise UndefinedTaskError, message
18
+ end
19
+
20
+ protected
21
+
22
+ # Finds a correct command with the shortest edit distance from +task+.
23
+ def find_suggestion(task)
24
+ all_tasks.keys.min_by { |key| ::Levenshtein.distance task, key }
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ class Thor
2
+ module Levenshtein
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thor-levenshtein
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jiunn Haur Lim
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.16.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.16.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: levenshtein
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.2.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.2.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 10.0.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 10.0.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.12.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.12.0
78
+ description: Thor that suggest possible commands when you make a typo.
79
+ email:
80
+ - codex.is.poetry@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - LICENSE
86
+ - README.md
87
+ - lib/thor/levenshtein/version.rb
88
+ - lib/thor/levenshtein.rb
89
+ homepage: https://github.com/jimjh/thor-levenshtein
90
+ licenses:
91
+ - MIT
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 1.9.2
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ segments:
109
+ - 0
110
+ hash: 3221524789103941959
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.24
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: Thor with auto-suggest
117
+ test_files: []