#! perl
# ABSTRACT: A tool for managing CODEOWNERS files
# PODNAME: git-codeowners


# FATPACK - Do not remove this line.

use warnings;
use strict;

use App::Codeowners;

our $VERSION = '0.44'; # VERSION

App::Codeowners->main(@ARGV);

__END__

=pod

=encoding UTF-8

=head1 NAME

git-codeowners - A tool for managing CODEOWNERS files

=head1 VERSION

version 0.44

=head1 SYNOPSIS

    git-codeowners [--version|--help|--manual]

    git-codeowners [show] [--format FORMAT] [--owner OWNER]...
                   [--pattern PATTERN]... [--[no-]patterns]
                   [--project PROJECT]... [--[no-]projects] [PATH...]

    git-codeowners owners [--format FORMAT] [--pattern PATTERN]

    git-codeowners patterns [--format FORMAT] [--owner OWNER]

    git-codeowners create|update [REPO_DIRPATH|CODEOWNERS_FILEPATH]

    # enable bash shell completion
    eval "$(git-codeowners --shell-completion)"

=head1 DESCRIPTION

F<git-codeowners> is yet another CLI tool for managing F<CODEOWNERS> files in git repos. In
particular, it can be used to quickly find out who owns a particular file in a monorepo (or
monolith).

B<THIS IS EXPERIMENTAL!> The interface of this tool and its modules will probably change as I field
test some things. Feedback welcome.

=head1 INSTALL

There are several ways to install F<git-codeowners> to your system.

=head2 from CPAN

You can install F<git-codeowners> using L<cpanm>:

    cpanm App::Codeowners

=head2 from GitHub

You can also choose to download F<git-codeowners> as a self-contained executable:

    curl -OL https://raw.githubusercontent.com/chazmcgarvey/git-codeowners/solo/git-codeowners
    chmod +x git-codeowners

To hack on the code, clone the repo instead:

    git clone https://github.com/chazmcgarvey/git-codeowners.git
    cd git-codeowners
    make bootstrap      # installs dependencies; requires cpanm

=head1 OPTIONS

=head2 --version

Print the program name and version to C<STDOUT>, and exit.

Alias: C<-v>

=head2 --help

Print the synopsis to C<STDOUT>, and exit.

Alias: C<-h>

You can also use C<--manual> to print the full documentation.

=head2 --color

Enable colorized output.

Color is ON by default on terminals; use C<--no-color> to disable. Some environment variables may
also alter the behavior of colorizing output:

=over 4

=item *

C<NO_COLOR> - Set to disable color (same as C<--no-color>).

=item *

C<COLOR_DEPTH> - Set the number of supportable colors (e.g. 0, 16, 256, 16777216).

=back

=head2 --format

Specify the output format to use. See L</FORMAT>.

Alias: C<-f>

=head2 --shell-completion

    eval "$(lintany --shell-completion)"

Print shell code to enable completion to C<STDOUT>, and exit.

Does not yet support Zsh...

=head1 COMMANDS

=head2 show

    git-codeowners [show] [--format FORMAT] [--owner OWNER]...
                   [--pattern PATTERN]... [--[no-]patterns]
                   [--project PROJECT]... [--[no-]projects] [PATH...]

Show owners of one or more files in a repo.

If C<--owner>, C<--project>, C<--pattern> are set, only show files with matching
criteria. These can be repeated.

Use C<--patterns> to also show the matching pattern associated with each file.

By default the output might show associated projects if the C<CODEOWNERS> file
defines them. You can control this by explicitly using C<--projects> or
C<--no-projects> to always show or always hide defined projects, respectively.

=head2 owners

    git-codeowners owners [--format FORMAT] [--pattern PATTERN]

List all owners defined in the F<CODEOWNERS> file.

=head2 patterns

    git-codeowners patterns [--format FORMAT] [--owner OWNER]

List all patterns defined in the F<CODEOWNERS> file.

=head2 create

    git-codeowners create [REPO_DIRPATH|CODEOWNERS_FILEPATH]

Create a new F<CODEOWNERS> file for a specified repo (or current directory).

=head2 update

    git-codeowners update [REPO_DIRPATH|CODEOWNERS_FILEPATH]

Update the "unowned" list of an existing F<CODEOWNERS> file for a specified
repo (or current directory).

=head1 FORMAT

The C<--format> argument can be one of:

=over 4

=item *

C<csv> - Comma-separated values (requires L<Text::CSV>)

=item *

C<json:pretty> - Pretty JSON (requires L<JSON::MaybeXS>)

=item *

C<json> - JSON (requires L<JSON::MaybeXS>)

=item *

C<table> - Table (requires L<Text::Table::Any>)

=item *

C<tsv> - Tab-separated values (requires L<Text::CSV>)

=item *

C<yaml> - YAML (requires L<YAML>)

=item *

C<FORMAT> - Custom format (see below)

=back

=head2 Format string

You can specify a custom format using printf-like format sequences. These are the items that can be
substituted:

=over 4

=item *

C<%F> - Filename

=item *

C<%O> - Owner or owners

=item *

C<%P> - Project

=item *

C<%T> - Pattern

=item *

C<%n> - newline

=item *

C<%t> - tab

=item *

C<%%> - percent sign

=back

The syntax also allows padding and some filters. Examples:

    git-codeowners show -f ' * %-50F %O'                # default for "show"
    git-codeowners show -f '%{quote}F,%{quote}O'        # ad hoc CSV
    git-codeowners patterns -f '--> %{color:0c0}T'      # whatever...

Available filters:

=over 4

=item *

C<quote> - Quote the replacement string.

=item *

C<color:FFFFFF> - Colorize the replacement string (if color is ON).

=item *

C<nocolor> - Do not colorize replacement string.

=back

=head2 Format table

Table formatting can be done by one of several different modules, each with its own features and
bugs. The default module is L<Text::Table::Tiny>, but this can be overridden using the
C<PERL_TEXT_TABLE> environment variable if desired, like this:

    PERL_TEXT_TABLE=Text::Table::HTML git-codeowners -f table

The list of available modules is at L<Text::Table::Any/@BACKENDS>.

=head1 CAVEATS

=over 4

=item *

Some commands require F<git> (at least version 1.8.5).

=back

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website
L<https://github.com/chazmcgarvey/git-codeowners/issues>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

Charles McGarvey <chazmcgarvey@brokenzipper.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2019 by Charles McGarvey.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
