Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basename: support -- option terminator #723

Merged
merged 2 commits into from
Aug 16, 2024
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
27 changes: 17 additions & 10 deletions bin/basename
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ License: perl


use strict;
use File::Basename;

my ($VERSION) = '1.3';
use File::Basename qw(basename fileparse);
use Getopt::Std qw(getopts);

unless (@ARGV == 1 || @ARGV == 2) {
$0 = basename ($0);
print <<EOF;
$0 (Perl bin utils) $VERSION
usage: $0 string [suffix | /pattern/]
EOF
exit 1;
};
my $Program = basename($0);
our $VERSION = '1.4';

getopts('') or usage();
usage() unless (@ARGV == 1 || @ARGV == 2);
if (@ARGV == 2) {
$ARGV [1] = quotemeta $ARGV [1] unless $ARGV [1] =~ s{^/(.*)/$}{$1};
}
Expand All @@ -44,6 +40,17 @@ $path =~ s/\/\Z//; # "a/" -> "a"
my @parsed = fileparse($path);
my $name = shift @parsed;
print $name, "\n";
exit 0;

sub VERSION_MESSAGE {
print "$Program version $VERSION\n";
exit 0;
}

sub usage {
warn "usage: $Program string [suffix | /pattern/]\n";
exit 1;
}

__END__

Expand Down
2 changes: 1 addition & 1 deletion bin/dirname
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use Getopt::Std qw(getopts);
my $Program = basename($0);
our $VERSION = '1.3';

getopts('') or die "usage: $Program string\n";
getopts('') or usage();
usage() unless scalar(@ARGV) == 1;
my $path = shift;
my $dir = dirname($path);
Expand Down
Loading