Skip to content

Commit fd4403e

Browse files
author
jorvis
committed
added script templates
1 parent 17ec8a9 commit fd4403e

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

Diff for: script_template.pl

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/env perl
2+
3+
=head1 NAME
4+
5+
template.pl - you should put a one-line description of your script here
6+
7+
=head1 SYNOPSIS
8+
9+
USAGE: template.pl
10+
--some_argument=/path/to/some_file.fsa
11+
--another_argument=/path/to/somedir
12+
[ --optional_argument=/path/to/somefile.list
13+
--optional_argument2=1000
14+
]
15+
16+
=head1 OPTIONS
17+
18+
B<--some_argument,-i>
19+
here you'll put a longer description of this argument that can span multiple lines. in
20+
this example, the script has a long option and a short '-i' alternative usage.
21+
22+
B<--another_argument,-o>
23+
here's another named required argument. please try to make your argument names all
24+
lower-case with underscores separating multi-word arguments.
25+
26+
B<--optional_argument,-s>
27+
optional. you should preface any long description of optional arguments with the
28+
optional word as I did in this description. you shouldn't use 'optional' in the
29+
actual argument name like I did in this example, it was just to indicate that
30+
optional arguments in the SYNOPSIS should go between the [ ] symbols.
31+
32+
B<--optional_argument2,-f>
33+
optional. if your optional argument has a default value, you should indicate it
34+
somewhere in this description. ( default = foo )
35+
36+
B<--log,-l>
37+
Log file
38+
39+
B<--help,-h>
40+
This help message
41+
42+
=head1 DESCRIPTION
43+
44+
put a longer overview of your script here.
45+
46+
=head1 INPUT
47+
48+
the input expectations of your script should be here. pasting in examples of file format
49+
expected is encouraged.
50+
51+
=head1 OUTPUT
52+
53+
the output format of your script should be here. if your script manipulates a database,
54+
you should document which tables and columns are affected.
55+
56+
=head1 CONTACT
57+
58+
Your Name
59+
60+
61+
=cut
62+
63+
use warnings;
64+
use strict;
65+
use Getopt::Long qw(:config no_ignore_case no_auto_abbrev pass_through);
66+
use Pod::Usage;
67+
68+
my %options = ();
69+
my $results = GetOptions (\%options,
70+
'some_argument|i=s',
71+
'another_argument|o=s',
72+
'optional_argument|s=s',
73+
'optional_argument2|f=s',
74+
'log|l=s',
75+
'help|h') || pod2usage();
76+
77+
## display documentation
78+
if( $options{'help'} ){
79+
pod2usage( {-exitval => 0, -verbose => 2, -output => \*STDERR} );
80+
}
81+
82+
## make sure everything passed was peachy
83+
&check_parameters(\%options);
84+
85+
## open the log if requested
86+
my $logfh;
87+
if (defined $options{log}) {
88+
open($logfh, ">$options{log}") || die "can't create log file: $!";
89+
}
90+
91+
##
92+
## CODE HERE
93+
##
94+
95+
exit(0);
96+
97+
98+
sub _log {
99+
my $msg = shift;
100+
101+
print $logfh "$msg\n" if $logfh;
102+
}
103+
104+
105+
sub check_parameters {
106+
my $options = shift;
107+
108+
## make sure required arguments were passed
109+
my @required = qw( some_argument another_argument );
110+
for my $option ( @required ) {
111+
unless ( defined $$options{$option} ) {
112+
die "--$option is a required option";
113+
}
114+
}
115+
116+
##
117+
## you can do other things here, such as checking that files exist, etc.
118+
##
119+
120+
## handle some defaults
121+
$options{optional_argument2} = 'foo' unless ($options{optional_argument2});
122+
}

Diff for: script_template.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3.2
2+
3+
import argparse
4+
import os
5+
6+
7+
def main():
8+
parser = argparse.ArgumentParser( description='Put a description of your script here')
9+
10+
## output file to be written
11+
parser.add_argument('-o', '--output_file', type=str, required=True, help='Path to an output file to be created' )
12+
args = parser.parse_args()
13+
14+
15+
16+
17+
if __name__ == '__main__':
18+
main()
19+
20+
21+
22+
23+
24+
25+

0 commit comments

Comments
 (0)