shell-base 0.1.1 → 0.1.2

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: fa79fe78424802c99dbcd0d71c9d98663c2ce978
4
- data.tar.gz: 38acfc0732dfbde7045ac5b33614e8bf661e00a0
3
+ metadata.gz: 26b534bc1605227dad77821842bf5c839b29f35b
4
+ data.tar.gz: cf118fcb64ca07918db99c924d34056b2387aa81
5
5
  SHA512:
6
- metadata.gz: 24bbca9a3a50afa14f04ca899ede765ea9a3d3057b23814eeb699ce64d8981e5eb63dd48ad0c111c862855a6648d08d374d9a295d1fd8ffd4f19fcdde84d4f22
7
- data.tar.gz: 07a25afc2f0bb5ed2ea9dd9c57f01a6804bce6404c44dd093544e6d5b44354b51b3f0d73127cdd5b51288fa97177200df7288fc37d539cf83c136e83cdac9613
6
+ metadata.gz: 64ffba11aee7a2c6a41b18927be6fc9149f3fbca21b7f709695d747bbb45e150df2285013b90d88c76b56e750f73dd432c74cb28fbe2f4543085d8df849cbab9
7
+ data.tar.gz: 21429508ee917377b3dbaab607cee5af63520a28b3430df0786a7537528eec803cd7ce3f2203bbcf7df06570e295e9969fa21ecfd32a2dfa969c900b8208656f
data/README.md CHANGED
@@ -18,7 +18,23 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ```ruby
22
+ class ExampleShell < ShellBase
23
+ prompt "example:$ "
24
+
25
+ def hello(*params)
26
+ puts "hello " + params.join(" ") + "."
27
+ @prompt = "example:#{params[0] || ''}:$ "
28
+ end
29
+ end
30
+ ExampleShell.new
31
+ ```
32
+
33
+ for example implemented `hello` command.
34
+
35
+ And exit to `exit` command.
36
+
37
+ `@prompt` instance variable is prompt string.
22
38
 
23
39
  ## Contributing
24
40
 
data/lib/shell_base.rb CHANGED
@@ -2,6 +2,7 @@ require 'shell_base/version'
2
2
  require 'readline'
3
3
 
4
4
  class ShellBase
5
+ class Exit < Exception; end
5
6
  def self.prompt(s)
6
7
  @@default_prompt = s
7
8
  end
@@ -11,15 +12,23 @@ class ShellBase
11
12
  while readline; end
12
13
  end
13
14
 
15
+ def exit
16
+ puts "bye."
17
+ raise Exit
18
+ end
19
+
20
+ def method_missing(method_name)
21
+ puts method_name.to_s + ": Command not found"
22
+ end
23
+
14
24
  def readline
15
25
  input = Readline.readline(@prompt, true).split(" ")
16
26
  cmd = input.shift
17
27
 
18
- return if cmd == 'exit'
19
- if respond_to? cmd
28
+ begin
20
29
  send(cmd, *input)
21
- else
22
- puts cmd + ": Command not found"
30
+ rescue Exit
31
+ return false
23
32
  end
24
33
  true
25
34
  end
@@ -1,3 +1,3 @@
1
1
  class ShellBase
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shell-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - myun2