#!/bin/sh

: <<=cut
=pod

=head1 NAME

wrt - WRiting Tool, a static site/blog generator and related utilites

=head1 SYNOPSIS

    wrt init          # Initialize a wrt repository
    wrt display       # Print HTML for entries
    wrt feed          # Print feeds for entries
    wrt render-all    # Render all defined entries to filesystem
    wrt ls            # List entries in repository
    wrt config        # Display current configuration
    wrt repl          # Get a debug REPL for current wrt repo
    wrt addprop       # Add a property to an entry
    wrt findprop      # Find entries containing certain properties
    wrt version, -v   # Print the installed version of wrt
    wrt help, -h      # Print this help message

=head1 DESCRIPTION

wrt is a small collection of utilities for authoring a simple, date-based
blog or other static site.

C<wrt> is a simple wrapper script which invokes other subcommands.  It will
pass its arguments along to any command of the form C<wrt-command>.

Detailed documentation can be found in the L<App::WRT> man page or at
L<https://code.p1k3.com/gitea/brennen/wrt>.

=head1 LICENSE

    wrt is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

=head1 AUTHOR

Brennen Bearnes <code@p1k3.com>

=cut

if [ $# -lt 1 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
  # No subcommand given or help requested:
  exec wrt-help
elif [ "$1" = "--version" ] || [ "$1" = "-v" ]; then
  # Version info requested:
  exec wrt-version
else
  # We should hand off to a requested subcommand:
  subprog="wrt-$1"
fi

# Make sure that the command we've been given exists:
command -v "$subprog" >/dev/null 2>&1 || {
  echo "wrt: '$1' is not a wrt command.  See 'wrt help'."
  exit 1
}

shift
exec "$subprog" "$@"