summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2023-05-21 13:44:57 +0000
committerMarc Espie <espie@cvs.openbsd.org>2023-05-21 13:44:57 +0000
commite64ecded01a4c592950c581ddc178a07ab42f48c (patch)
treea86ff3f855efe2123c3d40982ca3ae51c71c802a /usr.sbin
parent3c0f87a0db0476ae1b22f5c1183b8fdedbebc7de (diff)
document how this is used... There's nothing that actually uses the
export part, and be explicit about how we call code refs.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Getopt.pod27
1 files changed, 13 insertions, 14 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Getopt.pod b/usr.sbin/pkg_add/OpenBSD/Getopt.pod
index 182bec99e23..a4f17fbbce7 100644
--- a/usr.sbin/pkg_add/OpenBSD/Getopt.pod
+++ b/usr.sbin/pkg_add/OpenBSD/Getopt.pod
@@ -1,4 +1,4 @@
-$OpenBSD: Getopt.pod,v 1.1 2020/12/20 15:30:58 daniel Exp $
+$OpenBSD: Getopt.pod,v 1.2 2023/05/21 13:44:56 espie Exp $
=head1 NAME
@@ -8,25 +8,24 @@ OpenBSD::Getopt - Process single-characters switches
use OpenBSD::Getopt;
- our($opt_o, $opt_i, $opt_f, $opt_v);
- getopts('oifv:',
- { 'v' => sub {
- ++$opt_v;}
- }
+ my $h = { 'v' =>
+ sub() {
+ ++$opt_v;
+ };
+ };
+ getopts('oifv:', $h);
=head1 DESCRIPTION
-This is similar to L<getopt(3)>. One call to C<getopts($optstring)> parses
+This is similar to L<getopt(3)>. One call to C<getopts($optstring, $h)> parses
all the options using the C<$optstring> as a list of simple switches
(letter) and switches with arguments (letter followed by C<:>).
-Option values are directly written into local variables of the form
-C<$opt_S>, where C<S> is the switch name.
-
-Contrary to L<getopt(3)>, C<$opt_S> is incremented each time the switch is
+Option values are written into the hash C<$h>.
+Contrary to L<getopt(3)>, C<$h-E<gt>{v}> is incremented each time the switch is
seen, to allow for stuff like C<-vv>.
-An optional hash can be used as a second argument, with switches as keys
-and subs as values. When a switch is met, the sub C<$foo> is called as
-C<$foo> for a simple switch and as C<$foo(option_value)> for a switch
+Alternately, a code ref can be put into the hash for a given switch.
+When a switch is seen, the sub C<$foo> is called as
+C<&$foo()> for a simple switch and as C<&$foo(option_value)> for a switch
with argument.