view release on metacpan or search on metacpan
lib/App/NDTools/NDDiff.pm view on Meta::CPAN
our $VERSION = '0.61';
my $JSON = JSON->new->canonical->allow_nonref;
my %COLOR;
sub arg_opts {
my $self = shift;
return (
$self->SUPER::arg_opts(),
'A!' => \$self->{OPTS}->{diff}->{A},
'N!' => \$self->{OPTS}->{diff}->{N},
'O!' => \$self->{OPTS}->{diff}->{O},
'R!' => \$self->{OPTS}->{diff}->{R},
'U!' => \$self->{OPTS}->{diff}->{U},
'brief' => sub { $self->{OPTS}->{ofmt} = $_[0] },
'colors!' => \$self->{OPTS}->{colors},
'ctx-text=i' => \$self->{OPTS}->{'ctx-text'},
'grep=s@' => \$self->{OPTS}->{grep},
'json' => sub { $self->{OPTS}->{ofmt} = $_[0] },
lib/App/NDTools/NDDiff.pm view on Meta::CPAN
} elsif (@_ < 2) {
die_fatal "At least two arguments expected for diff", 1;
}
return $self;
}
sub configure {
my $self = shift;
$self->SUPER::configure();
$self->{OPTS}->{colors} = $self->{TTY}
unless (defined $self->{OPTS}->{colors});
# resolve colors
while (my ($k, $v) = each %{$self->{OPTS}->{term}->{line}}) {
if ($self->{OPTS}->{colors}) {
$COLOR{$k} = color($v);
$COLOR{"B$k"} = color("bold $v");
} else {
lib/App/NDTools/NDDiff.pm view on Meta::CPAN
map { $self->{OPTS}->{diff}->{$_} = 1 } keys %{$self->{OPTS}->{diff}},
if ($self->{OPTS}->{ofmt} eq 'jsonmergepatch');
return $self;
}
sub defaults {
my $self = shift;
my $out = {
%{$self->SUPER::defaults()},
'ctx-text' => 3,
'diff' => {
'A' => 1,
'N' => 1,
'O' => 1,
'R' => 1,
'U' => 0,
},
'ofmt' => 'term',
'term' => {
lib/App/NDTools/NDPatch.pm view on Meta::CPAN
use App::NDTools::Slurp qw(s_dump);
use Log::Log4Cli;
use Struct::Diff 0.96 qw();
our $VERSION = '0.09';
sub arg_opts {
my $self = shift;
return (
$self->SUPER::arg_opts(),
);
}
sub check_args {
my $self = shift;
die_fatal "One or two arguments expected", 1
if (@{$self->{ARGV}} < 1 or @{$self->{ARGV}} > 2);
return $self;
}
sub defaults {
my $self = shift;
return {
%{$self->SUPER::defaults()},
};
}
sub dump {
my ($self, $uri, $struct) = @_;
log_debug { "Restoring structure to '$uri'" };
s_dump($uri, $self->{OPTS}->{ofmt},
{pretty => $self->{OPTS}->{pretty}}, $struct);
}
lib/App/NDTools/NDProc.pm view on Meta::CPAN
use Struct::Path::PerlStyle 0.90 qw(str2path);
our $VERSION = '0.32';
sub arg_opts {
my $self = shift;
Getopt::Long::Configure('pass_through');
my %arg_opts = (
$self->SUPER::arg_opts(),
'builtin-format=s' => \$self->{OPTS}->{'builtin-format'},
'builtin-rules=s' => \$self->{OPTS}->{'builtin-rules'},
'disable-module=s@' => \$self->{OPTS}->{'disable-module'},
'dump-blame=s' => \$self->{OPTS}->{'dump-blame'},
'dump-rules=s' => \$self->{OPTS}->{'dump-rules'},
'embed-blame=s' => \$self->{OPTS}->{'embed-blame'},
'embed-rules=s' => \$self->{OPTS}->{'embed-rules'},
'list-modules|l' => \$self->{OPTS}->{'list-modules'},
'module|m=s' => \$self->{OPTS}->{module},
'rules=s@' => \$self->{OPTS}->{rules},
lib/App/NDTools/NDProc/Module/Insert.pm view on Meta::CPAN
use App::NDTools::Slurp qw(s_decode);
our $VERSION = '0.20';
sub MODINFO { "Insert value into structure" }
sub arg_opts {
my $self = shift;
return (
$self->SUPER::arg_opts(),
'boolean=s' => sub {
if ($_[1] eq '1' or $_[1] =~ /^(T|t)rue$/) {
$self->{OPTS}->{value} = JSON::true;
} elsif ($_[1] eq '0' or $_[1] =~ /^(F|f)alse$/) {
$self->{OPTS}->{value} = JSON::false;
} else {
$self->{ARG_ERROR} = "Unsuitable value for --boolean";
die "!FINISH";
}
},
lib/App/NDTools/NDProc/Module/JsonMergePatch.pm view on Meta::CPAN
use Struct::Path 0.80 qw(path);
our $VERSION = '0.02';
sub MODINFO { "Apply JSON Merge Patch (rfc7396) patches" }
sub arg_opts {
my $self = shift;
return (
$self->SUPER::arg_opts(),
'source=s' => \$self->{OPTS}->{source},
'strict!' => \$self->{OPTS}->{strict},
)
}
sub check_rule {
my ($self, $rule) = @_;
die_fatal "Source file should be specified", 1
unless ($rule->{source});
lib/App/NDTools/NDProc/Module/JsonPatch.pm view on Meta::CPAN
use Struct::Path 0.80 qw(path);
our $VERSION = '0.02';
sub MODINFO { "Apply JSON Patch (rfc6902) patches" }
sub arg_opts {
my $self = shift;
return (
$self->SUPER::arg_opts(),
'source=s' => \$self->{OPTS}->{source},
'strict!' => \$self->{OPTS}->{strict},
)
}
sub check_rule {
my ($self, $rule) = @_;
die_fatal "Source file should be specified", 1
unless ($rule->{source});
lib/App/NDTools/NDProc/Module/Merge.pm view on Meta::CPAN
use App::NDTools::Slurp qw(s_decode s_encode);
our $VERSION = '0.20';
sub MODINFO { "Merge structures according provided rules" }
sub arg_opts {
my $self = shift;
my %opts = $self->SUPER::arg_opts();
delete $opts{'path=s@'};
return (
%opts,
'ignore=s@' => \$self->{OPTS}->{ignore},
'merge|path=s' => sub {
if ($self->{rules} and @{$self->{rules}}) {
push @{$self->{rules}->[-1]->{path}}, { merge => $_[1] };
} else {
push @{$self->{OPTS}->{path}}, { merge => $_[1] };
lib/App/NDTools/NDProc/Module/Merge.pm view on Meta::CPAN
$rule->{structure} = s_decode($rule->{structure}, 'JSON')
if (exists $rule->{structure});
}
}
sub defaults {
my $self = shift;
return {
%{$self->SUPER::defaults()},
'strict' => 1,
'style' => 'R_OVERRIDE',
};
}
sub get_opts {
return @{$_[0]->{rules}};
}
sub map_paths {
lib/App/NDTools/NDProc/Module/Merge.pm view on Meta::CPAN
sub process {
my ($self, $data, $opts, $source) = @_;
if (exists $opts->{ignore}) {
for my $path (@{$opts->{ignore}}) {
log_debug { "Removing (ignore) from src '$path'" };
path($source, str2path($path), delete => 1);
}
}
$self->SUPER::process($data, $opts, $source);
}
sub process_path {
my ($self, $data, $path, undef, $opts, $source) = @_;
# merge whole source if path omitted
$path->{merge} = '' unless (defined $path->{merge});
if (exists $opts->{structure}) {
$opts->{source} = s_encode($opts->{structure}, 'JSON', {pretty => 0});
lib/App/NDTools/NDProc/Module/Patch.pm view on Meta::CPAN
use Struct::Path 0.80 qw(path);
our $VERSION = '0.03';
sub MODINFO { "Apply nested diff to the structure" }
sub arg_opts {
my $self = shift;
return (
$self->SUPER::arg_opts(),
'source=s' => \$self->{OPTS}->{source},
'strict!' => \$self->{OPTS}->{strict},
)
}
sub check_rule {
my ($self, $rule) = @_;
die_fatal "Source file should be specified", 1
unless ($rule->{source});
lib/App/NDTools/NDProc/Module/Pipe.pm view on Meta::CPAN
use Struct::Path 0.80 qw(path);
our $VERSION = '0.08';
sub MODINFO { "Modify structure using external process" }
sub arg_opts {
my $self = shift;
return (
$self->SUPER::arg_opts(),
'command|cmd=s' => \$self->{OPTS}->{command},
'strict' => \$self->{OPTS}->{strict},
)
}
sub check_rule {
my ($self, $rule) = @_;
my $out = $self;
push @{$rule->{path}}, '' unless (@{$rule->{path}});
lib/App/NDTools/NDProc/Module/Remove.pm view on Meta::CPAN
use Struct::Path::PerlStyle 0.80 qw(path2str);
our $VERSION = '0.13';
sub MODINFO { "Remove specified parts from structure" }
sub arg_opts {
my $self = shift;
return (
$self->SUPER::arg_opts(),
'strict' => \$self->{OPTS}->{strict},
)
}
sub check_rule {
my ($self, $rule) = @_;
die_fatal "At least one path should be specified", 1
unless ($rule->{path} and @{$rule->{path}});
lib/App/NDTools/NDQuery.pm view on Meta::CPAN
use Struct::Path 0.80 qw(list_paths path path_delta);
use Struct::Path::PerlStyle 0.80 qw(str2path path2str);
use Term::ANSIColor qw(color);
our $VERSION = '0.36';
sub arg_opts {
my $self = shift;
return (
$self->SUPER::arg_opts(),
'colors!' => \$self->{OPTS}->{colors},
'delete|ignore=s@' => \$self->{OPTS}->{delete},
'depth|d=i' => \$self->{OPTS}->{depth},
'grep=s@' => \$self->{OPTS}->{grep},
'keys' => \$self->{OPTS}->{keys},
'list|l' => \$self->{OPTS}->{list},
'md5' => \$self->{OPTS}->{md5},
'path|p=s' => \$self->{OPTS}->{path},
'raw-output' => sub { $self->{OPTS}->{ofmt} = 'RAW' },
'replace' => \$self->{OPTS}->{replace},
lib/App/NDTools/NDQuery.pm view on Meta::CPAN
die_fatal "--replace opt can't be used with --md5", 1
if ($self->{OPTS}->{md5});
}
return $self;
}
sub configure {
my $self = shift;
$self->SUPER::configure();
$self->{OPTS}->{colors} = $self->{TTY}
unless (defined $self->{OPTS}->{colors});
for (
@{$self->{OPTS}->{grep}},
@{$self->{OPTS}->{delete}}
) {
my $tmp = eval { str2path($_) };
die_fatal "Failed to parse '$_'", 4 if ($@);
$_ = $tmp;
}
return $self;
}
sub defaults {
my $self = shift;
return {
%{$self->SUPER::defaults()},
'color-common' => 'bold black',
'strict' => 1, # exit with 8 if unexisted path specified
'ofmt' => 'JSON',
};
}
sub dump {
my ($self, $uri, $data) = @_;
$uri = \*STDOUT unless ($self->{OPTS}->{replace});