Beam-Runner

 view release on metacpan or  search on metacpan

lib/Beam/Runner/Command/list.pm  view on Meta::CPAN


    my $config = $wire->config;
    my %services;
    for my $name ( keys %$config ) {
        my ( $name, $abstract ) = _list_service( $wire, $name, $config->{$name} );
        next unless $name;
        $services{ $name } = $abstract;
    }
    return 0 unless keys %services;

    my ( $bold, $reset ) = ( color( 'bold' ), color( 'reset' ) );
    print "$bold$cname$reset" . ( eval { " -- " . $wire->get( '$summary' ) } || '' ) . "\n";

    my $size = max map { length } keys %services;
    print join( "\n", map { sprintf "- $bold%-${size}s$reset -- %s", $_, $services{ $_ } } sort keys %services ), "\n";
    return 1;
}

#=sub _list_service
#
#   my $service_info = _list_service( $wire, $name, $config );
#
# If the given service is a runnable service, return the information
# about it ready to be printed to STDOUT. $wire is a Beam::Wire object,
# $name is the name of the service, $config is the service's

t/command/list.t  view on Meta::CPAN

use Test::Lib;
use Test::Fatal;
use Local::Runnable;
use FindBin ();
use Path::Tiny qw( path );
use Capture::Tiny qw( capture );
use Beam::Runner::Command::list;

local $ENV{BEAM_PATH} = undef;
my $SHARE_DIR = path( $FindBin::Bin, '..', 'share' );
my %COLOR = ( bold => color('bold'), reset => color( 'reset' ) );
my $class = 'Beam::Runner::Command::list';

subtest 'list all containers and services' => sub {
    my $expect_out = join "\n",
        "$COLOR{bold}container$COLOR{reset} -- A container for test purposes",
        "- $COLOR{bold}alias      $COLOR{reset} -- A task that succeeds",
        "- $COLOR{bold}dep_missing$COLOR{reset} -- Local::Runnable - A test runnable module",
        "- $COLOR{bold}extends    $COLOR{reset} -- A task that succeeds",
        "- $COLOR{bold}fail       $COLOR{reset} -- A task that fails",
        "- $COLOR{bold}success    $COLOR{reset} -- A task that succeeds",
        "",
        "$COLOR{bold}undocumented$COLOR{reset}", # This container has no $summary
        "- $COLOR{bold}bar$COLOR{reset} -- Local::Underdocumented",
        "- $COLOR{bold}foo$COLOR{reset} -- Local::Undocumented",
        "";

    local $ENV{BEAM_PATH} = "$SHARE_DIR";
    my ( $stdout, $stderr, $exit ) = capture {
        $class->run;
    };
    ok !$stderr, 'nothing on stderr';
    is $exit, 0, 'exit 0';
    is $stdout, $expect_out, 'containers listed on stdout';
};

subtest 'list one container' => sub {
    my $expect_out = join "\n",
        "$COLOR{bold}container$COLOR{reset} -- A container for test purposes",
        "- $COLOR{bold}alias      $COLOR{reset} -- A task that succeeds",
        "- $COLOR{bold}dep_missing$COLOR{reset} -- Local::Runnable - A test runnable module",
        "- $COLOR{bold}extends    $COLOR{reset} -- A task that succeeds",
        "- $COLOR{bold}fail       $COLOR{reset} -- A task that fails",
        "- $COLOR{bold}success    $COLOR{reset} -- A task that succeeds",
        "";

    local $ENV{BEAM_PATH} = "$SHARE_DIR";
    my ( $stdout, $stderr, $exit ) = capture {
        $class->run( 'container' );
    };
    ok !$stderr, 'nothing on stderr';
    is $exit, 0, 'exit 0';
    is $stdout, $expect_out, 'runnable services listed on stdout';



( run in 2.169 seconds using v1.01-cache-2.11-cpan-5dc5da66d9d )