/[cwmp]/google/bin/cli.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /google/bin/cli.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 104 by dpavlin, Sun Jun 24 17:41:55 2007 UTC revision 105 by dpavlin, Tue Jun 26 18:27:53 2007 UTC
# Line 7  use lib 'lib'; Line 7  use lib 'lib';
7    
8  use Term::Shelly;  use Term::Shelly;
9  use CWMP::Store;  use CWMP::Store;
10    use CWMP::Tree;
11  use DBM::Deep;  use DBM::Deep;
12  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
13  use Getopt::Long;  use Getopt::Long;
14    use Carp qw/confess/;
 my $sh = Term::Shelly->new();  
15    
16  my $debug = 0;  my $debug = 0;
17  my $store_path = 'state.db';  my $store_path = 'state.db';
# Line 21  GetOptions( Line 21  GetOptions(
21          'store-path=s' => \$store_path,          'store-path=s' => \$store_path,
22  );  );
23    
24    my $sh = Term::Shelly->new();
25    my $tree = CWMP::Tree->new({ debug => $debug });
26    
27  our $store = CWMP::Store->new({  our $store = CWMP::Store->new({
28          debug => $debug,          debug => $debug,
29          path => $store_path,          path => $store_path,
# Line 73  sub completer { Line 76  sub completer {
76          my @matches;          my @matches;
77    
78          # do we have list (part) of CPE?          # do we have list (part) of CPE?
79          if ( $line =~ /^(\w+)\s*$/ ) {          if ( $line =~ /^(\S*)\s*$/ ) {
80                  @matches = sort grep { /^\Q$curword\E/ } $store->known_CPE;                  @matches = sort grep { /^\Q$curword\E/ } $store->known_CPE;
81                  $sh->out( "CPE available: ", join(",", @matches ) );                  $sh->out( "CPE available: ", join(",", @matches ) );
82          } elsif ( $line =~          } elsif ( $line =~ /^(\w+)\s+(\S+)$/ ) {
83                    $sh->out("finding completes for '$2'");
84                    my ( $cpe_uid, $name ) = ( $1, $2 );
85    
86                    my $beginning = $name;
87                    my $part = '';
88                    if ( $beginning =~ s/\.([^\.]+)$// ) {
89                            $part = $1;
90                    } elsif ( $beginning =~ s/^(\S+)$// ) {
91                            $part = $1;
92                    } else {
93                            confess "can't extract suffix";
94                    }
95    
96                    $sh->out( "## $cpe_uid ## beginning: $beginning -- part: $part" );
97                    my $perl = "\$store->db->{state}->{'$cpe_uid'}->{ParameterInfo}";
98                    $perl .= '->' . $tree->name2perl( $beginning ) if ( defined( $beginning ) && $beginning ne '' );
99                    $sh->out( "## $cpe_uid ## $perl" );
100    
101                    @matches = eval "keys %{ $perl }";
102    
103            }
104    
105          return @matches;          return @matches;
106  }  }
# Line 91  sub command { Line 115  sub command {
115                  if ( main->can( $1 ) ) {                  if ( main->can( $1 ) ) {
116                          $sh->out( "# execute command $1" );                          $sh->out( "# execute command $1" );
117                          eval " \&$1( \$line ) ";                          eval " \&$1( \$line ) ";
118                  } elsif ( my $state = $store->db->get('state')->get( $1 ) ) {                  } elsif ( defined ( $store->db->{state}->{$1} ) ) {
119                          $sh->out( join(" ", keys %{ $state }) );                          $sh->out(
120                                    join(" ", keys %{ $store->db->{state}->{$1}->{ParameterInfo} })
121                            );
122                          push @history, $line;                          push @history, $line;
123                          $pos = $#history;                          $pos = $#history;
124                  } else {                  } else {

Legend:
Removed from v.104  
changed lines
  Added in v.105

  ViewVC Help
Powered by ViewVC 1.1.26