Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions contrib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Other Content

## Command Completion

### Installation

For Bash:

Copy the completion script to operating system specific folder, e.g.

* /usr/share/bash-completion/completions/
* /etc/bash_completion.d

11 changes: 11 additions & 0 deletions contrib/bash-completion/completions/mech-dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
_comp_cmd_mech_dump()
{
local cur
cur=${COMP_WORDS[COMP_CWORD]}

# shellcheck disable=SC2207,SC2016
COMPREPLY=( $( compgen -W '$(mech-dump --completions)' -- "$cur" ) )
} &&
complete -F _comp_cmd_mech_dump mech-dump

# ex: filetype=sh
34 changes: 28 additions & 6 deletions script/mech-dump
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ my $agent;
my $agent_alias;
my $cookie_filename;

GetOptions(
my %command_line_options = (
'user=s' => \$user,
'password=s' => \$pass,
headers => sub { push( @actions, \&dump_headers ) },
Expand All @@ -30,18 +30,39 @@ GetOptions(
all => sub {
$all++;
push(
@actions, \&dump_headers, \&dump_forms, \&dump_links,
\&dump_images
@actions,
\&dump_headers, \&dump_forms, \&dump_links, \&dump_images
);
},
text => sub { push( @actions, \&dump_text ) },
absolute => \$absolute,
'absolute!' => \$absolute,
'agent=s' => \$agent,
'agent-alias=s' => \$agent_alias,
'cookie-file=s' => \$cookie_filename,
help => sub { pod2usage(1); },
version => sub { print STDERR $WWW::Mechanize::VERSION, "\n"; exit 0; },
) or pod2usage(2);
'completions' => sub { completions(@ARGV); },
);
GetOptions(%command_line_options) or pod2usage(2);

sub completions {
my (@words) = @_;
my @opts;
foreach ( sort keys %command_line_options ) {
if (m/^ (?<opt> [^!]+) ! $/msx) {
push @opts, $+{opt}, 'no-' . $+{opt};
}
elsif (m/^ (?<opt> [^=]+) = [siof]{1} $/msx) {
push @opts, ( split qr{\|}, $+{opt} );
}
else {
push @opts, $_;
}
}
print join "\n", ( map { q{--} . $_ } @opts );
print "\n";
exit 0;
}

=head1 SYNOPSIS

Expand Down Expand Up @@ -103,7 +124,8 @@ elsif ( defined $agent_alias ) {
}
if ( defined $cookie_filename ) {
my $cookies = HTTP::Cookies->new(
file => $cookie_filename, autosave => 1,
file => $cookie_filename,
autosave => 1,
ignore_discard => 1
);
$cookies->load();
Expand Down