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 +4 -4
- data/README.md +17 -1
- data/lib/shell_base.rb +13 -4
- data/lib/shell_base/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26b534bc1605227dad77821842bf5c839b29f35b
|
4
|
+
data.tar.gz: cf118fcb64ca07918db99c924d34056b2387aa81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
19
|
-
if respond_to? cmd
|
28
|
+
begin
|
20
29
|
send(cmd, *input)
|
21
|
-
|
22
|
-
|
30
|
+
rescue Exit
|
31
|
+
return false
|
23
32
|
end
|
24
33
|
true
|
25
34
|
end
|
data/lib/shell_base/version.rb
CHANGED