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'; |
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, |
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 |
} |
} |
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 { |