package Dist::Zilla::App::Command::codeberg 2.0000;
use Modern::Perl;
use Cwd qw(cwd);
use Dist::Zilla::App -command;
our $AUTHORITY = 'cpan:GEEKRUTH';    # AUTHORITY

## no critic qw(ProhibitAmbiguousNames)
sub abstract    {'use the Codeberg plugins from the command-line'}
sub description {'Use the Codeberg plugins from the command-line'}
sub usage_desc  {'%c %o [ update | create [<repository>] ]'}

## no critic qw(ProhibitCommaSeparatedStatements)
sub opt_spec {
   [
      'profile|p=s', 'name of the profile to use',
      { default => 'default' }
   ],

      [
      'provider|P=s', 'name of the profile provider to use',
      { default => 'Default' }
      ],
      ;
}
## use critic
sub execute {
   my ( $self, $opt, $arg ) = @_;

   my $zilla = $self->zilla;

   $_->gather_files
      for eval { Dist::Zilla::App->VERSION('7.000') }
      ? $zilla->plugins_with( -FileGatherer )
      : @{ $zilla->plugins_with( -FileGatherer ) };

   if ( $arg->[0] eq 'create' ) {
      require Dist::Zilla::Dist::Minter;

      my $minter = Dist::Zilla::Dist::Minter->_new_from_profile(
         [ $opt->provider, $opt->profile ], {
            chrome => $self->app->chrome,
            name   => $zilla->name,
         },
      );

      my $create = _find_plug( $minter, 'Codeberg::Create' );
      my $root   = cwd();
      my $repo   = $arg->[1];
      $create->after_mint(
         {
            mint_root   => $root,
            repo        => $repo,
            description => $zilla->abstract
         }
      );
   }
   elsif ( $arg->[0] eq 'update' ) {
      _find_plug( $zilla, 'Codeberg::Update' )->after_release;
   }
}

sub _find_plug {
   my ( $self, $name ) = @_;

   foreach ( @{ $self->plugins } ) {
      return $_ if $_->plugin_name =~ /$name/;
   }
}

1;

=pod

=encoding UTF-8

=head1 NAME

Dist::Zilla::App::Command::codeberg - Use the Codeberg plugins from the command-line

=head1 VERSION

version 2.0000

=head1 SYNOPSIS

    # create a new Codeberg repository for your dist
    $ dzil codeberg create [<repository>]

    # update Codeberg repo information
    $ dzil codeberg update

=head1 AUTHOR

D Ruth Holloway <ruth@hiruthie.me>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by D Ruth Holloway.

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

__END__

# ABSTRACT: Use the Codeberg plugins from the command-line

