From 4da8c75b2fb8133aa63dcf4e7f75a0ec0e5cc6e6 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Fri, 20 Oct 2023 21:59:59 +0800 Subject: [PATCH] cut: error for unknown options * Print usage and exit with error code if user typed an incorrect option * If getopts() succeeded but one of -b/-c/-f is not provided, print a descriptive error before usage() --- bin/cut | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/bin/cut b/bin/cut index d2fe4214..a377befa 100755 --- a/bin/cut +++ b/bin/cut @@ -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 <