Back to documentation
#!/usr/bin/env perl
package ymask;
our $VERSION = '0.036';
# ABSTRACT: Mask a data structure to display only the desired fields
use ETL::Yertl;
use Pod::Usage::Return qw( pod2usage );
use Getopt::Long qw( GetOptionsFromArray );
use ETL::Yertl::Command::ymask;
$|++; # no buffering
sub main {
my ( $class, @argv ) = @_;
my %opt;
GetOptionsFromArray( \@argv, \%opt,
'help|h',
'version',
);
return pod2usage(0) if $opt{help};
if ( $opt{version} ) {
print "ymask version $ymask::VERSION (Perl $^V)\n";
return 0;
}
eval {
ETL::Yertl::Command::ymask->main( @argv, \%opt );
};
if ( $@ ) {
return pod2usage( "ERROR: $@" );
}
return 0;
}
exit __PACKAGE__->main( @ARGV ) unless caller(0);
__END__
=head1 SYNOPSIS
ymask <mask> [<file>...]
ymask -h|--help|--version
=head1 DESCRIPTION
This program takes a stream of YAML documents (on STDIN or file arguments),
and prints only the fields specified by the C<mask>.
=head1 ARGUMENTS
=head2 mask
See L<MASK SYNTAX|/MASK SYNTAX> for more information
=head2 <file>
A YAML file to read. The special file "-" refers to STDIN. If no files are
specified, read STDIN.
=head1 OPTIONS
=head2 -h | --help
Show this help document.
=head2 --version
Print the current ymask and Perl versions.
=head1 MASK SYNTAX
=head2 PROPERTIES
$ ymask 'name,rank,serial'
Select multiple properties in a document using C<,>. If a property does not exist,
nothing will be added (and no error or warning will be output).
=head2 DESCENDANTS
$ ymask 'squad/name'
Select an inner document's properties using C</>. Arrays are automatically looped over.
=head2 SUB-SELECTION
$ ymask 'squad(name,location)'
Select multiple parts of an inner document by using parentheses.
=head2 WILDCARDS
$ ymask 'squad/*/city'
Select every property in a document, which is useful for picking parts out of
every inner document.
=head1 EXAMPLES
All these examples use the following documents:
---
name: Hazel Murphy
role: Captain
nickname: Hank
history:
- location: Sealab
from: 2014-01-01
- location: USS Hunley
from: 2012-06-01
to: 2013-11-28
---
name: Quinn Quinlan
role: Science Officer
nickname: Doctor
history:
- location: Sealab
from: 2014-04-01
- location: MIT
from: 2008-08-01
to: 2012-06-05
---
name: Debbie Dupree
role: Oceanographer
history:
- location: Sealab
from: 2014-02-10
- location: Sea Parks
from: 2004-09-01
to: 2014-01-20
=head2 SELECT MULTIPLE PROPERTIES
$ ymask 'name,role,nickname'
---
name: Hazel Murphy
nickname: Hank
role: Captain
---
name: Quinn Quinlan
nickname: Doctor
role: Science Officer
---
name: Debbie Dupree
role: Oceanographer
=head2 SELECT PROPERTIES IN ARRAYS
$ ymask 'name,history/location'
---
history:
- location: Sealab
- location: USS Hunley
name: Hazel Murphy
---
history:
- location: Sealab
- location: MIT
name: Quinn Quinlan
---
history:
- location: Sealab
- location: Sea Parks
name: Debbie Dupree
=head1 ENVIRONMENT VARIABLES
=over 4
=item YERTL_FORMAT
Specify the default format Yertl uses between commands. Defaults to C<yaml>. Can be
set to C<json> for interoperability with other programs.
=back
=head1 SEE ALSO
=over 4
=item *
L<Data::Partial::Google> - The implementation of this command
=back