From: Mark Wooding Date: Wed, 10 Jun 2020 15:05:46 +0000 (+0100) Subject: bin/disorder-notify: Add a proper command-line parser, and support `-u'. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/21ec4bc8ec92f4190a7506586e3f528c14536eba?ds=sidebyside bin/disorder-notify: Add a proper command-line parser, and support `-u'. --- diff --git a/bin/disorder-notify b/bin/disorder-notify index 49e83f0..91278f0 100755 --- a/bin/disorder-notify +++ b/bin/disorder-notify @@ -5,6 +5,8 @@ use strict; use DisOrder; use File::FcntlLock; +use Getopt::Long qw{:config gnu_compat bundling + require_order no_getopt_compat}; use POSIX qw{:errno_h :fcntl_h}; ###-------------------------------------------------------------------------- @@ -14,6 +16,7 @@ my %C = (config => "$ENV{HOME}/.disorder/passwd", lockdir => "$ENV{HOME}/.disorder/", mixer => "Master,0"); +(my $PROG = $0) =~ s:^.*/::; my $TITLE = "DisOrder"; my $VARIANT = "default"; if (-l $C{config} && (my $t = readlink $C{config}) =~ /^passwd\.(.*)$/) @@ -358,7 +361,39 @@ $OP{"next-config"} = sub { ###-------------------------------------------------------------------------- ### Main program. -if (@ARGV != 1) { print STDERR "usage: $0 OP\n"; exit 2; } +sub usage (\*) { + my ($fh) = @_; + print $fh "usage: $PROG [-u CONFIG] COMMAND\n"; +} + +sub help () { + usage *STDOUT; + print < sub { help; exit 0; }, + "u|user-config=s" => \$C{config} + or $bad = 1; +@ARGV == 1 or $bad = 1; +if ($bad) { usage *STDERR; exit 2; } my $op = $ARGV[0]; if (!exists $OP{$op}) { print STDERR "$0: unknown op `$op'\n"; exit 2; } $OP{$op}();