| 1 | #!/usr/bin/env perl | ||
| 2 | package App::SD::CLI; | ||
| 3 | use Any::Moose; | ||
| 4 | extends 'Prophet::CLI'; | ||
| 5 | |||
| 6 | use App::SD; | ||
| 7 | use App::SD::CLI::Dispatcher; | ||
| 8 | |||
| 9 | has '+app_class' => ( | ||
| 10 | default => 'App::SD', | ||
| 11 | ); | ||
| 12 | |||
| 13 | sub dispatcher_class { "App::SD::CLI::Dispatcher" } | ||
| 14 | |||
| 15 | sub format_change { | ||
| 16 | my $self = shift; | ||
| 17 | my %args = ( | ||
| 18 | change => undef, | ||
| 19 | header_callback => undef, | ||
| 20 | @_ | ||
| 21 | ); | ||
| 22 | my $output = $args{header_callback} ? $args{header_callback}->( $args{change} ) : '' ; | ||
| 23 | |||
| 24 | if ( $args{change}->record_type eq 'comment' && $args{change}->change_type eq 'add_file' ) { | ||
| 25 | my $change = $args{change}->as_hash; | ||
| 26 | |||
| 27 | $output .= App::SD::CLI::Command::Ticket::Show->format_comment( | ||
| 28 | ( ( $change->{prop_changes}->{'content_type'} && $change->{prop_changes}->{'content_type'}->{new_value} ) | ||
| 29 | ? $change->{prop_changes}->{'content_type'}->{new_value} | ||
| 30 | : 'text/plain' | ||
| 31 | ), | ||
| 32 | $change->{prop_changes}->{'content'}->{new_value} | ||
| 33 | |||
| 34 | ); | ||
| 35 | } else { | ||
| 36 | if ( my @prop_changes = $args{change}->prop_changes ) { | ||
| 37 | $output .= $args{change_header}->( $args{change} ) if ( $args{change_header} ); | ||
| 38 | $output .= App::SD::CLI->format_prop_changes( \@prop_changes ); | ||
| 39 | |||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | return $output . "\n"; | ||
| 44 | |||
| 45 | } | ||
| 46 | |||
| 47 | sub format_prop_changes { | ||
| 48 | my $self = shift; | ||
| 49 | my $prop_changes = shift; | ||
| 50 | my $output; | ||
| 51 | for (@$prop_changes) { | ||
| 52 | if ( defined $_->new_value && defined $_->old_value ) { | ||
| 53 | $output .= sprintf( "%18.18s", $_->name ) . ": changed from " . $_->old_value . " to " . $_->new_value; | ||
| 54 | } elsif ( defined $_->new_value ) { | ||
| 55 | $output .= sprintf( "%18.18s", $_->name ) . ": set to " . $_->new_value; | ||
| 56 | |||
| 57 | } elsif ( defined $_->old_value ) { | ||
| 58 | $output .= sprintf( "%18.18s", $_->name ) . ": " . $_->old_value . " deleted"; | ||
| 59 | } else { | ||
| 60 | next; | ||
| 61 | } | ||
| 62 | |||
| 63 | $output .= "\n"; | ||
| 64 | } | ||
| 65 | return $output; | ||
| 66 | } | ||
| 67 | |||
| 68 | __PACKAGE__->meta->make_immutable; | ||
| 69 | no Any::Moose; | ||
| 70 | |||
| 71 | 1; | ||
| 72 |