App-Colorist

 view release on metacpan or  search on metacpan

bin/colorist  view on Meta::CPAN

=head1 SYNOPSIS

  colorist [ options ] files...

  Options:
      -c --configuration - name the configuration to use
      -R --ruleset       - name the colorist ruleset to use
      -C --colorset      - name the colorist colorset to use
      -I --include       - add a directory to the config search path
      -e --execute       - the remaining arguments are a command to run
      -E --stderr        - when running a command, colorize STDERR too
      --debug            - turn on debugging (you probably don't want to)

=head1 DESCRIPTION

Before this application will work, it must be configured. See L<App::Colorist> for information on getting started with existing configuration or writing your own.

This is a script to colorize a file or command output in place. There are three basic ways to use this command.

=over

bin/colorist  view on Meta::CPAN

=head2 -I --include

  -I $HOME/colorist-configs

Normally, only F</etc/colorist> and F<~/.colorist> are searched for colorist configuration. With this option set, it will look in other directories you name.

=head2 -e --execute

If this flag is set, the additional arguments on the command line are treated as a command name and arguments to pass to it during execution. The standard output stream of the command will be captured and colored.

=head2 -E --stderr

This flag implies C<-e>. In addition to capturing standard out, this will also capture standard error and colorize it too.

=head2 --debug

You probably don't want to bother with this. It is primarily helpful for testing, though it might be helpful in testing colorist configurations. Instead of colorizing the output, the output will have notation like "{10}" added where each color would ...

=head1 ENVIRONMENT VARIABLES

This application will read a single environment variable, C<COLORIST_CONFIG>, which is basically identical to passing an C<--include> option to the command-line. It is a colon-separated list of paths that will be searched for configuration.

lib/App/Colorist.pm  view on Meta::CPAN

has execute => (
    is          => 'ro',
    isa         => 'Bool',
    traits      => [ 'Getopt' ],
    cmd_aliases => [ qw(e) ],
    lazy_build  => 1,
);

sub _build_execute {
    my $self = shift;
    return $self->stderr ? 1 : 0;
}

has stderr => (
    is          => 'ro',
    isa         => 'Bool',
    required    => 1,
    traits      => [ 'Getopt' ],
    cmd_aliases => [ qw(E) ],
    default     => 0,
);

# I would like to have this someday...
# has follow => (

lib/App/Colorist.pm  view on Meta::CPAN

    my $self = shift;

    my @args = @{ $self->extra_argv };

    my %params;

    # The command-line contains the command to run and arguments to it
    if ($self->execute) {

        # They have asked us to capture STDERR too
        if ($self->stderr) {
            open3('<&STDIN', my $outfh, my $errfh, @args);
            $params{inputs} = [ $outfh, $errfh ];
        }

        # They have asked us to capture just STDOUT
        else {
            open my $fh, '-|', @args or die "cannot execute ", join(' ', @args), ": ", $!;
            $params{inputs} = [ $fh ];
        }
    }



( run in 1.055 second using v1.01-cache-2.11-cpan-49f99fa48dc )