#!/usr/bin/perl

use strict;
use FindBin qw($Bin);
use lib "$Bin/../lib";

use Getopt::Long;
use App::Followme;
use App::Followme::Initialize qw(initialize);

my ($initialize, $help);
GetOptions('init|i' => \$initialize, 'help|h' => \$help);

my $filename = shift @ARGV;
if ($help) {
    show_help();
    
} elsif ($initialize) {
    initialize($filename);

} else {
    my $config = configuration_file();
    my $app = App::Followme->new({configuration_file => $config});
    $app->run($filename);
}

#----------------------------------------------------------------------
# Construct configuration file name

sub configuration_file {
    my @path = split(/\//, $0);
    my $basename = pop(@path);
    $basename .= '.cfg';
    
    return $basename;
}

#----------------------------------------------------------------------
# Print the help file

sub show_help {
    print <<'EOQ';

Usage: followme [file or directory]

Update a static website after changes. Constant portions of each page are
updated to match, text files are converted to html, and indexes are created
for new files in the archive.

The script is run on the directory or file passed as its argument. If no
argument is given, it is run on the current directory.

If a file is passed, the script is run on the directory the file is in. In
addition, the script is run in quick mode, meaning that only the directory
the file is in is checked for changes. Otherwise not only that directory, but
all directories below it are checked.

Options:

-h --help    print this help
-i --init    copy default templates and configurations to directory

EOQ
    return;
}