Moved this script into clearscm
[clearscm.git] / bin / speak
1 #!/usr/bin/perl
2
3 =pod
4
5 =head1 NAME $RCSfile: speak,v $
6
7 Simply speaks the passed in message, clipboard or file
8
9 =head1 VERSION
10
11 =over
12
13 =item Author
14
15 Andrew DeFaria <Andrew@DeFaria.com>
16
17 =item Revision
18
19 $Revision: 1.0 $
20
21 =item Created:
22
23 Wed 24 Feb 2021 12:01:12 PM PST
24
25 =item Modified:
26
27 =back
28
29 =head1 SYNOPSIS
30
31  Usage: speak [-usa|ge] [-h|elp] [-v|erbose] [-de|bug]
32               [-c|lipboard] [-f|ile <filename>] ["message"]
33
34  Where:
35    -usa|ge:          Print this usage
36    -h|elp:           Detailed help
37    -v|erbose:        Verbose mode (Default: -verbose)
38    -de|bug:          Turn on debugging (Default: Off)
39    -c|lipboard:      Speak the contents of the clipboard
40    -f|ile <filename> Speak the contents of <filename>
41    "message"         Speak the message
42
43 =head1 DESCRIPTION
44
45 This script speaks the contents of the passed in message, clipboard or file
46
47 =cut
48
49 use strict;
50 use warnings;
51
52 use FindBin;
53 use Getopt::Long;
54 use Pod::Usage;
55
56 use lib"$FindBin::Bin/../lib";
57
58 use Display;
59 use Clipboard;
60 use Speak;
61
62 my %opts = (
63   usage       => sub { pod2usage },
64   help        => sub { pod2usage(-verbose => 2)},
65   verbose     => sub { set_verbose },
66   debug       => sub { set_debug },
67 );
68
69 ## Main
70 GetOptions(
71   \%opts,
72   'usage',
73   'help',
74   'verbose',
75   'debug',
76   'clipboard',
77   'file=s',
78 ) || pod2usage;
79
80 my $msg = join ' ', @ARGV;
81
82 if ($opts{clipboard}) {
83   if ($opts{file}) {
84     error 'Cannot specify both -clipboard and -file', 1;
85   } elsif ($msg) {
86     error 'Cannot specify both -clipboard and <message>', 1;
87   } else {
88     $msg = Clipboard->paste;
89   } # if
90 } elsif ($opts{file}) {
91   if ($msg) {
92     error 'Cannot specify both -file and <message>', 1;
93   } else {
94     open my $file, '<', $opts{file} or
95       error "Unable to open $opts{file} - $!", 1;
96
97     $msg = <$file>;
98
99     close $file;
100   } # if
101 } # if
102
103 speak $msg;