command-set 0.8.3 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- data/doc/GUIDED_TOUR +24 -0
- data/doc/Specifications +50 -8
- data/lib/command-set/command-set.rb +1 -1
- data/lib/command-set/command.rb +1 -21
- data/lib/command-set/dsl.rb +9 -9
- data/lib/command-set/standard-commands.rb +3 -3
- data/lib/command-set/text-interpreter.rb +8 -2
- metadata +8 -4
data/doc/GUIDED_TOUR
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
The quickest way to get a handle on what CommandSet can do for you is to
|
2
|
+
look at the various pieces and get a handle on how they work together.
|
3
|
+
|
4
|
+
The rough sketch is that you enumerate a series of commands, which you then
|
5
|
+
feed to an interpreter. The interpreter will set you up with a template for
|
6
|
+
your porgram's subject, which you fill in with some defaults. Then, give
|
7
|
+
the filled in subject back to the interpreter and let it run.
|
8
|
+
|
9
|
+
Here's the appropriate places to get started:
|
10
|
+
|
11
|
+
0. DSL (Read thoroughly - especially the sub modules)
|
12
|
+
0. BaseInterpreter#subject_template
|
13
|
+
0. BaseInterpreter#subject=
|
14
|
+
0. TextInterpreter#go
|
15
|
+
|
16
|
+
A couple of handy tricks can be found at
|
17
|
+
|
18
|
+
0. BaseInterpreter#process_input
|
19
|
+
0. StandardCommands
|
20
|
+
0. QuickInterpreter
|
21
|
+
|
22
|
+
More advanced stuff that worth learning once your app is off the ground:
|
23
|
+
|
24
|
+
0. Results
|
data/doc/Specifications
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
|
2
|
+
CommandSet::require_commands
|
3
|
+
- should absorb commands from a module
|
4
|
+
- should absorb a single command from a module
|
5
|
+
- should fail when module doesn't define commands
|
6
|
+
|
2
7
|
Empty command set
|
3
8
|
- should_not be nil
|
4
9
|
- should be a CommandSet
|
@@ -23,6 +28,7 @@ Command::DSL::Argument
|
|
23
28
|
- should raise a typeerror on an unhandled type
|
24
29
|
- should raise ArgumentError with missing based_on
|
25
30
|
- should decorate arguments as optional
|
31
|
+
- should document it's own commands
|
26
32
|
|
27
33
|
A NumberArgument
|
28
34
|
- should complete arguments in range
|
@@ -32,20 +38,32 @@ A NumberArgument
|
|
32
38
|
- should not validate non-numeric input
|
33
39
|
- should consume arguments properly
|
34
40
|
|
35
|
-
|
41
|
+
Command::FileArgument
|
36
42
|
- should complete with me
|
43
|
+
- should complete with relative path
|
44
|
+
- should complete with relative dir
|
45
|
+
- should complete at root dir
|
37
46
|
- should complete with list if prefix empty
|
38
47
|
- should validate me
|
39
48
|
- should validate absolute paths
|
40
49
|
- should not validate garbage
|
41
50
|
- should not validate directory
|
42
51
|
|
52
|
+
Command::FileArgument
|
53
|
+
- should be able to create with a block
|
54
|
+
|
43
55
|
A ArrayArgument
|
44
56
|
- should consume legitimate values
|
45
57
|
|
58
|
+
Command::RestOfLineArgument
|
59
|
+
- should consume the rest of the line
|
60
|
+
|
46
61
|
A MultiArgument
|
47
62
|
- Should consume what it can, and put the rest back
|
48
63
|
|
64
|
+
Command::Repeating
|
65
|
+
- should eat many terms, but not all
|
66
|
+
|
49
67
|
Command::AlternatingArgument
|
50
68
|
- should consume to array
|
51
69
|
- should consume to number
|
@@ -77,12 +95,22 @@ Command::TextInterpreter
|
|
77
95
|
|
78
96
|
Command::TextInterpreter all set up
|
79
97
|
- should complete words in the commmand-line
|
80
|
-
- should
|
98
|
+
- should fail on missing commands on the commmand-line
|
99
|
+
- should fail on ambiguous commands on the commmand-line
|
100
|
+
- should complete words from user
|
101
|
+
- should process a single command-line
|
102
|
+
- should process commands from user
|
103
|
+
- should prompt the user and return their answer
|
81
104
|
|
82
105
|
Command::TextInterpreter with a command with a named argument
|
83
106
|
- should complete words in the commmand-line
|
84
107
|
- should process a command-line
|
85
108
|
|
109
|
+
Command::TextInterpreter with serious problems
|
110
|
+
- should ask the user to quit instead of Ctrl-C
|
111
|
+
- should catch command errors and continue
|
112
|
+
- should catch exceptions and quit
|
113
|
+
|
86
114
|
A fresh Subject
|
87
115
|
- should allow a field to be required
|
88
116
|
- should allow multiple fields to be required
|
@@ -149,10 +177,6 @@ Command::Results::Formatter
|
|
149
177
|
- should mark up items as directed by Command#format_advice
|
150
178
|
|
151
179
|
Command::Results::StrategyFormatter
|
152
|
-
1
|
153
|
-
Two
|
154
|
-
Whoa!
|
155
|
-
missing
|
156
180
|
- should
|
157
181
|
|
158
182
|
A command set with the Set command
|
@@ -176,6 +200,12 @@ A CommandSet with Help
|
|
176
200
|
- should gracefully recover if a command has nil documentation
|
177
201
|
- should cope with nil command names in full help listing
|
178
202
|
|
203
|
+
#<Command::CommandSet:0xb75fe940>
|
204
|
+
- should enter and leave a mode
|
205
|
+
|
206
|
+
Command::StandardCommand::Resume
|
207
|
+
- should pause and resume
|
208
|
+
|
179
209
|
Command::OutputStandin undispatched
|
180
210
|
- should return the base IO from getobj
|
181
211
|
- should pass puts unmolested
|
@@ -214,6 +244,18 @@ Command::Results::Presenter driving a Formatter
|
|
214
244
|
Command::Results::Presenter driving a strict Formatter
|
215
245
|
- should send notifications in correct order
|
216
246
|
|
217
|
-
|
247
|
+
Command::Results::XMLFormatter
|
248
|
+
- should format two lists
|
249
|
+
|
250
|
+
Command::Results::StrategyFormatter with indent strategy
|
251
|
+
- should format two lists
|
252
|
+
|
253
|
+
Command::Results::StrategyFormatter with chatty strategy
|
254
|
+
- should format two lists
|
255
|
+
|
256
|
+
Command::Results::StrategyFormatter with progress strategy
|
257
|
+
- should format two lists
|
258
|
+
|
259
|
+
Finished in 0.304894 seconds
|
218
260
|
|
219
|
-
|
261
|
+
161 examples, 0 failures
|
@@ -94,7 +94,7 @@ Command::wrap_stdout
|
|
94
94
|
# automatically gets a command line version, for testing or administrator's
|
95
95
|
# convenience.
|
96
96
|
#
|
97
|
-
#:include: GUIDED_TOUR
|
97
|
+
#:include: doc/GUIDED_TOUR
|
98
98
|
module Command
|
99
99
|
class CommandError < ScriptError; end
|
100
100
|
class CommandException < StandardError
|
data/lib/command-set/command.rb
CHANGED
@@ -246,23 +246,6 @@ module Command
|
|
246
246
|
optional.argument(arg, values, &get_values)
|
247
247
|
end
|
248
248
|
|
249
|
-
def optional_arguments(name, &block)
|
250
|
-
optional.multiword_argument(name, block)
|
251
|
-
end
|
252
|
-
|
253
|
-
def no_more_required_arguments(*args) #:nodoc:
|
254
|
-
raise NoMethodError, "Can't define required arguments after optionals"
|
255
|
-
end
|
256
|
-
private :no_more_required_arguments
|
257
|
-
|
258
|
-
def stop_requireds #:nodoc:
|
259
|
-
class << self
|
260
|
-
alias_method :argument, :no_more_required_arguments
|
261
|
-
def stop_requireds
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
private :stop_requireds
|
266
249
|
end
|
267
250
|
|
268
251
|
extend DSL::CommandDefinition
|
@@ -282,7 +265,7 @@ module Command
|
|
282
265
|
@validation_problem = CommandException.new("No arguments provided!")
|
283
266
|
@last_completed_task = DontResume
|
284
267
|
@resume_from = resume
|
285
|
-
@main_collector =
|
268
|
+
@main_collector = nil
|
286
269
|
end
|
287
270
|
|
288
271
|
attr_reader :arg_hash
|
@@ -443,9 +426,6 @@ module Command
|
|
443
426
|
return nil
|
444
427
|
end
|
445
428
|
|
446
|
-
def collector
|
447
|
-
end
|
448
|
-
|
449
429
|
def validate_arguments
|
450
430
|
raise @validation_problem if Exception === @validation_problem
|
451
431
|
required_arguments.each do |argument|
|
data/lib/command-set/dsl.rb
CHANGED
@@ -418,6 +418,15 @@ Action:: utility functions within the command action block
|
|
418
418
|
def item(name, options={})
|
419
419
|
@main_collector.item(name, options)
|
420
420
|
end
|
421
|
+
|
422
|
+
#This returns a new Results::Collector, which can allow for some very
|
423
|
+
#sophisticated command output. Specifically, it can allow a command
|
424
|
+
#to loop over a large amount of data once, depositing output in
|
425
|
+
#multiple lists at once, for instance a status list (with hashmarks)
|
426
|
+
#and results(with useful data) list.
|
427
|
+
def sub_collector
|
428
|
+
@main_collector.dup
|
429
|
+
end
|
421
430
|
end
|
422
431
|
|
423
432
|
#The methods available within the DSL::CommandDefinition#action method
|
@@ -514,15 +523,6 @@ Action:: utility functions within the command action block
|
|
514
523
|
raise CommandException, "#{@name} cannot be undone"
|
515
524
|
end
|
516
525
|
|
517
|
-
#This returns a new Results::Collector, which can allow for some very
|
518
|
-
#sophisticated command output. Specifically, it can allow a command
|
519
|
-
#to loop over a large amount of data once, depositing output in
|
520
|
-
#multiple lists at once, for instance a status list (with hashmarks)
|
521
|
-
#and results(with useful data) list.
|
522
|
-
def sub_collector
|
523
|
-
@main_collector.dup
|
524
|
-
end
|
525
|
-
|
526
526
|
#This method is deprecated but remains as a nicety. As it stands, any
|
527
527
|
#command can be interrupted at the command line with Ctrl-C, and
|
528
528
|
#return to the prompt.
|
@@ -248,9 +248,9 @@ module StdCmd
|
|
248
248
|
@@set = nil
|
249
249
|
def self.define_commands
|
250
250
|
return @@set ||= Command::CommandSet.define_commands do
|
251
|
-
|
252
|
-
|
253
|
-
|
251
|
+
require_commands Quit
|
252
|
+
require_commands Undo
|
253
|
+
require_commands Help
|
254
254
|
end
|
255
255
|
end
|
256
256
|
end
|
@@ -79,6 +79,10 @@ module Command
|
|
79
79
|
end
|
80
80
|
|
81
81
|
line = readline(get_prompt, true)
|
82
|
+
if line.nil?
|
83
|
+
puts
|
84
|
+
break
|
85
|
+
end
|
82
86
|
next if line.empty?
|
83
87
|
process_line(line)
|
84
88
|
rescue Interrupt
|
@@ -89,7 +93,9 @@ module Command
|
|
89
93
|
output_exception("Exception", e)
|
90
94
|
pause_before_dying
|
91
95
|
ensure
|
92
|
-
|
96
|
+
unless old_proc.nil?
|
97
|
+
set_readline_completion(&old_proc)
|
98
|
+
end
|
93
99
|
end until @stop
|
94
100
|
end
|
95
101
|
|
@@ -204,7 +210,7 @@ module Command
|
|
204
210
|
protected
|
205
211
|
def set_readline_completion(&block)
|
206
212
|
old_proc = Readline.completion_proc
|
207
|
-
Readline.completion_proc = block
|
213
|
+
Readline.completion_proc = proc &block
|
208
214
|
return old_proc
|
209
215
|
end
|
210
216
|
|
metadata
CHANGED
@@ -3,12 +3,12 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: command-set
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.8.
|
7
|
-
date: 2007-12-
|
6
|
+
version: 0.8.4
|
7
|
+
date: 2007-12-20 00:00:00 -08:00
|
8
8
|
summary: Framework for interactive programs focused around a DSL for commands
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
email:
|
11
|
+
email: nyarly@gmail.com
|
12
12
|
homepage:
|
13
13
|
rubyforge_project:
|
14
14
|
description: CommandSet is a interactive program framework. Its focus is a DSL for defining commands, much like Rake or RSpec. The actual interpreter is left as an open question, although a default readline based terminal interpreter is included, it could very well be adapted to interact with CGI or a GUI.
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/command-set/quick-interpreter.rb
|
46
46
|
- lib/command-set/batch-interpreter.rb
|
47
47
|
- doc/README
|
48
|
+
- doc/GUIDED_TOUR
|
48
49
|
- doc/Specifications
|
49
50
|
- doc/argumentDSL
|
50
51
|
test_files: []
|
@@ -55,8 +56,11 @@ rdoc_options:
|
|
55
56
|
- --main
|
56
57
|
- Command
|
57
58
|
- --title
|
58
|
-
- command-set-0.8.
|
59
|
+
- command-set-0.8.4 RDoc
|
59
60
|
extra_rdoc_files:
|
61
|
+
- doc/README
|
62
|
+
- doc/GUIDED_TOUR
|
63
|
+
- doc/Specifications
|
60
64
|
- doc/argumentDSL
|
61
65
|
executables: []
|
62
66
|
|