Changeset 2203 for trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm
- Timestamp:
- 02/19/19 19:43:08 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm
r2175 r2203 32 32 my $OUT = $term->OUT || \*STDOUT; 33 33 34 my $trans_mode = 0; 34 our $trans_mode = 0; 35 my $trans_start = 0; 35 36 36 37 =head1 FUNCTIONS … … 46 47 sub globalenv { 47 48 my ($labase) = @_; 48 my $env = LATMOS::Accounts::Cli->new({ prompt => sub { $_[0]->base->label . " cli >" }, },49 my $env = LATMOS::Accounts::Cli->new({ prompt => sub { $_[0]->base->label . " cli" }, }, 49 50 $labase); 50 51 $env->add_func('unexported', { … … 251 252 { 252 253 prompt => sub { 253 sprintf("%s %s/%s >",254 sprintf("%s %s/%s", 254 255 $_[0]->base->label, 255 256 $_[0]->{_otype}, … … 722 723 ); 723 724 $env->add_func( 725 'begin', { 726 help => 'Start transaction', 727 code => sub { 728 $trans_start = 1; 729 }, 730 } 731 ); 732 $env->add_func( 724 733 'commit', { 725 734 help => 'commit pending change', … … 871 880 sub prompt { 872 881 my ($self) = @_; 873 if (!$self->{prompt}) { 874 return "LA cli > "; 875 } else { 876 $self->{prompt}->($self); 877 } 882 my $pr = $self->{prompt} 883 ? $self->{prompt}->($self) 884 : "LA cli"; 885 return sprintf( 886 "%s%s%s ", 887 $pr, 888 $trans_start ? '-' : '=', 889 $trans_mode ? '#' : '>', 890 ); 878 891 } 879 892 … … 896 909 897 910 =cut 898 899 # TODO: hide this900 911 901 912 sub getoption { … … 906 917 907 918 return @ARGV; 908 }909 910 # TODO: useless ?911 912 sub _parse_arg {913 my ($self, $name, @args) = @_;914 return @args;915 919 } 916 920 … … 929 933 $self->complete($lastw, @{$self->{funcs}{$name}{alias}}, @args); 930 934 } elsif ($self->{funcs}{$name}{completion}) { 931 my @pargs = $self->_parse_arg($name, @args); 932 return map { my $t = $_; $t =~ s/\s/\\ /g; $t } grep { $_ && /^\Q$lastw\E/ } $self->{funcs}{$name}{completion}->($self, $lastw, @pargs); 935 return map { my $t = $_; $t =~ s/\s/\\ /g; $t } grep { $_ && /^\Q$lastw\E/ } $self->{funcs}{$name}{completion}->($self, $lastw, @args); 933 936 } else { 934 937 return (); … … 950 953 $self->run(@{$self->{funcs}{$name}{alias}}, @args); 951 954 } elsif ($self->{funcs}{$name}{code}) { 952 my @pargs = $self->_parse_arg($name, @args);953 955 $self->{funcs}{$name}{code}->($self, @args); 954 956 } else { … … 965 967 sub commit { 966 968 my ($self) = @_; 967 if ($trans_mode) { 969 if ($trans_mode || $trans_start) { 970 $trans_start = 1; 968 971 } else { 969 972 $self->_commit; … … 974 977 my ($self) = @_; 975 978 $self->base->commit; 979 $trans_start = 0; 976 980 } 977 981 … … 987 991 print $OUT "All pending changes get rollback\n"; 988 992 } 989 $self->_rollback; 993 if (!$trans_start) { 994 $self->_rollback; 995 } 990 996 } 991 997 … … 993 999 my ($self) = @_; 994 1000 $self->base->rollback; 1001 $trans_start = 0; 995 1002 } 996 1003
Note: See TracChangeset
for help on using the changeset viewer.