Skip to content

Commit edb9378

Browse files
authored
shar: error detected for no files processed (#475)
* Print usage and exit if no file arguments are given (in docs, at least one file argument is required and standard input is not used) * Remove variable $dirty for keeping track of whether header was printed; just print it once before loop * Introduce variable $done to count how many files were processed * Checking $dirty at end of loop was incorrect; this resulted in printing an error on success and exiting with error code * test1: "perl shar" --> no args, usage * test2: "perl shar no-such-file" --> print message "no files were processed" * test3: "perl shar tar" --> archive one file 'tar' successfully
1 parent 1d74b03 commit edb9378

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

bin/shar

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ sub usage {
3131
}
3232

3333
getopts('') or usage();
34+
@ARGV or usage();
3435
binmode STDOUT;
3536

36-
my $dirty = 0;
37-
ARGUMENT: for my $f ( @ARGV ) {
38-
unless ($dirty) {
39-
print '# --cut here--
37+
print '# --cut here--
4038
# To extract, remove everything before the "cut here" line
4139
# and run the command "sh file".
4240
';
43-
$dirty = 1;
44-
}
41+
42+
my $done = 0;
43+
ARGUMENT: for my $f ( @ARGV ) {
4544
if (-d $f) {
4645
print "echo x - $f/\n";
4746
print "mkdir -p $f\n";
47+
$done++;
4848
next ARGUMENT;
4949
}
5050
unless (open FH, '<', $f) {
@@ -68,9 +68,9 @@ ARGUMENT: for my $f ( @ARGV ) {
6868
}
6969
print "FUNKY_STUFF\n";
7070
close(FH);
71+
$done++;
7172
}
72-
73-
unless ($dirty) {
73+
if ($done == 0) {
7474
warn "$Program: no input files were processed\n";
7575
exit EX_FAILURE;
7676
}

0 commit comments

Comments
 (0)