Subversion Repositories DevTools

Rev

Rev 315 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
313 dpurdie 1
########################################################################
2
# Copyright (C) 2009 ERG Limited, All rights reserved
3
#
4
# Module name   : jats_help.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Utility to drive the JATS Help System
10
#
11
# Usage:
12
#
13
#......................................................................#
14
 
15
require 5.008_002;
16
use strict;
17
use warnings;
18
 
19
use Pod::Usage;
20
use Pod::Find qw(contains_pod);
21
use Getopt::Long;
22
 
23
use JatsError;
24
 
25
#-------------------------------------------------------------------------------
26
#   Global variables
27
#
28
my $VERSION = "1.0.0";                      # Update this
29
 
30
#
31
#   Options
32
#
33
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
34
my $opt_verbose = $ENV{'opt_verbose'};      # Allow global verbose
35
my $opt_help = 0;
36
my $opt_all = 0;
37
 
38
#
39
#   Hash of substitute/hide items
40
#   Hide with undef value
41
#
42
my %subst = (
43
    'jmake'                 => 'make',
44
    'buildlib'              => 'build',
45
 
46
    #
47
    #   Don't show the user these programs
48
    #   Many are internal programs and don't have POD
49
    #
50
    'cloc-1.00'             => undef,
51
    'common'                => undef,
52
    'makelib'               => undef,
53
    'installpkg'            => undef,
54
 
55
);
56
 
57
#
58
#   A list of paths to search
59
#
60
my @etool_path = ( "$ENV{'GBE_TOOLS'}",
61
#                   "$ENV{'GBE_TOOLS'}/DEPLOY",
62
#                   "$ENV{'GBE_TOOLS'}/LOCAL",
63
                   "$ENV{'GBE_TOOLS'}/POD"
64
                    );
65
 
66
my @all_path = (   "$ENV{'GBE_TOOLS'}/DEPLOY",
67
                   "$ENV{'GBE_TOOLS'}/LOCAL",
68
                    );
69
 
70
 
71
#-------------------------------------------------------------------------------
72
# Function        : Mainline Entry Point
73
#
74
# Description     :
75
#
76
# Inputs          :
77
#
78
my $result = GetOptions (
79
                "help|h:+"      => \$opt_help,
80
                "manual:3"      => \$opt_help,
81
                "verbose+"      => \$opt_verbose,           # flag, multiple use allowed
82
                "all:+"         => \$opt_all,
83
                #
84
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
85
                #
86
                );
87
 
88
#
89
#   Configure the error reporting process now that we have the user options
90
#
91
ErrorConfig( 'name'    =>'help',
92
             'verbose' => $opt_verbose,
93
            );
94
#
95
#   Extend the search path if required
96
#
97
push @etool_path, @all_path if ( $opt_all );
98
 
