App-ShellCompleter-cpanm

 view release on metacpan or  search on metacpan

lib/App/ShellCompleter/cpanm.pm  view on Meta::CPAN

        my @mods;
        while (my @row = $sth->fetchrow_array) {
            my $mod = $row[0];
            $mod =~ s/\A\Q$mod_prefix\E//;
            push @mods, $mod unless grep { $_ eq $mod } @mods;
            if ($row[1]) {
                $mod .= '::';
                push @mods, $mod unless grep { $_ eq $mod } @mods;
            }
        };
        return \@mods if @mods;
    }

    # TODO module name can be suffixed with '@<version>'

    [];
};

sub _connect_lcpan {
    no warnings 'once';

    eval "use App::lcpan 0.32"; ## no critic: TestingAndDebugging::ProhibitNoStrict
    if ($@) {
        log_trace("[_cpanm] App::lcpan not available, skipped ".
                         "trying to complete from CPAN module names");
        return;
    }

    require Perinci::CmdLine::Util::Config;

    my %lcpanargs;
    my $res = Perinci::CmdLine::Util::Config::read_config(
        program_name => "lcpan",
    );
    unless ($res->[0] == 200) {
        log_trace("[_cpanm] Can't get config for lcpan: %s", $res);
        last;
    }
    my $config = $res->[2];

    $res = Perinci::CmdLine::Util::Config::get_args_from_config(
        config => $config,
        args   => \%lcpanargs,
        #subcommand_name => 'update',
        meta   => $App::lcpan::SPEC{update},
    );
    unless ($res->[0] == 200) {
        log_trace("[_cpanm] Can't get args from config: %s", $res);
        return;
    }
    App::lcpan::_set_args_default(\%lcpanargs);
    my $dbh = App::lcpan::_connect_db('ro', $lcpanargs{cpan}, $lcpanargs{index_name});
}

sub run_completer {
    my %cargs = @_;

    die "This script is for shell completion only\n"
        unless $ENV{GETOPT_LONG_DUMP} || $ENV{COMP_LINE} || $ENV{COMMAND_LINE};

    # the list of options is taken from Menlo::CLI:Compat. should be updated
    # from time to time.
    GetOptionsWithCompletion(
        sub {
            my %args  = @_;
            my $type      = $args{type};
            my $word      = $args{word};
            if ($type eq 'arg') {
                log_trace("[_cpanm] Completing arg");
                my $seen_opts = $args{seen_opts};
                if ($seen_opts->{'--uninstall'} || $seen_opts->{'--reinstall'}) {
                    return $comp_installed_mods->(word=>$word);
                } else {
                    return $comp_installable->(
                        mod_prefix => $cargs{mod_prefix},
                        word=>$word, mirror=>$seen_opts->{'--mirror'});
                }
            } elsif ($type eq 'optval') {
                my $ospec = $args{ospec};
                my $opt   = $args{opt};
                log_trace("[_cpanm] Completing optval (opt=$opt)");
                if ($ospec eq 'l|local-lib=s' ||
                        $ospec eq 'L|local-lib-contained=s') {
                    return complete_file(filter=>'d', word=>$word);
                } elsif ($ospec eq 'format=s') {
                    return complete_array_elem(
                        array=>[qw/tree json yaml dists/], word=>$word);
                } elsif ($ospec eq 'cpanfile=s') {
                    return complete_file(word=>$word);
                }
            }
            return [];
        },
        'f|force'   => $noop,
        'n|notest!' => $noop,
        'test-only' => $noop,
        'S|sudo!'   => $noop,
        'v|verbose' => $noop,
        'verify!'   => $noop,
        'q|quiet!'  => $noop,
        'h|help'    => $noop,
        'V|version' => $noop,
        'perl=s'          => $noop,
        'l|local-lib=s'   => $noop,
        'L|local-lib-contained=s' => $noop,
        'self-contained!' => $noop,
        'exclude-vendor!' => $noop,
        'mirror=s@'       => $noop,
        'mirror-only!'    => $noop,
        'mirror-index=s'  => $noop,
        'M|from=s'        => $noop, # url (this is --mirror and --mirror-only combined)
        'cpanmetadb=s'    => $noop,
        'cascade-search!' => $noop,
        'prompt!'         => $noop,
        'installdeps'     => $noop,
        'skip-installed!' => $noop,
        'skip-satisfied!' => $noop,
        'reinstall'       => $noop,
        'interactive!'    => $noop,
        'i|install'       => $noop,
        'info'            => $noop,



( run in 2.758 seconds using v1.01-cache-2.11-cpan-13bb782fe5a )