Properly handle Ctrl+C; add '?' and 'man' aliases; don't import symbols

Make Ctrl+C behave like in the shell (abort current line, redisplay)
Add '?' and 'man' as aliases for help
Add qw// on module 'use's to not import any symbols

FossilOrigin-Name: fc4cb91774beb03f371ad04c5b26e45f6db49ae40af72bb2fbccc6c3c1a65e6f
This commit is contained in:
docelic@crystallabs.io 2019-04-29 19:57:56 +00:00
parent 69dbc50d3c
commit c89d193e53

View file

@ -461,9 +461,9 @@ Mahlon E. Smith <mahlon@martini.nu>
package LDAP::Shell; package LDAP::Shell;
use strict; use strict;
use warnings; use warnings;
use Term::ReadKey; use Term::ReadKey qw//;
use Term::Shell; use Term::Shell qw//;
use Digest::MD5; use Digest::MD5 qw//;
use Net::LDAP qw/ use Net::LDAP qw/
LDAP_SUCCESS LDAP_SUCCESS
LDAP_SERVER_DOWN LDAP_SERVER_DOWN
@ -478,16 +478,16 @@ use Net::LDAP qw/
LDAP_CONNECT_ERROR LDAP_CONNECT_ERROR
LDAP_CONTROL_PAGED /; LDAP_CONTROL_PAGED /;
use Net::LDAP::Util qw/ canonical_dn ldap_explode_dn /; use Net::LDAP::Util qw/ canonical_dn ldap_explode_dn /;
use Net::LDAP::LDIF; use Net::LDAP::LDIF qw//;
use Net::LDAP::Extension::SetPassword; use Net::LDAP::Extension::SetPassword qw//;
use Net::LDAP::Control::Paged; use Net::LDAP::Control::Paged qw//;
use Data::Dumper; use Data::Dumper qw//;
use File::Temp; use File::Temp qw//;
use Algorithm::Diff; use Algorithm::Diff qw//;
use Carp 'confess'; use Carp 'confess';
use POSIX qw//;
use base 'Term::Shell'; use base 'Term::Shell';
my $conf = $main::conf; my $conf = $main::conf;
# make 'die' backtrace in debug mode # make 'die' backtrace in debug mode
@ -1410,6 +1410,8 @@ my %cmd_map = (
'mv' => [ 'move', 'comp_cwd' ], 'mv' => [ 'move', 'comp_cwd' ],
'touch' => [ 'create', 'comp_create' ], 'touch' => [ 'create', 'comp_create' ],
'export' => [ 'setenv', 'comp_setenv' ], 'export' => [ 'setenv', 'comp_setenv' ],
'?' => [ 'help' ],
'man' => [ 'help' ],
); );
@ -2457,9 +2459,22 @@ $conf->{'cacheage'} ||= 300;
$conf->{'timeout'} ||= 10; $conf->{'timeout'} ||= 10;
$conf->{'attributes'} ||= ['*']; $conf->{'attributes'} ||= ['*'];
# create and enter shell loop
my $shell = LDAP::Shell->new(); # create and enter shell loop while also handling Ctrl+C correctly.
my $shell = LDAP::Shell->new;
my $sigset = POSIX::SigSet->new();
sub ctrl_c_handler {
print "\n";
$shell->term->on_new_line;
$shell->term->replace_line('', 0);
$shell->term->redisplay;
}
my $sigaction = POSIX::SigAction->new( \&ctrl_c_handler, $sigset, 0);
my $old_action = POSIX::SigAction->new;
POSIX::sigaction(&POSIX::SIGINT, $sigaction, $old_action); # save default one
$shell->cmdloop(); $shell->cmdloop();
POSIX::sigaction(&POSIX::SIGINT, $old_action); # restore default one
### load YAML config into global conf. ### load YAML config into global conf.
### ###