#!perl

use strict;
use warnings;
use Nephia::Setup;
use File::Spec;
use Getopt::Long;

my $flavor = 'Default';
my $plugin = '';
my @plugins = ();

my $config = do File::Spec->catfile($ENV{HOME}, '.nephia-setup');

$flavor = join ',', @{$config->{flavor}} if defined $config->{flavor};
@plugins = @{$config->{plugin}} if defined $config->{plugin};

GetOptions(
    "flavor=s" => \$flavor,
    "plugin=s" => \$plugin,
    "v|version"  => \&version,
);

my $appname = shift @ARGV || '';
help() unless $appname =~ /^\w+/;

my @flavors = $flavor =~ /,/ ? split(/,/, $flavor) : ( $flavor );
push @plugins, split /,/, $plugin;

my $setup = Nephia::Setup->new(
    flavor => [@flavors],
    plugin => [@plugins],
    appname => $appname,
);
$setup->create;

sub help {
    print <<EOF;
Usage:

to create new application,

  nephia-setup AppName [--flavor Flavor::Name]

show Nephia version,

  nephia-setup --version

EOF
    exit;
}

sub version {
    print 'Nephia ' . Nephia::Setup->get_version() . "\n";
    exit;
}
