[asterisk-commits] tilghman: branch 1.6.0 r114099 - in /branches/1.6.0: ./ contrib/scripts/astcli

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Apr 13 21:59:51 CDT 2008


Author: tilghman
Date: Sun Apr 13 21:59:50 2008
New Revision: 114099

URL: http://svn.digium.com/view/asterisk?view=rev&rev=114099
Log:
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)

........

Modified:
    branches/1.6.0/   (props changed)
    branches/1.6.0/contrib/scripts/astcli

Propchange: branches/1.6.0/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.0/contrib/scripts/astcli
URL: http://svn.digium.com/view/asterisk/branches/1.6.0/contrib/scripts/astcli?view=diff&rev=114099&r1=114098&r2=114099
==============================================================================
--- branches/1.6.0/contrib/scripts/astcli (original)
+++ branches/1.6.0/contrib/scripts/astcli Sun Apr 13 21:59:50 2008
@@ -12,6 +12,7 @@
 #
 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 @@
 	$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 @@
 		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 @@
 	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;
+}
+




More information about the asterisk-commits mailing list