Subversion Repositories DevTools

Rev

Rev 313 | Rev 325 | Go to most recent revision | Details | Compare with Previous | 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
315 dpurdie 166
#       Programs - show help based on opt_help
167
#       Pods     - show it all
313 dpurdie 168
#
169
Verbose ( "Items", @item_paths  );
170
foreach my $item ( @item_paths )
171
{
172
    pod2usage(-input   => $item,
315 dpurdie 173
              -verbose => ($item =~ m{\.pod$}) ? 3 : $opt_help,
313 dpurdie 174
              -exitval => 'noexit' );
175
}
176
exit (0);
177
 
178
#-------------------------------------------------------------------------------
179
# Function        : display_help_items
180
#
181
# Description     : Create and display a list of help items
182
#                   This will be created based on the search path
183
#
184
#                   Append a (*) to programs that don't have any POD
185
#                   Should serve as a hint to add some helpful help
186
#
187
# Inputs          : prefix
188
#                   header
189
#                   List of files to match
190
#
191
# Returns         : Does not return
192
#
193
 
194
sub display_help_items
195
{
196
    my ($prefix, $header, @ext_list) = @_;
197
 
198
    #
199
    #   Display a list of commands
200
    #
201
    my %list;
202
    foreach my $path ( @etool_path )
203
    {
204
        Verbose2 ("Scanning: $path");
205
        foreach my $ext ( @ext_list )
206
        {
207
            foreach my $file (  glob( "$path/$ext") )
208
            {
209
                my $pod = contains_pod ($file, 0 );
210
                unless ( $opt_verbose )
211
                {
212
                    $file =~ s~.*/~~;
213
                    $file =~ s~\.pl$~~;
214
                    $file =~ s~\.pod$~~;
215
                    $file =~ s~^jats_~~;
216
                    if ( exists $subst{$file} )
217
                    {
218
                        $file = $subst{$file};
219
                        next unless ( $file );
220
                    }
221
                }
222
                $file .= ' *' unless ( $pod );
223
                $list{$file} = 1;
224
            }
225
        }
226
    }
227
 
228
    my $count = 0;
229
    my $limit = $opt_verbose ? 1 : 3;
230
    print "${prefix}Available Help $header\n", '-' x 80;
231
    foreach ( sort keys %list )
232
    {
233
        print "\n  " if ( !( $count++ % $limit) );
234
        printf "%-26s", $_;
235
    }
236
    print "\n";
237
#    print "\n",'-' x 80, "\n";
238
}
239
 
240
#-------------------------------------------------------------------------------
241
#   Documentation
242
#
243
 
244
=pod
245
 
246
=head1 NAME
247
 
248
help - Display help from the various JATS utilities
249
 
250
=head1 SYNOPSIS
251
 
252
 Usage: jats help [opts] topic
253
 
254
 Where opts:
255
    -h, -h=[n], -man=[n]    - Help messages with increasing verbosity
256
    -verbose[=n]            - Verbose operation
257
    -all                    - Also search to internal directories
258
 
259
 Where topic is one of:
260
    A help item             - Documentation on a specific aspect of JATS
261
    A JATS command          - Commands with built in help
262
 
263
=head1 OPTIONS
264
 
265
=over 8
266
 
267
=item B<-help>
268
 
269
Print a brief help message and exits.
270
 
271
=item B<-help -help>
272
 
273
Print a detailed help message with an explanation for each option.
274
 
275
=item B<-man>
276
 
277
Prints the manual page and exits.
278
 
279
=item B<-verbose[=n]>
280
 
281
This option will increase the level of verbosity of the JATS command.
282
 
283
If an argument is provided, then it will be used to set the level, otherwise the
284
existing level will be incremented. This option may be specified multiple times.
285
 
286
=item B<-all>
287
 
288
This option will extend the directories that the help utility will scan for
289
programs and documentation files to include several internal directories.
290
 
291
=back
292
 
293
=head1 DESCRIPTION
294
 
295
This program will display help information from the various JATS utility
296
programs.
297
 
298
Without any options the program will display a list of available commands with
299
built-in help and specialised items.
300
 
301
Commands may be flagged with with a '*' to indicate that the command does not
302
have any built-in help. This serves as an indication that the command needs to
303
be documented.
304
 
305
=cut
306