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

use lib 'lib';

use Getopt::Long;
use App::Changelog;

sub show_help {
    print <<"END_HELP";
Usage: $0 [options]

Options:
  --output, -o       Set the output file (default: CHANGELOG.md)
  --compact          Use compact logs (default: enabled)
  --no-compact       Use detailed logs (disables compact mode)
  --filter, -f       Filter tags that start with the specified prefix
  --conventional     Format the changelog based on Conventional Commits
  --help, -h         Show this help message

Examples:
  $0 --output changelog.md
  $0 --compact
  $0 --filter v
  $0 --conventional
END_HELP
    exit;
}

my ( $output_file, $compact, $filter_tag, $conventional, $help );

$compact = 1;

GetOptions(
    'output|o=s' => \$output_file,
    'compact!'   => \$compact,
    'filter|f=s' => \$filter_tag,
    'conventional!'  => \$conventional,
    'help|h'     => \$help,
) or die "Invalid options passed. Use --help for usage information.\n";

if ($help) {
    show_help();
}

my $generator = App::Changelog->new(
    output_file => $output_file,
    compact     => $compact,
    filter_tag  => $filter_tag,
    conventional  => $conventional,
);

$generator->generate_changelog();
