| | 392 | |
|---|
| | 393 | # Add administrative functions if allowed |
|---|
| | 394 | if (-w $PLUGINBASE and $SELF eq 'manage') { |
|---|
| | 395 | $GRAMMAR = { |
|---|
| | 396 | %$GRAMMAR, |
|---|
| | 397 | init => { |
|---|
| | 398 | HELP => "Initialise basic skeleton for a new CLI.", |
|---|
| | 399 | '$\w+' => { |
|---|
| | 400 | HELP => [ "<name>", "Name of CLI." ], |
|---|
| | 401 | '$*.+' => { |
|---|
| | 402 | HELP => [ "<module>", "Add a skeleton module to new CLI." ], |
|---|
| | 403 | ACTION => { |
|---|
| | 404 | HELP => "Initialise skeleton.", |
|---|
| | 405 | ACTION => sub { |
|---|
| | 406 | my ($ctx, $cli) = (shift, shift); |
|---|
| | 407 | my @modules = @_; |
|---|
| | 408 | |
|---|
| | 409 | print(<<EOF); |
|---|
| | 410 | About to create CLI skeleton with the following attributes: |
|---|
| | 411 | |
|---|
| | 412 | Binary symlink: |
|---|
| | 413 | $Config{bin}/$SELF -> $Config{bin}/$cli |
|---|
| | 414 | Modules: |
|---|
| | 415 | EOF |
|---|
| | 416 | for my $module (@modules) { |
|---|
| | 417 | print(" $Config{prefix}/libexec/$cli/$module.pm\n"); |
|---|
| | 418 | } |
|---|
| | 419 | print("\n"); |
|---|
| | 420 | my $response = read_key("Continue (y/n)? ", "yn"); |
|---|
| | 421 | if ($response eq 'y') { |
|---|
| | 422 | info("Creating skeleton directories."); |
|---|
| | 423 | mkdir("$Config{prefix}/libexec"); |
|---|
| | 424 | mkdir("$Config{prefix}/libexec/$cli"); |
|---|
| | 425 | for my $module (@modules) { |
|---|
| | 426 | if (open(F, ">$Config{prefix}/libexec/$cli/$module.pm")) { |
|---|
| | 427 | info("Creating module $cli\::$module"); |
|---|
| | 428 | print(F <<EOF); |
|---|
| | 429 | # Put us in the manage namespace |
|---|
| | 430 | package manage; |
|---|
| | 431 | |
|---|
| | 432 | use warnings; |
|---|
| | 433 | use strict; |
|---|
| | 434 | |
|---|
| | 435 | # Some useful functions from manage itself |
|---|
| | 436 | #sub format_columns(\$\$); |
|---|
| | 437 | #sub read_key(\$\$); |
|---|
| | 438 | #sub read_line(\$); |
|---|
| | 439 | #sub get_password(\$); |
|---|
| | 440 | |
|---|
| | 441 | |
|---|
| | 442 | { |
|---|
| | 443 | # Place commands for CLI module $module here |
|---|
| | 444 | }; |
|---|
| | 445 | EOF |
|---|
| | 446 | close(F); |
|---|
| | 447 | } else { |
|---|
| | 448 | warning("Failed to create skeleton for $cli::$module."); |
|---|
| | 449 | } |
|---|
| | 450 | } |
|---|
| | 451 | info("Creating symlink $Config{bin}/$cli"); |
|---|
| | 452 | symlink(${SELF}, "$Config{bin}/$cli"); |
|---|
| | 453 | info("Finished creating skeleton CLI."); |
|---|
| | 454 | } elsif ($response eq 'n') { |
|---|
| | 455 | warning("Initialisation aborted."); |
|---|
| | 456 | } |
|---|
| | 457 | }, |
|---|
| | 458 | }, |
|---|
| | 459 | }, |
|---|
| | 460 | }, |
|---|
| | 461 | }, |
|---|
| | 462 | }; |
|---|
| | 463 | } |
|---|