package WGDev::Command::Group; # ABSTRACT: Utilities for manipulating WebGUI Groups use strict; use warnings; use 5.008008; use parent qw(WGDev::Command::Base); use WGDev::X (); sub config_options { return qw( list|l format|f=s long hidden ); } sub process { my $self = shift; my $wgd = $self->wgd; my $session = $wgd->session(); if ( $self->option('list') ) { my $format = $self->option('format'); if ( $self->option('long') ) { $format = 'Name: %groupName% %%n Id: %groupId% %%n Description: %description% %%n'; } elsif ( !$format ) { $format = '%groupName%'; } my $show_in_forms = $self->option('hidden'); my $group_ids = $session->db->buildArrayRef( 'select groupId from groups order by groupName'); for my $group_id ( @{$group_ids} ) { my $group = WebGUI::Group->new( $session, $group_id ); if ( !$group ) { warn "Unable to instantiate group via groupId: $group_id"; next; } next if !$show_in_forms && !$group->showInForms; my $output = $self->format_output( $format, $group ); print $output . "\n"; } } } sub format_output { my ( $self, $format, $group ) = @_; $format =~ s/%%n/\n/msxg; { no warnings 'uninitialized'; $format =~ s{% (?: (\w+) (?: :(-?\d+) )? )? %}{ my $replace; if ($1) { $replace = $group->get($1); if ($2) { $replace = sprintf('%*2$s', $replace, $2); } } else { $replace = '%'; } $replace; }msxeg; } return $format; } 1; =head1 SYNOPSIS wgd group [--list [--long] [--hidden]] =head1 DESCRIPTION Utilities for manipulating WebGUI Groups =head1 OPTIONS =over 8 =item C<-l> C<--list> List groups. This is currently the only supported action. =item C<--long> Use long list format, which includes group name, ID, and description. =item C<-f> C<--format=> Use arbitrary formatting. Format looks like C<%description:30%>, where 'C' is the field to display, and 30 is the length to left pad/cut to. Negative lengths can be specified for right padding. Percent signs can be included by using C<%%>. Newlines can be included by using C<%%n> =item C<--hidden> Include groups that are normally hidden from WebGUI forms. =back =method C Returns the formatted information about a group. C<$format> is the format to output as specified in the L. =cut