view release on metacpan or search on metacpan
dist.ini
lib/App/AppSpec.pm
lib/App/AppSpec/Schema/Validator.pm
lib/App/AppSpec/Spec.pm
lib/appspec.pod
share/appspec-spec.yaml
share/completion/bash/appspec.bash
share/completion/zsh/_appspec
t/00.load.t
t/02.pod-cover.t
t/11.validate-spec.t
tools/generate-spec-pm.pl
lib/App/AppSpec.pm view on Meta::CPAN
require App::Spec::Pod;
my $generator = App::Spec::Pod->new(
spec => $spec,
);
my $pod = $generator->generate;
say $pod;
}
sub cmd_validate {
my ($self, $run) = @_;
my $options = $run->options;
my $parameters = $run->parameters;
my @errors;
require App::AppSpec::Schema::Validator;
my $validator = App::AppSpec::Schema::Validator->new;
my $spec_file = $parameters->{spec_file};
if (ref $spec_file eq 'SCALAR') {
my $spec = YAML::PP::Load($$spec_file);
@errors = $validator->validate_spec($spec);
}
else {
@errors = $validator->validate_spec_file($spec_file);
}
binmode STDOUT, ":encoding(utf-8)";
if (@errors) {
print $validator->format_errors(\@errors);
say $run->colored(out => red => "Not valid!");
}
else {
say $run->colored(out => [qw/ bold green /] => "Validated â");
}
}
lib/App/AppSpec.pm view on Meta::CPAN
=head1 DESCRIPTION
This is the app class for the L<appspec> command line tool.
It contains utilities for L<App::Spec> files, like generating
completion or pod from it.
=head1 METHODS
=over 4
=item cmd_completion, cmd_new, cmd_validate, generate_pod
=back
=head1 LICENSE
This library is free software and may be distributed under the same terms
as perl itself.
=cut
lib/App/AppSpec/Schema/Validator.pm view on Meta::CPAN
use warnings;
package App::AppSpec::Schema::Validator;
our $VERSION = '0.006'; # VERSION
use App::Spec;
use App::Spec::Schema qw/ $SCHEMA /;
use YAML::PP;
use Moo;
sub validate_spec_file {
my ($self, $file) = @_;
my $yp = YAML::PP->new( boolean => 'JSON::PP', schema => [qw/ JSON /] );
my $spec = $yp->load_file($file);
return $self->validate_spec($spec);
}
sub validate_spec {
my ($self, $spec) = @_;
eval { require JSON::Validator }
or die "JSON::Validator is needed for validating a spec file";
my $json_validator = JSON::Validator->new;
$json_validator->schema($SCHEMA);
my @errors = $json_validator->validate($spec);
return @errors;
}
sub format_errors {
my ($self, $errors) = @_;
my $output = '';
for my $error (@$errors) {
$output .= "Path: " . $error->path . "\n";
$output .= " Message: " . $error->message . "\n";
}
lib/App/AppSpec/Spec.pm view on Meta::CPAN
'version' => '0.001'
},
'class' => 'App::AppSpec',
'description' => 'This script is a collection of tools for authors of L<App::Spec> command line
scripts.
# generate completion
% appspec completion --bash path/to/spec.yaml
# generate pod
% appspec pod path/to/spec.yaml
# validate your spec file
% appspec validate path/to/spec.yaml
# generate a new App::Spec app skeleton
% appspec new --class App::foo --name foo --with-subcommands
',
'markup' => 'pod',
'name' => 'appspec',
'options' => [],
'subcommands' => {
'completion' => {
'description' => 'This command takes a spec file and outputs the corresponding
shell script for tab completion.
lib/App/AppSpec/Spec.pm view on Meta::CPAN
'pod' => {
'description' => 'This command takes a spec file and outputs the generated pod
documentation.
',
'op' => 'generate_pod',
'parameters' => [
'+spec_file= +file --Path to the spec file (use \'-\' for standard input)'
],
'summary' => 'Generate pod'
},
'validate' => {
'description' => 'This command takes a spec file and validates it against the current
L<App::Spec> schema.
',
'op' => 'cmd_validate',
'options' => [
'color|C --output colorized'
],
'parameters' => [
'+spec_file= +file --Path to the spec file (use \'-\' for standard input)'
],
'summary' => 'Validate spec file'
}
},
'title' => 'Utilities for spec files for App::Spec cli apps'
lib/appspec.pod view on Meta::CPAN
=head1 DESCRIPTION
This script is a collection of tools for authors of L<App::Spec> command line
scripts.
# generate completion
% appspec completion --bash path/to/spec.yaml
# generate pod
% appspec pod path/to/spec.yaml
# validate your spec file
% appspec validate path/to/spec.yaml
# generate a new App::Spec app skeleton
% appspec new --class App::foo --name foo --with-subcommands
=head2 GLOBAL OPTIONS
--help -h Show command help (flag)
=head2 SUBCOMMANDS
lib/appspec.pod view on Meta::CPAN
Generate pod
This command takes a spec file and outputs the generated pod
documentation.
Parameters:
spec_file * Path to the spec file (use '-' for standard input)
=head3 validate
appspec validate [options] <spec_file>
Validate spec file
This command takes a spec file and validates it against the current
L<App::Spec> schema.
Options:
--color -C output colorized (flag)
Parameters:
spec_file * Path to the spec file (use '-' for standard input)
share/appspec-spec.yaml view on Meta::CPAN
class: App::AppSpec
markup: pod
description: |
This script is a collection of tools for authors of L<App::Spec> command line
scripts.
# generate completion
% appspec completion --bash path/to/spec.yaml
# generate pod
% appspec pod path/to/spec.yaml
# validate your spec file
% appspec validate path/to/spec.yaml
# generate a new App::Spec app skeleton
% appspec new --class App::foo --name foo --with-subcommands
options: []
subcommands:
completion:
summary: Generate completion for a specified spec file
description: |
This command takes a spec file and outputs the corresponding
shell script for tab completion.
share/appspec-spec.yaml view on Meta::CPAN
pod:
summary: Generate pod
description: |
This command takes a spec file and outputs the generated pod
documentation.
op: generate_pod
parameters:
- *param_spec_file
validate:
summary: Validate spec file
description: |
This command takes a spec file and validates it against the current
L<App::Spec> schema.
op: cmd_validate
parameters:
- *param_spec_file
options:
- color|C --output colorized
# vim:et:sts=2:sws=2:sw=2:foldmethod=indent
share/completion/bash/appspec.bash view on Meta::CPAN
MYWORDS=("${words[@]:1:$cword}")
FLAGS=('--help' 'Show command help' '-h' 'Show command help')
OPTIONS=()
__appspec_handle_options_flags
case $INDEX in
0)
__comp_current_options || return
__appspec_dynamic_comp 'commands' 'completion'$'\t''Generate completion for a specified spec file'$'\n''help'$'\t''Show command help'$'\n''new'$'\t''Create new app'$'\n''pod'$'\t''Generate pod'$'\n''validate'$'\t''Validate spec file'
;;
*)
# subcmds
case ${MYWORDS[0]} in
_meta)
__appspec_handle_options_flags
case $INDEX in
1)
share/completion/bash/appspec.bash view on Meta::CPAN
;;
esac
;;
help)
FLAGS+=('--all' '')
__appspec_handle_options_flags
case $INDEX in
1)
__comp_current_options || return
__appspec_dynamic_comp 'commands' 'completion'$'\n''new'$'\n''pod'$'\n''validate'
;;
*)
# subcmds
case ${MYWORDS[1]} in
_meta)
__appspec_handle_options_flags
case $INDEX in
2)
share/completion/bash/appspec.bash view on Meta::CPAN
__comp_current_options true || return # no subcmds, no params/opts
;;
new)
__appspec_handle_options_flags
__comp_current_options true || return # no subcmds, no params/opts
;;
pod)
__appspec_handle_options_flags
__comp_current_options true || return # no subcmds, no params/opts
;;
validate)
__appspec_handle_options_flags
__comp_current_options true || return # no subcmds, no params/opts
;;
esac
;;
esac
;;
new)
FLAGS+=('--overwrite' 'Overwrite existing dist directory' '-o' 'Overwrite existing dist directory' '--with-subcommands' 'Create an app with subcommands' '-s' 'Create an app with subcommands')
share/completion/bash/appspec.bash view on Meta::CPAN
__comp_current_options || return
compopt -o filenames
;;
*)
__comp_current_options || return
;;
esac
;;
validate)
FLAGS+=('--color' 'output colorized' '-C' 'output colorized')
__appspec_handle_options_flags
case ${MYWORDS[$INDEX-1]} in
esac
case $INDEX in
1)
__comp_current_options || return
compopt -o filenames
;;
share/completion/zsh/_appspec view on Meta::CPAN
# ---- Command:
_arguments -s \
'1: :->cmd1' \
'*: :->args' \
&& ret=0
case $state in
cmd1)
_alternative 'args:cmd2:((completion\:"Generate completion for a specified spec file" help\:"Show command help" new\:"Create new app" pod\:"Generate pod" validate\:"Validate spec file"))'
;;
args)
case $line[1] in
_meta)
# ---- Command: _meta
_arguments -s -C \
'1: :->cmd1' \
'2: :->cmd2' \
share/completion/zsh/_appspec view on Meta::CPAN
# ---- Command: help
_arguments -s -C \
'1: :->cmd1' \
'2: :->cmd2' \
'*: :->args' \
&& ret=0
case $state in
cmd2)
_alternative 'args:cmd3:((completion new pod validate))'
;;
args)
case $line[2] in
_meta)
# ---- Command: help _meta
_arguments -s -C \
'1: :->cmd1' \
'2: :->cmd2' \
share/completion/zsh/_appspec view on Meta::CPAN
_arguments -s -C \
'1: :->cmd1' \
'2: :->cmd2' \
'--help[Show command help]' \
'-h[Show command help]' \
'--all[]' \
&& ret=0
;;
validate)
# ---- Command: help validate
_arguments -s -C \
'1: :->cmd1' \
'2: :->cmd2' \
'--help[Show command help]' \
'-h[Show command help]' \
'--all[]' \
&& ret=0
;;
share/completion/zsh/_appspec view on Meta::CPAN
'-h[Show command help]' \
&& ret=0
case $state in
spec_file)
_files
;;
esac
;;
validate)
# ---- Command: validate
_arguments -s -C \
'1: :->cmd1' \
'2: :->spec_file' \
'--help[Show command help]' \
'-h[Show command help]' \
'--color[output colorized]' \
'-C[output colorized]' \
&& ret=0
case $state in
t/11.validate-spec.t view on Meta::CPAN
use strict;
use warnings;
use Test::More tests => 1;
use File::Share qw/ dist_file /;
use App::AppSpec;
use App::AppSpec::Schema::Validator;
my $validator = App::AppSpec::Schema::Validator->new;
my $specfile = dist_file("App-AppSpec", "appspec-spec.yaml");
for my $file ($specfile) {
my @errors = $validator->validate_spec_file($file);
is(scalar @errors, 0, "spec $file is valid");
if (@errors) {
diag $validator->format_errors(\@errors);
}
}