#!perl

use strict;
use warnings;

use SPVM();
use SPVM::Dist;
use SPVM::Builder::Util;

SPVM::Builder::Util::getopt
  'h|help'          => \my $help,
  'v|version'       => \my $show_version,
  'q|quiet'   => \my $quiet,
  'f|force' => \my $force,
  'native=s' => \my $native,
  'precompile' => \my $precompile,
  'resource' => \my $resource,
  'interface' => \my $interface,
  'only-lib-files' => \my $only_lib_files,
  'no-pm-file' => \my $no_pm_file,
  'genlib' => \my $genlib,
  'user-name=s' => \my $user_name,
  'user-email=s' => \my $user_email,
  'version_from=s' => \my $version_from,
;

if ($help) {
  print SPVM::Builder::Util::extract_usage;
}
elsif ($show_version) {
  my $version_string = "spvmdist v$SPVM::VERSION";
  print "$version_string\n";
}
else {
  my ($class_name, $output_dir) = @ARGV;
  unless (defined $class_name) {
    die SPVM::Builder::Util::extract_usage;
  }
  
  if ($genlib) {
    $only_lib_files = 1;
    $no_pm_file = 1;
  }
  
  my $gendist= SPVM::Dist->new(
    class_name => $class_name,
    quiet => $quiet,
    force => $force,
    output_dir => $output_dir,
    native => $native,
    precompile => $precompile,
    only_lib_files => $only_lib_files,
    no_pm_file => $no_pm_file,
    interface => $interface,
    resource => $resource,
    user_name => $user_name,
    user_email => $user_email,
    version_from => $version_from,
  );
  
  $gendist->generate_dist;
}

=encoding utf8

=head1 Name

spvmdist - Generating SPVM Distribution

=head1 Usage

  Usage: spvmdist [OPTIONS] CLASS_NAME [DIR]
    
    spvmdist Foo
    spvmdist Foo My-Foo
    spvmdist Foo::Bar::Baz
    spvmdist --native c Foo
    spvmdist --native c++ Foo
    spvmdist --precompile Foo
    spvmdist --resource Foo

  Options:
    -h, --help                     Show this message
    -v, --version                  Show the version
    -q, --quiet                    Quiet output
    -f, --force                    Force to generate files
    --native LANGUAGE              Output a distributioon for a native class
    --precompile                   Add precompilattion setting
    --only-lib-files               Output only the files in "lib" directory
    --no-pm-file                   Don't output Perl module(.pm) file
    --resource                     Output a distributioon for for a resource
    --genlib                       Shortcut for --only-lib-files --no-pm-file
    --user-name NAME               User name
    --user-email EMAIL             User email
    --version_from CLASS_NAME      Add version_from statement


=head1 Description

C<spvmdist> is the command to generate a SPVM distribution.

=head1 Details

  spvmdist [OPTIONS] CLASS_NAME [DIR]

I<OPTIONS> are L<options|/"Options">. These are optional.

C<E<lt>class nameE<gt>> is the name of the class contained in the distribution.

I<DIR> is the output directory. This is optional. The default is the current directory.

These are the output files when C<E<lt>class nameE<gt>> is C<MyClass>.

  SPVM-MyClass
  SPVM-MyClass/.gitattributes
  SPVM-MyClass/MANIFEST.SKIP
  SPVM-MyClass/.gitignore
  SPVM-MyClass/LICENSE
  SPVM-MyClass/Makefile.PL
  SPVM-MyClass/t
  SPVM-MyClass/t/basic.t
  SPVM-MyClass/t/lib
  SPVM-MyClass/t/lib/SPVM
  SPVM-MyClass/t/lib/SPVM/TestCase
  SPVM-MyClass/t/lib/SPVM/TestCase/MyClass.spvm
  SPVM-MyClass/README.md
  SPVM-MyClass/Changes
  SPVM-MyClass/lib
  SPVM-MyClass/lib/SPVM
  SPVM-MyClass/lib/SPVM/MyClass.spvm
  SPVM-MyClass/lib/SPVM/MyClass.pm

If a file is already exists, the file is not overwritten.

=head1 Options

=head2 --help

  --help

Outputs how to use the C<spvmdist> command to standard output.

=head2 -h

  -h

Same as L</"--help">.

=head2 --version

  --version

Outputs the version of the C<spvmdist> command to standard output. This version is the same as the version of L<SPVM>.

=head2 -v

  -v

Same as L</"--version">.

=head2 --quiet

  --quiet

Suppresses messages from the C<spvmdist> command.

=head2 -q

  -q

Same as L</"--quiet">.

=head2 --force

  --force

If this option is specified and files as the same name as the files output by the C<spvmdist> command are exists, the files are overwritten.

=head2 -f

  -f

Same as L</"--force">.

=head2 --native

  --native LANGUAGE

Outputs a distribution for a L<native class|SPVM::Document::NativeClass> specified in I<LANGUAGE>.

The default is C<c>.

The List of Option Values:

=over 2

=item * C<c>

The C language.

=item * C<c++>

C++

=back

=head2 --precompile

  --precompile

Adds precompilation setting. If the class has precompilation methods, it is good to specify this option.

=head2 --only-lib-files

  --only-lib-files

Output only files output to the C<lib> directory. These files are a SPVM class file (.spvm) and a Perl module file (.pm).

=head2 --no-pm-file

  --no-pm-file

Dose not output a Perl module file (.pm).

=head2 --resource

  --resource

Output a distribution for a L<resource|SPVM::Document::Resource>.

=head2 --genlib

  --genlib

Specifies both L</"--only-lib-files"> and L<"--no-pm-file">.

=head2 --user-name

  --user-name NAME

Specifies the user name I<NAME>.

=head2 --user-email

  --user-email EMAIL

Specifies the user email I<EMAIL>.

=head2 --version_from

  --version_from CLASS_NAME

Add version_from statement given I<CLASS_NAME>.

=head1 Copyright & License

Copyright 2023 Yuki Kimoto. All Rights Reserved.

MIT License.
