Changeset 174
- Timestamp:
- 07/07/04 02:10:37 (4 years ago)
- Files:
-
- manage/trunk/CLI.pm (modified) (3 diffs)
- manage/trunk/manage (modified) (1 diff)
- manage/trunk/plugins/nodelist2.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
manage/trunk/CLI.pm
r173 r174 115 115 my $token = $ctx->next_token(); 116 116 my ($width, $height) = GetTerminalSize(*STDIN); 117 my $process_help = sub { 118 my $help = shift; 119 my $commands = shift; 120 my $command = shift; 121 my $type = ref($help); 122 123 if ($type eq 'ARRAY') { 124 $commands->{$help->[0]} = $help->[1]; 125 } elsif ($type eq 'CODE') { 126 %$commands = (%$commands, $help->($ctx, @{$ctx->args()})); 127 } elsif (!$type) { 128 $commands->{$command} = $help; 129 } 130 }; 117 131 118 132 # Help!! … … 130 144 # Construct help string 131 145 $help .= $format->paragraphs(split(/^\s*$/m, $cmd->{HELPHEADER})) . "\n" if $cmd->{HELPHEADER}; 132 133 my $process_help = sub {134 my $help = shift;135 my $commands = shift;136 my $command = shift;137 my $type = ref($help);138 139 if ($type eq 'ARRAY') {140 $commands->{$help->[0]} = $help->[1];141 } elsif ($type eq 'CODE') {142 %$commands = (%$commands, $help->($ctx, @{$ctx->args()}));143 } elsif (!$type) {144 $commands->{$command} = $help;145 }146 };147 146 148 147 for my $key (keys %$cmd) { … … 270 269 # Do validation 271 270 if ($cmd->{$key}->{VALIDATE}) { 272 return ('ERROR', "Invalid input '$token'.", $ctx) 273 unless $cmd->{$key}->{VALIDATE}->($ctx, $token, @{$ctx->args()}); 271 my $type = ref($cmd->{$key}->{VALIDATE}); 272 273 if (not $type) { 274 if ($cmd->{$key}->{VALIDATE} and $cmd->{$key}->{HELP}) { 275 my %commands; 276 277 $process_help->($cmd->{$key}->{HELP}, \%commands, '<eol>'); 278 return ('ERROR', "Invalid input '$token'.", $ctx) 279 unless $commands{$token}; 280 } 281 } elsif ($type eq 'CODE') { 282 return ('ERROR', "Invalid input '$token'.", $ctx) 283 unless $cmd->{$key}->{VALIDATE}->($ctx, $token, @{$ctx->args()}); 284 } elsif ($type eq 'HASH') { 285 return ('ERROR', "Invalid input '$token'.", $ctx) 286 unless $cmd->{$key}->{VALIDATE}->{$token}; 287 } elsif ($type eq 'ARRAY') { 288 my $found = 0; 289 290 VALIDATE_ARRAY: for my $t (@{$cmd->{$key}->{VALIDATE}}) { 291 $found =1, last VALIDATE_ARRAY 292 if $token eq $t; 293 } 294 return ('ERROR', "Invalid input '$token'.", $ctx) 295 unless $found; 296 } else { 297 return ('ERROR', 'Invalid value for VALIDATE target.', $ctx); 298 } 274 299 } 275 300 manage/trunk/manage
r173 r174 53 53 # Plugin path 54 54 my $PLUGINS = "/usr/local/libexec/$SELF"; 55 $PLUGINS = "./plugins";55 #$PLUGINS = "./plugins"; 56 56 our %CONF = ( 57 57 prompt => { manage/trunk/plugins/nodelist2.pm
r173 r174 5 5 '1)lalala' => sub { print "FOO\n"; }, 6 6 '2)$.*' => { 7 VALIDATE => 1, 7 8 HELP => sub { 8 9 return (
