#!/usr/bin/env perl

use strict;
use warnings;

use Cwd 'realpath';
use File::Basename 'dirname';
use Getopt::Long;
use open ":std", ":encoding(UTF-8)";
use Template;

my $params = {};

GetOptions($params,
    'input=s',
    'envtype=s',
    'envname=s',
    'hostip=s',
);

$params->{envtype} ||= '';
$params->{envname} = '' if $params->{envname} eq 'undef';
$params->{hostip} ||= '';

my $home = realpath(dirname(__FILE__) . '/..');

my $tt = Template->new({
    INCLUDE_PATH => "$home/conf/nginx",
    CACHE_SIZE   => 0,
    UNICODE      => 1,
    ENCODING     => 'utf-8',
    PRE_CHOMP    => '-',
});

$tt->process($params->{input}, $params, \*STDOUT)
  or die $tt->error;
