| 1 | package Enbld::Command::List; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use 5.010001; | ||
| 7 | |||
| 8 | use parent qw/Enbld::Command/; | ||
| 9 | |||
| 10 | use Encode; | ||
| 11 | |||
| 12 | require Enbld::Home; | ||
| 13 | require Enbld::App::Configuration; | ||
| 14 | |||
| 15 | sub do { | ||
| 16 | my $self = shift; | ||
| 17 | |||
| 18 | my $target_name = shift @{ $self->{argv} }; | ||
| 19 | |||
| 20 | if ( $target_name ) { | ||
| 21 | |||
| 22 | $self->list_target_installed_version( $target_name ); | ||
| 23 | |||
| 24 | } else { | ||
| 25 | $self->list_all_installed; | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | sub list_all_installed { | ||
| 30 | my $self = shift; | ||
| 31 | |||
| 32 | Enbld::Home->initialize; | ||
| 33 | Enbld::App::Configuration->read_file; | ||
| 34 | |||
| 35 | my $collection = Enbld::App::Configuration->config; | ||
| 36 | |||
| 37 | if ( ! keys %{ $collection } ) { | ||
| 38 | say "Nothing is installed yet."; | ||
| 39 | } | ||
| 40 | |||
| 41 | foreach my $name ( sort keys %{ $collection } ) { | ||
| 42 | my $config = Enbld::App::Configuration->search_config( $name ); | ||
| 43 | |||
| 44 | my $line = $name . ' ' x 15; | ||
| 45 | |||
| 46 | print substr( $name . ' ' x 15 , 0, 15 ); | ||
| 47 | |||
| 48 | my $version; | ||
| 49 | if ( $config->enabled ) { | ||
| 50 | $version = $config->enabled; | ||
| 51 | } else { | ||
| 52 | $version = 'Not enabled now...'; | ||
| 53 | } | ||
| 54 | |||
| 55 | print substr( $version . ' ' x 20, 0, 20 ); | ||
| 56 | |||
| 57 | if ( $config->enabled && $config->condition->annotation ) { | ||
| 58 | print encode( 'UTF-8', $config->condition->annotation ); | ||
| 59 | } | ||
| 60 | |||
| 61 | print "\n"; | ||
| 62 | } | ||
| 63 | |||
| 64 | return $self; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub list_target_installed_version { | ||
| 68 | my $self = shift; | ||
| 69 | my $target_name = shift; | ||
| 70 | |||
| 71 | Enbld::Home->initialize; | ||
| 72 | Enbld::App::Configuration->read_file; | ||
| 73 | |||
| 74 | my $config = Enbld::App::Configuration->search_config( $target_name ); | ||
| 75 | |||
| 76 | if ( ! $config ) { | ||
| 77 | require Enbld::Error; | ||
| 78 | die Enbld::Error->new( "Target '$target_name' is not installed yet.\n" ); | ||
| 79 | } | ||
| 80 | |||
| 81 | for my $installed ( sort keys %{ $config->installed } ) { | ||
| 82 | print $installed . "\n"; | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | return $self; | ||
| 88 | } | ||
| 89 | |||
| 90 | 1; |