#!/usr/bin/env perl
use strict;
use warnings;

use Text::Trac ();
use Getopt::Long qw(GetOptions);
use Path::Tiny qw(path);

my ($infile, $outfile);
my $url = '';
my $class;
my $span;
my $id;
my $force;

GetOptions(
	'infile=s'  => \$infile,
	'outfile=s' => \$outfile,
	'url=s'     => \$url,
	'class'     => \$class,
	'span'      => \$span,
	'id'        => \$id,
	'force'     => \$force,
) or usage();
usage() if not $infile or not $outfile;
die "Infile '$infile' does not exist.\n" if not -e $infile;
die "Outfile '$outfile' already exists.\n" if -e $outfile and not $force;

main();
exit;


sub main {
	my $parser = Text::Trac->new(
		trac_url      => $url,
		class         => $class,
		span          => $span,
		id            => $id,
	#	disable_links => [ qw( changeset ticket ) ],
	);
	$parser->parse( path($infile)->slurp_utf8 );
	path($outfile)->spew_utf8( $parser->html );
}


sub usage {
	print <<"END_USAGE";
Usage: $0
    --infile filename     (File in Trac wiki format)
    --outfile filename    (The html file to generate)

    --url http://...      ()
    --class               Include class="" in the HTML tags.
	--span                Include <span></span>
    --id                  Include id="" in the HTML tags.
    --force               Overwrite exisiting html file.
END_USAGE
	exit;
}

