12 use Data::Dump qw/dump/;
17 my $store_path = './';
18 my $store_plugin = 'YAML';
22 'store-path=s' => \$store_path,
23 'store-plugin=s' => \$store_plugin,
26 my $sh = Term::Shelly->new();
27 my $tree = CWMP::Tree->new({ debug => $debug });
29 our $store = CWMP::Store->new({
30 module => $store_plugin,
36 "You can issue commenads in form using tab-complete:
38 CPE_Serial ( parametar [ [=] value ] | command )
42 $sh->{"completion_function"} = \&completer;
43 $sh->{"readline_callback"} = \&command;
45 my @history = ( 'exit' );
47 $sh->{'mappings'}->{'up-history'} = [ sub {
50 $self->{'input_line'} = $history[ $pos ];
52 $self->{'input_position'} = length( $self->{'input_line'} );
56 $sh->{'mappings'}->{'down-history'} = [ sub {
59 if ( $pos < $#history ) {
61 $line = $history[ $pos ];
63 $self->{'input_line'} = $line;
64 $self->{'input_position'} = length( $self->{'input_line'} );
75 my ($line, $bword, $pos, $curword) = @_;
77 $sh->out( "line: '$line' [ $bword - $pos ] -> '$curword'" );
81 # do we have list (part) of CPE?
82 if ( $line =~ /^(\S*)\s*$/ ) {
83 @matches = sort grep { /^\Q$curword\E/ } $store->all_uids;
84 $sh->out( "CPE available: ", join(",", @matches ) );
85 } elsif ( $line =~ /^(\w+)\s+(\S+)$/ ) {
86 $sh->out("finding completes for '$2'");
87 my ( $cpe_uid, $name ) = ( $1, $2 );
89 my $beginning = $name;
91 if ( $beginning =~ s/\.([^\.]+)$// ) {
93 } elsif ( $beginning =~ s/^(\S+)$// ) {
96 confess "can't extract suffix";
99 $sh->out( "## $cpe_uid ## beginning: $beginning -- part: $part" );
100 my $perl = "\$store->db->{state}->{'$cpe_uid'}->{ParameterInfo}";
101 $perl .= '->' . $tree->name2perl( $beginning ) if ( defined( $beginning ) && $beginning ne '' );
102 $sh->out( "## $cpe_uid ## $perl" );
104 @matches = eval "keys %{ $perl }";
114 return unless ( $line && $line ne '' );
117 if ( $line =~ /^(\w+)\s*$/ ) {
118 if ( main->can( $1 ) ) {
119 $sh->out( "# execute command $1" );
120 eval " \&$1( \$line ) ";
121 } elsif ( defined ( $store->db->{state}->{$1} ) ) {
123 join(" ", keys %{ $store->db->{state}->{$1}->{ParameterInfo} })
125 push @history, $line;
128 $sh->out( "$line: CPE not found" );
131 $sh->out( "$line: command not recognized" );
136 $sh->out( "history: ", dump ( @history ) );