Changeset 2226 for trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Base.pm
- Timestamp:
- 02/27/19 09:38:36 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Base.pm
r2225 r2226 35 35 =head1 CLI FUNCTIONS 36 36 37 =head2 GLOBAL FUNCTIONS 38 37 39 =cut 38 40 … … 42 44 my $OUT = $self->Context->Out; 43 45 44 if ($self->base->is_transactionnal) { 45 $self->add_func( 46 'transaction', { 47 help => 'change transaction mode', 48 code => sub { 49 $self->Context->TransMode($_[1] eq 'on' ? 1 : 0); 50 }, 51 completion => sub { 52 $self->Context->TransMode == 0 ? 'on' : 'off'; 53 }, 54 } 55 ); 56 $self->add_func( 57 'begin', { 58 help => 'Start transaction', 59 code => sub { 60 $self->Context->TransStarted(1); 61 }, 62 } 63 ); 64 $self->add_func( 65 'commit', { 66 help => 'commit pending change', 67 code => sub { 68 $_[0]->_commit; 69 }, 70 } 71 ); 72 $self->add_func( 73 'rollback', { 74 help => 'commit pending change', 75 code => sub { 76 $_[0]->_rollback; 77 }, 78 } 79 ); 80 } 46 =head3 help 47 48 help [command] - print help about command 49 50 =cut 51 52 $self->add_func('help', { 53 completion => sub { 54 if (!$_[2]) { return sort keys %{ $_[0]->{funcs} || {}} } 55 }, 56 code => sub { 57 my $env = shift; 58 59 $env->Help(@_); 60 }, 61 }); 62 63 =head3 unexported 64 65 unexported yes|no|show 66 67 switch or show base mode regarding' unexported objects behavior 68 69 =cut 70 71 $self->add_func('unexported', { 72 completion => sub { 73 if (!$_[2]) { 74 return qw(yes no show); 75 } 76 }, 77 code => sub { 78 my ($self, $arg) = @_; 79 if (!$arg) { 80 print $OUT "Unexported objects is" . ($self->base->unexported ? 81 "enable" : "disable") . "\n"; 82 } elsif ($arg eq 'yes') { 83 $self->base->unexported(1); 84 print $OUT "Unexported are now show\n"; 85 } elsif ($arg eq 'no') { 86 $self->base->unexported(0); 87 print $OUT "Unexported are no longer show\n"; 88 } elsif ($arg eq 'show') { 89 print $OUT "Unexported objects is" . ($self->base->unexported ? 90 "enable" : "disable") . "\n"; 91 } else { 92 print $OUT "wrong argument\n"; 93 } 94 }, 95 }); 81 96 $self->add_func('quit', { help => 'quit - exit the tool', 82 97 code => sub { print "\n"; exit(0) }, }); … … 94 109 } ); 95 110 96 97 =head2 help 98 99 help [command] - print help about command 100 101 =cut 102 103 $self->add_func('help', { 104 completion => sub { 105 if (!$_[2]) { return sort keys %{ $_[0]->{funcs} || {}} } 106 }, 107 code => sub { 108 my $env = shift; 109 110 $env->Help(@_); 111 }, 112 }); 111 if ($self->base->is_transactionnal) { 112 113 =head2 TRANSACTIONS FUNCTIONS 114 115 transaction [on|off] 116 117 Enable or disable the transaction mode: ie automatic commit 118 119 =cut 120 121 $self->add_func( 122 'transaction', { 123 code => sub { 124 $self->Context->TransMode($_[1] eq 'on' ? 1 : 0); 125 }, 126 completion => sub { 127 $self->Context->TransMode == 0 ? 'on' : 'off'; 128 }, 129 } 130 ); 131 132 =head3 begin 133 134 Start a transaction, meaning changes will be saved only by C<commit> and canceled by C<rollback> 135 136 =cut 137 138 $self->add_func( 139 'begin', { 140 code => sub { 141 $self->Context->TransStarted(1); 142 }, 143 } 144 ); 145 146 =head3 commit 147 148 Save pending changes in transaction mode or following C<begin> 149 150 =cut 151 $self->add_func( 152 'commit', { 153 code => sub { 154 $_[0]->_commit; 155 }, 156 } 157 ); 158 159 =head3 rollback 160 161 Cancel pending changes following a C<begin> or in transaction mode 162 163 =cut 164 $self->add_func( 165 'rollback', { 166 code => sub { 167 $_[0]->_rollback; 168 }, 169 } 170 ); 171 } 172 173 =head2 GLOBAL and OBJECTS FUNCTION 174 175 =head3 query 176 177 query objectname [attribute] 178 query [attribute] 179 180 Show attribute 181 182 options: 183 184 =over 4 185 186 =item -o|--otype objecttype 187 188 In global context specify the object type (default: user) 189 190 =item -e|--empty 191 192 Show empty/unset attributes 193 194 =item --ro 195 196 Show readonly attributes 197 198 =item --fmt format 199 200 Instead displaying attribute list use C<format> as formating string 201 202 =back 203 204 =cut 113 205 114 206 $self->add_func( 'query' => { 115 207 proxy => '*', 116 help => 'show attribute',117 208 completion => sub { }, 118 209 code => sub { … … 374 465 375 466 podselect( 376 {-output => $fh, -sections => ["CLI FUNCTIONS/ \Q$name"]},467 {-output => $fh, -sections => ["CLI FUNCTIONS/.*/\Q$name"]}, 377 468 $self->{funcs}{$name}{podfile} 378 469 );
Note: See TracChangeset
for help on using the changeset viewer.