ruby-cmd 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c236384faf0338bb7e48aee0a60d506c4548f218
4
- data.tar.gz: ae9c825eb74ae0b1fbf925e36b8a786ff4468d33
3
+ metadata.gz: 1a991dafdab91418933396f874e6edd8ce202ad9
4
+ data.tar.gz: 751d85061f0253f2e008507973e644451ddd5daf
5
5
  SHA512:
6
- metadata.gz: 67b813a6c73f6ee26ab4cc38ce8d2ce646062592fd4d5b2cb15d99e2386badbef9876cd8fd0264be9fbe6e04cdd8f324dc557132d77fb0eaab923c78cdc807eb
7
- data.tar.gz: ee215c9ccd18d939792843625909bbc8714990ad05c4510ed807065500fbe46a6dca97e10ae977108211e3eb09b8493af21a3b30e48908468bb34418df218134
6
+ metadata.gz: 4e8b4080fa7ee6621d09972d21fd4d4be88254ac365fe004993665872ffadc316910070231d23cb2c7bcf5464a1046f1b015aa4be98b2b1f776c664293075908
7
+ data.tar.gz: 0260980cadc73e403ef46de039a8322517228d10a9176a56ed870ced975ef6abfcc184f561b4dc55e30bb3407af5350843ba0a41b058c491b4ad0c3fc9f9b4fa
data/lib/ruby/cmd.rb CHANGED
@@ -1,85 +1,11 @@
1
1
  require 'ruby/cmd/version'
2
- # require 'ruby/cmd/prompt'
3
-
4
- require 'readline'
2
+ require 'ruby/cmd/prompt'
5
3
 
6
4
  ###
7
5
  #
8
- # This module provides the CLI interface
6
+ # Entry point to Cmd module
9
7
  #
10
8
  ###
11
9
 
12
10
  module Cmd
13
-
14
- ###
15
- #
16
- # This class contains auto complete functionality
17
- # TODO: should be refactored to a new module
18
- #
19
- ###
20
-
21
- class Prompt
22
- def initialize(class_name, prompt = '> ')
23
- @prompt = prompt
24
- @class_name = class_name
25
- @complete_commands = []
26
- @initial_complete_commands = []
27
-
28
- complete
29
-
30
- Readline.completion_append_character = ' '
31
- Readline.basic_word_break_characters = ''
32
-
33
- Readline.completion_proc = proc do |s|
34
- s = update_complete_commands! s
35
- @complete_commands.grep(/^#{Regexp.escape(s)}/)
36
- end
37
- end
38
-
39
- def complete
40
- @complete_commands = (
41
- @class_name.instance_methods.grep(/^do_(.*?)$/).map do |s|
42
- s.to_s.sub('do_', '')
43
- end)
44
- @initial_complete_commands = (
45
- @class_name.instance_methods.grep(/^do_(.*?)$/).map do |s|
46
- s.to_s.sub('do_', '')
47
- end)
48
- end
49
-
50
- # def do_git line
51
- # puts line
52
- # end
53
-
54
- # def complete_git
55
- # %w(clone init commit status push)
56
- # end
57
-
58
- def update_complete_commands! s
59
- args = s.split
60
- command = args.shift
61
- method_names = command.nil? ? [] : @class_name.instance_methods.grep(/^complete_#{Regexp.escape(command)}$/)
62
-
63
- @complete_commands = if command.nil? or method_names.empty?
64
- @initial_complete_commands.clone
65
- else
66
- send(method_names[0]).map {|s| "#{command} #{s}"}
67
- end
68
-
69
- s
70
- end
71
-
72
- def cmd_loop
73
- while true
74
- line = Readline.readline(@prompt, false)
75
- params = line.split
76
- unless params.empty?
77
- method_names = @class_name.instance_methods.grep(/^do_#{Regexp.escape(params.shift)}$/)
78
- send(method_names[0], params.join(' ')) unless method_names.empty?
79
- end
80
-
81
- Readline::HISTORY.push << line if line.to_s.strip != ''
82
- end
83
- end
84
- end
85
- end
11
+ end
@@ -0,0 +1,83 @@
1
+ require 'readline'
2
+
3
+ ###
4
+ #
5
+ # This module provides the CLI interface
6
+ #
7
+ ###
8
+
9
+ module CLI
10
+
11
+ ###
12
+ #
13
+ # This class contains auto complete functionality
14
+ # TODO: should be refactored to a new module
15
+ #
16
+ ###
17
+
18
+ class Prompt
19
+ def initialize(class_name, prompt = "> ")
20
+ @prompt = prompt
21
+ @class_name = class_name
22
+ @complete_commands = []
23
+ @initial_complete_commands = []
24
+
25
+ complete
26
+
27
+ Readline.completion_append_character = " "
28
+ Readline.basic_word_break_characters = ""
29
+
30
+ Readline.completion_proc = proc do |s|
31
+ s = update_complete_commands! s
32
+ @complete_commands.grep(/^#{Regexp.escape(s)}/)
33
+ end
34
+ end
35
+
36
+ def complete
37
+ @complete_commands = @class_name.instance_methods.grep(/^do_(.*?)$/).map {|s| s.to_s.sub("do_", "")}
38
+ @initial_complete_commands = @class_name.instance_methods.grep(/^do_(.*?)$/).map {|s| s.to_s.sub("do_", "")}
39
+ end
40
+
41
+ # def do_git line
42
+ # puts line
43
+ # end
44
+
45
+ # def complete_git
46
+ # %w(clone init commit status push)
47
+ # end
48
+
49
+ def update_complete_commands! s
50
+ args = s.split
51
+ command = args.shift
52
+ method_names = command.nil? ? [] : @class_name.instance_methods.grep(/^complete_#{Regexp.escape(command)}$/)
53
+
54
+ if command.nil? or method_names.empty?
55
+ @complete_commands = @initial_complete_commands.clone
56
+ else
57
+ @complete_commands = self.send(method_names[0]).map {|s| "#{command} #{s}"}
58
+ end
59
+
60
+ s
61
+ end
62
+
63
+ def cmd_loop
64
+ while true
65
+ line = Readline.readline(@prompt, false)
66
+ if line.nil?
67
+ break
68
+ end
69
+ params = line.split
70
+ unless params.empty?
71
+ method_names = @class_name.instance_methods.grep(/^do_#{Regexp.escape(params.shift)}$/)
72
+ unless method_names.empty?
73
+ self.send(method_names[0], params.join(" "))
74
+ end
75
+ end
76
+
77
+ if line.to_s.strip != ""
78
+ Readline::HISTORY.push << line
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module Cmd
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
Binary file
data/ruby-cmd.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/codebrk/ruby-cmd"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.files = `git ls-files -z`.split("\x0").push(*["lib/ruby/cmd/prompt.rb"]).reject { |f| f.match(%r{^(test|spec|features)/}) }
17
17
  spec.bindir = "exe"
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-cmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeeva
@@ -70,7 +70,9 @@ files:
70
70
  - bin/console
71
71
  - bin/setup
72
72
  - lib/ruby/cmd.rb
73
+ - lib/ruby/cmd/prompt.rb
73
74
  - lib/ruby/cmd/version.rb
75
+ - ruby-cmd-0.1.0.gem
74
76
  - ruby-cmd.gemspec
75
77
  homepage: https://github.com/codebrk/ruby-cmd
76
78
  licenses: