- Timestamp:
- 09/24/19 21:27:33 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm
r2241 r2284 236 236 } 237 237 ); 238 239 $self->add_func('loadcsv', 240 { 241 help => 'Load CSV file to create object', 242 code => sub { 243 my ($self, $otype, $file) = @_; 244 245 open(my $fh, '<', $file) or do { 246 warn "Cannot open $file $!\n"; 247 return; 248 }; 249 250 my @ids; 251 252 loadCSV( 253 $fh, 254 cb => sub { 255 my ($res, $linecount) = @_; 256 257 my $ochelper = $labase->ochelper($otype); 258 259 my $info = { 260 contents => $res 261 }; 262 if ($res->{name}) { 263 $info->{name}{content} = $res->{name}; 264 } 265 266 if ($ochelper->Automate($info)) { 267 push(@ids, $res->{name}); 268 } else { 269 warn "Cannot create object line $linecount (not enough information ?)\n"; 270 } 271 }, 272 ); 273 274 close($fh); 275 276 my @objs; 277 foreach (@ids) { 278 my $obj = $self->base->get_object($otype, $_) or do { 279 print $OUT "Cannot get $otype $_\n"; 280 return; 281 }; 282 push(@objs, $obj); 283 } 284 285 print $OUT "Selecting $otype " . join(', ', @ids) . "\n"; 286 LATMOS::Accounts::Cli::Object->new( 287 Parent => $self, 288 Context => $self->Context, 289 otype => $otype, 290 objs => \@objs, 291 )->cli(); 292 }, 293 completion => sub { 294 if ($_[2]) { 295 return Term::ReadLine::Gnu::filename_list(@_); 296 } else { 297 return '@', $_[0]->base->list_supported_objects; 298 } 299 }, 300 } 301 ); 302 238 303 $self->add_func('user', { alias => [qw'select user' ] }); 239 304 $self->add_func('group', { alias => [qw'select group'] });
Note: See TracChangeset
for help on using the changeset viewer.