99
#-------------------------------------------------------------------------------
100
#
101
#   If the user has not provided any arguments, then display some simple
102
#   help and a list of possible commands
103
#
104
if ( $#ARGV < 0 )
105
{
106
    pod2usage(-verbose => $opt_help,
107
              -message => "Version: $VERSION",
108
              -exitval => 'noexit'
109
              );
110
    unless( $opt_help )
111
    {
112
        display_help_items("",   'Items',   '*.pod');
113
        display_help_items("\n", 'Commands','*.pl');
114
    }
115
    exit 0;
116
}
117
 
118
#-------------------------------------------------------------------------------
119
#   Take the user argument as help topic and attempt to locate it it as:
120
#       JATS etool          - Exists as a tool
121
#       JATS help item      - Exists in a POD directory
122
#
123
 
124
#
125
#   Allow the user item to be substituted
126
#   Some commands had bad names
127
#
128
#   First, invert the %subst hash and delete the hidden entries
129
#
130
my %lookup;
131
while (my ($k,$v) = each(%subst)) {
132
    $lookup{$v} = $k if ( defined $v );
133
}
134
 
135
my $uitem =$ARGV[0];
136
$uitem = $lookup{$uitem}
137
    if ( $lookup{$uitem} );
138
 
139
#
140
#   Scan for all possible items
141
#
142
my @item_paths;
143
foreach my $path ( @etool_path )
144
{
145
    Verbose2 ("Scanning: $path");
146
 
147
    foreach my $prefix ( 'jats_', '' )
148
    {
149
        foreach my $suffix ( '.pl', '.pod', '' )
150
        {
151
            my $item = $path . '/' . $prefix . $uitem . $suffix;
152
            push @item_paths, $item if ( -f $item );
153
        }
154
    }
155
}
156
 
157
#
158
#   If no topics are found, then prod the user
159
#
160
Error ("No matching help topic found for : $uitem",
161
       "Use 'jats help' to provide a list of available topics"
162
        )unless ( @item_paths );
163
 
164
#
165
#   Process the required items
166
#
167
Verbose ( "Items", @item_paths  );
168
foreach my $item ( @item_paths )
169
{
170
    pod2usage(-input   => $item,
171
              -verbose => $opt_help,
172
              -exitval => 'noexit' );
173
}
174
exit (0);
175
 
176
#-------------------------------------------------------------------------------
177
# Function        : display_help_items
178
#
179
# Description     : Create and display a list of help items
180
#                   This will be created based on the search path
181
#
182
#                   Append a (*) to programs that don't have any POD
183
#                   Should serve as a hint to add some helpful help
184
#
185
# Inputs          : prefix
186
#                   header
187
#                   List of files to match
188
#
189
# Returns         : Does not return
190
#
191
 
192
sub display_help_items
193
{
194
    my ($prefix, $header, @ext_list) = @_;
195
 
196
    #
197
    #   Display a list of commands
198
    #
199
    my %list;
200
    foreach my $path ( @etool_path )
201
    {
202
        Verbose2 ("Scanning: $path");
203
        foreach my $ext ( @ext_list )
204
        {
205
            foreach my $file (  glob( "$path/$ext") )
206
            {
207
                my $pod = contains_pod ($file, 0 );
208
                unless ( $opt_verbose )
209
                {
210
                    $file =~ s~.*/~~;
211
                    $file =~ s~\.pl$~~;
212
                    $file =~ s~\.pod$~~;
213
                    $file =~ s~^jats_~~;
214
                    if ( exists $subst{$file} )
215
                    {
216
                        $file = $subst{$file};
217
                        next unless ( $file );
218
                    }
219
                }
220
                $file .= ' *' unless ( $pod );
221
                $list{$file} = 1;
222
            }
223
        }
224
    }
225
 
226
    my $count = 0;
227
    my $limit = $opt_verbose ? 1 : 3;
228
    print "${prefix}Available Help $header\n", '-' x 80;
229
    foreach ( sort keys %list )
230
    {
231
        print "\n  " if ( !( $count++ % $limit) );
232
        printf "%-26s", $_;
233
    }
234
    print "\n";
235
#    print "\n",'-' x 80, "\n";
236
}
237
 
238
#-------------------------------------------------------------------------------
239
#   Documentation
240
#
241
 
242
=pod
243
 
244
=head1 NAME
245
 
246
help - Display help from the various JATS utilities
247
 
248
=head1 SYNOPSIS
249
 
250
 Usage: jats help [opts] topic
251
 
252
 Where opts:
253
    -h, -h=[n], -man=[n]    - Help messages with increasing verbosity
254
    -verbose[=n]            - Verbose operation
255
    -all                    - Also search to internal directories
256
 
257
 Where topic is one of:
258
    A help item             - Documentation on a specific aspect of JATS
259
    A JATS command          - Commands with built in help
260
 
261
=head1 OPTIONS
262
 
263
=over 8
264
 
265
=item B<-help>
266
 
267
Print a brief help message and exits.
268
 
269
=item B<-help -help>
270
 
271
Print a detailed help message with an explanation for each option.
272
 
273
=item B<-man>
274
 
275
Prints the manual page and exits.
276
 
277
=item B<-verbose[=n]>
278
 
279
This option will increase the level of verbosity of the JATS command.
280
 
281
If an argument is provided, then it will be used to set the level, otherwise the
282
existing level will be incremented. This option may be specified multiple times.
283
 
284
=item B<-all>
285
 
286
This option will extend the directories that the help utility will scan for
287
programs and documentation files to include several internal directories.
288
 
289
=back
290
 
291
=head1 DESCRIPTION
292
 
293
This program will display help information from the various JATS utility
294
programs.
295
 
296
Without any options the program will display a list of available commands with
297
built-in help and specialised items.
298
 
299
Commands may be flagged with with a '*' to indicate that the command does not
300
have any built-in help. This serves as an indication that the command needs to
301
be documented.
302
 
303
=cut
304