From 6b50bdb6053ee46305ef761a2f6f2a2aee8469b4 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 3 Jun 2013 21:42:49 -0500 Subject: add some option parsing to the reply script --- bin/reply | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/bin/reply b/bin/reply index f6f5171..c4f284c 100644 --- a/bin/reply +++ b/bin/reply @@ -6,6 +6,7 @@ use warnings; use File::HomeDir; use File::Spec; +use Getopt::Long; use Reply; @@ -24,7 +25,19 @@ this program. =cut -my $cfg = File::Spec->catfile(File::HomeDir->my_home, ".replyrc"); +my $cfgfile = '.replyrc'; +GetOptions( + 'cfg:s' => \$cfgfile, + 'version' => sub { version() }, + 'help' => sub { usage(0) }, +) or usage(1); + +my $cfg = File::Spec->catfile( + (File::Spec->file_name_is_absolute($cfgfile) + ? () + : (File::HomeDir->my_home)), + $cfgfile +); my %args = (config => $cfg); if (!-e $cfg) { @@ -46,6 +59,16 @@ if (!-e $cfg) { Reply->new(%args)->run; +sub usage { + print " reply [--version] [--help] [--cfg file]\n"; + exit($_[0]); +} + +sub version { + print "Reply version $Reply::VERSION\n"; + exit(0); +} + __DATA__ script_line1 = use strict script_line2 = use warnings -- cgit v1.2.3-54-g00ecf