aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-04-14 02:59:50 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-04-14 02:59:50 +0000
commitd623fbe4004e57ba7276b7f90b87ecd1d7d87555 (patch)
treece6b11f6759d56a57fa209136ab1a7fe5d2cb0a6 /contrib
parenta9af38b9770acc53cbbdee0f2d549edd141569fc (diff)
Merged revisions 114098 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ........ r114098 | tilghman | 2008-04-13 21:55:41 -0500 (Sun, 13 Apr 2008) | 3 lines Add tab command-line completion (Closes issue #12428) ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@114099 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/scripts/astcli41
1 files changed, 31 insertions, 10 deletions
diff --git a/contrib/scripts/astcli b/contrib/scripts/astcli
index cf0ebdf15..d6feef021 100755
--- a/contrib/scripts/astcli
+++ b/contrib/scripts/astcli
@@ -12,6 +12,7 @@ use Getopt::Long;
#
my ($user, $pw, $host, $port, $interactive, $save) = (undef, undef, 'localhost', 5038, 0, 0);
my $EOL = "\r\n"; # Standard End of Line
+my @commands;
process_credentials('/etc/astcli.conf');
process_credentials("$ENV{HOME}/.astcli") if defined $ENV{HOME};
GetOptions("username=s" => \$user, "secret=s" => \$pw, "host=s" => \$host, "port=s" => \$port, "readline" => \$interactive, "write" => \$save);
@@ -51,12 +52,16 @@ sub send_command($) {
$tc->send($EOL);
my $response = '';
while (<$tc>) {
- last if $_ =~ /--END COMMAND--/;
+ if ($_ =~ /--END COMMAND--/) {
+ $_ =~ s/--END COMMAND--\s*//;
+ $response .= $_;
+ last;
+ }
$response .= $_;
}
$response =~ s/Privilege: Command$EOL//;
$response =~ s/Response: Follows$EOL//;
- print $response;
+ return $response;
}
sub login {
@@ -93,27 +98,23 @@ if ($action eq '-' || !defined $action || $action eq '') {
my $term = new Term::ReadLine 'Command Line Interface';
my $prompt = "$host*CLI> ";
my $attribs = $term->Attribs;
- $attribs->{completion_function} = sub {
- my ($text, $line, $start) = @_;
- # Stub function for tab auto completion for those feeling adventurous
- return;
- };
+ $attribs->{completion_function} = \&tab_completion;
while (defined($_ = $term->readline($prompt))) {
(logoff() and exit) if $_ =~ /exit|quit/; # Give them a way to exit the "terminal"
- send_command($_);
+ print send_command($_);
}
} else {
while (<>) {
chomp;
(logoff() and exit) if $_ =~ /exit|quit/; # If someone accidentally ends up here, let them exit
- send_command($_);
+ print send_command($_);
}
}
exit 0;
}
# Otherwise just send the command:
-send_command($action);
+print send_command($action);
# parses a configuration file into the global $user and $pw.
sub process_credentials {
@@ -144,3 +145,23 @@ sub usage {
exit;
}
+sub tab_completion {
+ my ($word, $buffer, $offset) = @_;
+ my %items;
+ my $lastword = '';
+ if ($word eq '') {
+ $buffer =~ m/(\S+)\s?$/;
+ $lastword = $1;
+ print STDERR "\n\nlastword=\"$lastword\"\n";
+ }
+
+ my $res = send_command("_command matchesarray \"$buffer\" \"$word\"\n");
+ foreach my $item (split /\s+/, $res) {
+ $items{$item}++ unless ($item eq '_EOF_' or $item eq '' or $item eq $lastword);
+ }
+
+ #print STDERR "\nword=\"$word\" buffer=\"$buffer\" offset=\"$offset\" res=\"$res\"\n";
+
+ return sort keys %items;
+}
+