Changeset 181
- Timestamp:
- 11/10/04 21:51:29 (4 years ago)
- Files:
-
- manage/trunk (modified) (1 prop)
- manage/trunk/CLI.pm (modified) (7 diffs)
- manage/trunk/plugins/nodelist2.pm (modified) (2 diffs)
- manage/trunk/.todo (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
manage/trunk
- Property svn:ignore set to
.todo.*
- Property svn:ignore set to
manage/trunk/CLI.pm
r180 r181 110 110 # node, or undef if not found. 111 111 # 112 # parse_node(\@tokens [, $node, \@args, $ trackall])113 # parse_node($ctx [, $ trackall])112 # parse_node(\@tokens [, $node, \@args, $checkpoint]) 113 # parse_node($ctx [, $checkpoint]) 114 114 sub parse_node { 115 115 my $self = shift; 116 116 my $ctx = shift; 117 117 my $cmd = $ctx->current_grammar(); 118 my $ trackallparent = @_ ? shift() : 0;118 my $checkpoint = @_ ? shift() : undef; 119 119 my $token = $ctx->next_token(); 120 120 my ($width, $height) = GetTerminalSize(*STDIN); … … 167 167 } 168 168 169 # If we have a checkpoint, bring in the help 170 $process_help->($checkpoint->{HELP}, \%commands) 171 if defined($checkpoint->{HELP}) and defined($cmd->{ACTION}) and defined($checkpoint); 172 169 173 # If this node can be a terminating node, check for an ACTIONHELP 170 174 # key. If it exists, use this as the help line for <eol>, otherwise try … … 181 185 } 182 186 } 183 $commands{'<eol>'} = 'Execute command.' if $trackallparent; 187 188 $commands{'<eol>'} = 'Execute command.' if $checkpoint and not defined($commands{'<eol>'}) and defined($cmd->{ACTION}); 184 189 185 190 my $keywidth = 0; … … 244 249 my $key = $rx; 245 250 my $trackvar = 0; 246 my $ trackall= 0;251 my $newcheckpoint = 0; 247 252 248 253 # Skip if help 249 254 next if $rx =~ /^HELP/; 250 251 # Find out if this candidate is a unique minimum match252 # my $unique = 0;253 255 254 256 # Remove ordering token … … 261 263 # Remove wildcard 262 264 if ($rx =~ /^\*/) { 263 $ trackall = 1;265 $newcheckpoint = $cmd->{$key}; 264 266 $rx =~ s/^\*//; 265 267 } 266 268 } 267 268 # if (defined($token)) {269 # my @candidates = grep(/^(\d+\))?(\$(\*)?)?\q$token\e/, keys(%$cmd));270 #271 # $unique = 1 if @candidates == 1 and $candidates[0] eq $key;272 # }273 269 274 270 if ((!defined($token) and $rx eq 'ACTION') or (defined($token) and $token =~ /^(?:$rx)$/is)) { … … 309 305 310 306 # Recurse if we are tracking 311 return $self->parse_node($ctx->next_grammar($cmd ), $trackall)312 if $ctx->more_tokens() and $ trackall;307 return $self->parse_node($ctx->next_grammar($cmd->{$key}), $newcheckpoint) 308 if $ctx->more_tokens() and $newcheckpoint; 313 309 314 310 if ($type eq 'HASH') { 315 311 $ctx->inject_token($token) if $rx eq 'ACTION'; 316 return $self->parse_node($ctx->next_grammar($cmd->{$key}) );312 return $self->parse_node($ctx->next_grammar($cmd->{$key}), $checkpoint); 317 313 } elsif ($type eq 'CODE') { 318 314 # Tokens are still remaining … … 336 332 return ('ERROR', $error, $ctx); 337 333 } else { 338 # if (defined($token)) { 339 # my @rawcandidates = grep(/^(\d+\))?(\$(\*)?)?\Q$token\E/, keys(%$cmd)); 340 # 341 # if (@rawcandidates > 1) { 342 # my @candidates = (); 343 # 344 # for my $c (@rawcandidates) { 345 # my $cp = $c; 346 # 347 # $cp =~ s/^(\d+\))?(\$(\*)?)?//; 348 # push(@candidates, $cp); 349 # } 350 # return ('ERROR', "No unique candidates for '$token', candidates are '@candidates'", $ctx) 351 # } 352 # } 334 return $self->parse_node($ctx->next_grammar($checkpoint), $checkpoint) 335 if $checkpoint; 353 336 return ('ERROR', "Unrecognized command '$token'.", $ctx); 354 337 } manage/trunk/plugins/nodelist2.pm
r174 r181 3 3 { 4 4 test => { 5 '1)lalala' => sub { print "FOO\n"; }, 6 '2)$.*' => { 7 VALIDATE => 1, 8 HELP => sub { 9 return ( 10 foo => 1, 11 bar => 2, 12 ); 5 '$*foo|bar' => { 6 HELP => { 7 foo => "Foo", 8 bar => "Bar", 13 9 }, 14 ACTION => { 15 ACTION => sub { 16 my $c = shift; 17 18 print("@_\n"); 19 }, 20 HELP => "Do it.", 21 }, 22 }, 23 }, 24 user => { 25 HELP => 'NL2 user management.', 26 '1)add' => { 27 HELP => 'Add a new user.', 28 '$[\w-]+' => { 29 HELP => 'Username to add.', 30 '$.*' => { 31 HELP => 'User description.', 10 '$.+' => { 11 HELP => [ "<value>", "Some value" ], 12 ACTION => { 13 HELP => "Test foo or bar", 32 14 ACTION => sub { 33 15 }, … … 35 17 }, 36 18 }, 37 '2)show' => {38 ACTION => sub {39 },40 HELP => 'List users.'41 },42 '3)$[\w -]+' => {43 HELP => [ '<username>', 'User to manage.' ],44 remove => {45 HELP => 'Remove user.',46 ACTION => sub {47 },48 },49 lock => {50 HELP => 'Lock user.',51 ACTION => sub {52 },53 },54 show => {55 HELP => 'Show user details, including configuration values.',56 ACTION => sub {57 },58 },59 set => {60 HELP => 'Set user configuration values.',61 '$[\w-]+' => {62 HELP => ['<key>', 'User configuration key to set.' ],63 '$.*' => {64 HELP => ['<value>', 'Value to set configuration key to.' ],65 ACTION => sub {66 },67 },68 },69 },70 unset => {71 HELP => 'Remove a user configuration key.',72 '$[\w-]+' => {73 HELP => 'Configuration key to remove.',74 ACTION => sub {75 },76 },77 },78 '$\d+' => {79 HELP => sub {80 return (81 '<digit>' => 'Fooobbrr'82 );83 },84 },85 },86 19 }, 87 20 }; manage/trunk/.todo
r170 r181 1 <!-- Automagically generated by the ToDo program on Thu Jul 1 17:54:52 2004-->2 <todo version="0.1.1 7">1 <!-- Automagically generated by the ToDo program on 11/11/04, 13:31 --> 2 <todo version="0.1.18"> 3 3 <title> 4 4 Manage - command line interface intfrastructure 5 5 </title> 6 <note priority="high" time="1088668492" >6 <note priority="high" time="1088668492" done="1100140286"> 7 7 Because shortest match is allowed on grammar nodes, we need to expand the matches before execution. eg. The command "a u barry" might match the grammar "add $user barry", but the arg $user is passed as "u" to the final ACTION. Not good. 8 <comment> 9 No longer supporting short match, too hard. 10 </comment> 8 11 </note> 9 12 </todo>
