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

cut: error for unknown options #297

Merged
merged 1 commit into from
Oct 20, 2023
Merged
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
54 changes: 30 additions & 24 deletions bin/cut
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,35 @@ License: perl

$^W = 1; # -w
use strict;
use Getopt::Std;
use File::Basename;

## What's my name?
use File::Basename qw(basename);
use Getopt::Std qw(getopts);

use constant EX_SUCCESS => 0;
use constant EX_FAILURE => 1;

my $me = basename($0);

## Grab options
getopts ('b:c:d:f:ns', \my %opt);
sub usage {
print <<EOT;
usage: $me -b list [-n] [file ...]
$me -c list [file ...]
$me -f list [-d delim] [-s] [file ...]

Each LIST is made up of one range, or many ranges separated by commas.
Each range is one of:

N Nth byte, character or field, counted from 1
N- from Nth byte, character or field, to end of line
N-M from Nth to Mth (included) byte, character or field
-M from first to Mth (included) byte, character or field

EOT
exit EX_FAILURE;
}

my %opt;
getopts('b:c:d:f:ns', \%opt) or usage();

# There's no difference between -b and -c on any unix I
# use regularly -- it's for i18n. Thus, -n is a noop, too.
Expand Down Expand Up @@ -64,7 +85,7 @@ if (defined ($opt{b})) {
}
print "\n";
}
exit 0;
exit EX_SUCCESS;
}

## Field operations
Expand Down Expand Up @@ -114,26 +135,11 @@ elsif (defined ($opt{f})) {
}
}

exit 0;
exit EX_SUCCESS;
}

## $SIG{__CLUE__}
print <<EOT;
usage: $me -b list [-n] [file ...]
$me -c list [file ...]
$me -f list [-d delim] [-s] [file ...]

Each LIST is made up of one range, or many ranges separated by commas.
Each range is one of:

N Nth byte, character or field, counted from 1
N- from Nth byte, character or field, to end of line
N-M from Nth to Mth (included) byte, character or field
-M from first to Mth (included) byte, character or field

EOT

exit 1;
warn "$me: byte, character or field list required\n";
usage();

# (Thanks to Abigail for the pod template.)

Expand Down