12 use Data::Dump qw/dump/;
17 my $store_path = 'state.db';
21 'store-path=s' => \$store_path,
24 my $sh = Term::Shelly->new();
25 my $tree = CWMP::Tree->new({ debug => $debug });
27 our $store = CWMP::Store->new({
33 "You can issue commenads in form using tab-complete:
35 CPE_Serial ( parametar [ [=] value ] | command )
39 $sh->{"completion_function"} = \&completer;
40 $sh->{"readline_callback"} = \&command;
42 my @history = ( 'exit' );
44 $sh->{'mappings'}->{'up-history'} = [ sub {
47 $self->{'input_line'} = $history[ $pos ];
49 $self->{'input_position'} = length( $self->{'input_line'} );
53 $sh->{'mappings'}->{'down-history'} = [ sub {
56 if ( $pos < $#history ) {
58 $line = $history[ $pos ];
60 $self->{'input_line'} = $line;
61 $self->{'input_position'} = length( $self->{'input_line'} );
72 my ($line, $bword, $pos, $curword) = @_;
74 $sh->out( "line: '$line' [ $bword - $pos ] -> '$curword'" );
78 # do we have list (part) of CPE?
79 if ( $line =~ /^(\S*)\s*$/ ) {
80 @matches = sort grep { /^\Q$curword\E/ } $store->known_CPE;
81 $sh->out( "CPE available: ", join(",", @matches ) );
82 } elsif ( $line =~ /^(\w+)\s+(\S+)$/ ) {
83 $sh->out("finding completes for '$2'");
84 my ( $cpe_uid, $name ) = ( $1, $2 );
86 my $beginning = $name;
88 if ( $beginning =~ s/\.([^\.]+)$// ) {
90 } elsif ( $beginning =~ s/^(\S+)$// ) {
93 confess "can't extract suffix";
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" );
101 @matches = eval "keys %{ $perl }";
111 return unless ( $line && $line ne '' );
114 if ( $line =~ /^(\w+)\s*$/ ) {
115 if ( main->can( $1 ) ) {
116 $sh->out( "# execute command $1" );
117 eval " \&$1( \$line ) ";
118 } elsif ( defined ( $store->db->{state}->{$1} ) ) {
120 join(" ", keys %{ $store->db->{state}->{$1}->{ParameterInfo} })
122 push @history, $line;
125 $sh->out( "$line: CPE not found" );
128 $sh->out( "$line: command not recognized" );
133 $sh->out( "history: ", dump ( @history ) );