Changeset 186

Show
Ignore:
Timestamp:
02/01/05 03:21:38 (4 years ago)
Author:
athomas
Message:

Removed plugin dir, made whole system into a Perl package and added an "init"
command to the manage script itself:

manage init <cli> <module> [<module> ...]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • manage/trunk/manage

    r183 r186  
    44use strict; 
    55 
     6package manage; 
     7 
    68BEGIN { $ENV{COLUMNS} = 80; $ENV{LINES} = 25; } 
    79 
     10use Config; 
    811use CLI; 
    912use CLI::Plugin; 
     
    5356our $BANNER = ''; 
    5457# Plugin path 
    55 my $PLUGINS = "/usr/local/libexec/$SELF"; 
    56 $PLUGINS = "./plugins"; 
     58my $PLUGINBASE = "$Config{prefix}/libexec"; 
     59my $PLUGINS = "$PLUGINBASE/$SELF"; 
     60#$PLUGINS = "./plugins"; 
    5761our %CONF = ( 
    5862        prompt => {  
     
    163167        ReadMode(2, *TTY); 
    164168my $secret = ReadLine(0, *TTY); 
    165         chomp($secret)
     169        chomp($secret) if $secret
    166170        ReadMode(0, *TTY); 
    167171        print("\n"); 
     
    386390        }, 
    387391}; 
     392 
     393# Add administrative functions if allowed 
     394if (-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); 
     410About to create CLI skeleton with the following attributes: 
     411 
     412  Binary symlink: 
     413    $Config{bin}/$SELF -> $Config{bin}/$cli 
     414  Modules: 
     415EOF 
     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 
     430package manage; 
     431 
     432use warnings; 
     433use 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}; 
     445EOF 
     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} 
    388464$CLI = new CLI( 
    389465        grammar => $GRAMMAR,