cmd 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/Rakefile +1 -1
- data/TODO +36 -0
- data/example/my-phonebook.rb +72 -0
- data/lib/cmd.rb +6 -1
- metadata +12 -10
data/CHANGELOG
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
= Cmd Changelog
|
2
2
|
|
3
|
+
== Version 0.7.1
|
4
|
+
|
5
|
+
* Broke assignment to READLINE_SUPPORTED over several lines as removing the
|
6
|
+
semicolons resulted in the incorrect behavior, and having the semicolons made
|
7
|
+
RDoc fail to parse the file. [Jim Weirich]
|
8
|
+
|
3
9
|
== Version 0.7.0
|
4
10
|
|
5
11
|
* Initial public release
|
data/Rakefile
CHANGED
data/TODO
CHANGED
@@ -4,6 +4,38 @@ Send suggestions for this list to marcel@vernix.org.
|
|
4
4
|
|
5
5
|
== Todo list
|
6
6
|
|
7
|
+
* The subclassing from Cmd and defining do_ methods for commands paradigm is a
|
8
|
+
bit limiting. So, ideas for radical change:
|
9
|
+
|
10
|
+
Cmd is a module. All do_ methods are no longer the way to write commands.
|
11
|
+
There are two ways to get Cmd functionality into a class.
|
12
|
+
|
13
|
+
1) You mix in Cmd::Interpreter (or something like that). You then just define
|
14
|
+
methods in the class where Cmd::Interpreter is mixed in, and then use a
|
15
|
+
command macro to indicate that the method is a command.
|
16
|
+
|
17
|
+
e.g.
|
18
|
+
command :add
|
19
|
+
def add(etc)
|
20
|
+
|
21
|
+
This would be useful fo pre-existing classes that would like to add Cmd
|
22
|
+
behavior. [credit Chad Fowler and Sam Stephenson]
|
23
|
+
|
24
|
+
2) There is a Cmd::Base class that mixes in Cmd::Interpreter. You inherit
|
25
|
+
from Cmd::Base and in this case all methods that are public are commands
|
26
|
+
implicitly without needing to use the +command+ macro. This base class would
|
27
|
+
be a convenience class that automatically defnotes every public method as a
|
28
|
+
command method.
|
29
|
+
|
30
|
+
* Cmd::ClassMethods sucks. Using the singleton vars sucks. Create a metaprogramming
|
31
|
+
framework that is self hosting. It would be used to create the domain
|
32
|
+
language that would describe domain languages. [credit Sam Stephenson]
|
33
|
+
|
34
|
+
* Create a way to define named-parameter options hashes and define certain
|
35
|
+
options as depending on other options. The allowed parameters should be able
|
36
|
+
to be changed depending on the values of a certain parameter. [credit Sam
|
37
|
+
Stephenson]
|
38
|
+
|
7
39
|
* Writing a complete_(command name) is enough to have the completion results be
|
8
40
|
displayed, but not enough to actually complete. In order to complete as well
|
9
41
|
there must be additional logic such as what complete_grep does. So right now
|
@@ -76,6 +108,10 @@ Send suggestions for this list to marcel@vernix.org.
|
|
76
108
|
|
77
109
|
I think that's pretty nice.
|
78
110
|
|
111
|
+
UPDATE: The above todo regarding making Cmd a module and having the choice of
|
112
|
+
subclassing Cmd::Base or mixing in something like Cmd::Interpreter obsoletes
|
113
|
+
this approach.
|
114
|
+
|
79
115
|
* Take another shot at having more objects (e.g. Command, Subcommand,
|
80
116
|
Documentation, etc)
|
81
117
|
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'cmd'
|
5
|
+
rescue LoadError
|
6
|
+
require File.dirname(__FILE__) + '/../lib/cmd'
|
7
|
+
end
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
class PhoneBook < Cmd
|
11
|
+
STORAGE = File.expand_path('~/.phonebook')
|
12
|
+
|
13
|
+
doc :list, "List names in phone book."
|
14
|
+
def do_list
|
15
|
+
write @data.names
|
16
|
+
end
|
17
|
+
|
18
|
+
doc :add, "Add an entry into the phone book."
|
19
|
+
def do_add
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def setup
|
26
|
+
create_storage_if_need_be
|
27
|
+
File.open(STORAGE) do |file|
|
28
|
+
@data = YAML.load(file)
|
29
|
+
end
|
30
|
+
rescue
|
31
|
+
write "Unable to load phonebook - #$!"
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_storage_if_need_be
|
36
|
+
File.open(STORAGE, 'w') unless File.exists?(STORAGE)
|
37
|
+
end
|
38
|
+
|
39
|
+
def postloop
|
40
|
+
save_data
|
41
|
+
end
|
42
|
+
|
43
|
+
def save_data
|
44
|
+
write 'Saving...'
|
45
|
+
File.open(STORAGE, 'w') do |file|
|
46
|
+
file.write YAML.dump(@data)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class PhoneBookListing
|
52
|
+
|
53
|
+
attr_accessor :name, :number, :type
|
54
|
+
def initialize
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class PhoneBookList
|
59
|
+
def initialize
|
60
|
+
@list = []
|
61
|
+
end
|
62
|
+
|
63
|
+
def <<(listing)
|
64
|
+
@list.push listing
|
65
|
+
end
|
66
|
+
|
67
|
+
def names
|
68
|
+
@list.map {|listing| listing.name}.sort
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
PhoneBook.run
|
data/lib/cmd.rb
CHANGED
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.8
|
3
3
|
specification_version: 1
|
4
4
|
name: cmd
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.7.
|
7
|
-
date: 2005-04-
|
6
|
+
version: 0.7.1
|
7
|
+
date: 2005-04-11
|
8
8
|
summary: A generic class to build line-oriented command interpreters.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,21 +29,23 @@ authors:
|
|
29
29
|
files:
|
30
30
|
- test
|
31
31
|
- lib
|
32
|
-
-
|
33
|
-
- setup.rb
|
32
|
+
- example
|
34
33
|
- AUTHORS
|
35
|
-
- TODO
|
36
34
|
- INSTALL
|
37
|
-
- example
|
38
|
-
- CHANGELOG
|
39
|
-
- THANKS
|
40
35
|
- MIT-LICENSE
|
36
|
+
- THANKS
|
37
|
+
- Rakefile
|
41
38
|
- download
|
39
|
+
- rdoc
|
40
|
+
- setup.rb
|
41
|
+
- TODO
|
42
|
+
- CHANGELOG
|
42
43
|
- README
|
43
44
|
- lib/cmd.rb
|
44
45
|
- test/tc_cmd.rb
|
45
|
-
- example/phonebook.rb
|
46
46
|
- example/calc.rb
|
47
|
+
- example/my-phonebook.rb
|
48
|
+
- example/phonebook.rb
|
47
49
|
test_files:
|
48
50
|
- test/tc_cmd.rb
|
49
51
|
rdoc_options:
|