Subversion Repositories DevTools

Rev

Rev 5709 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
313 dpurdie 1
########################################################################
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
313 dpurdie 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
325 dpurdie 34
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
313 dpurdie 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
#
325 dpurdie 91
ErrorConfig( 'name'    => 'help',
313 dpurdie 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
              );
325 dpurdie 110
    display_help_items("",   'Items',   '*.pod');
111
    display_help_items("\n", 'Commands','*.pl');
313 dpurdie 112
    exit 0;
113
}
114
 
115
#-------------------------------------------------------------------------------
116
#   Take the user argument as help topic and attempt to locate it it as:
117
#       JATS etool          - Exists as a tool
118
#       JATS help item      - Exists in a POD directory
119
#
120
 
121
#
122
#   Allow the user item to be substituted
123
#   Some commands had bad names
124
#
125
#   First, invert the %subst hash and delete the hidden entries
126
#
127
my %lookup;
128
while (my ($k,$v) = each(%subst)) {
129
    $lookup{$v} = $k if ( defined $v );
130
}
131
 
132
my $uitem =$ARGV[0];
133
$uitem = $lookup{$uitem}
134
    if ( $lookup{$uitem} );
135
 
136
#
137
#   Scan for all possible items
138
#
139
my @item_paths;
140
foreach my $path ( @etool_path )
141
{
142
    Verbose2 ("Scanning: $path");
143
 
144
    foreach my $prefix ( 'jats_', '' )
145
    {
146
        foreach my $suffix ( '.pl', '.pod', '' )
147
        {
148
            my $item = $path . '/' . $prefix . $uitem . $suffix;
149
            push @item_paths, $item if ( -f $item );
150
        }
151
    }
152
}
153
 
154
#
155
#   If no topics are found, then prod the user
156
#
157
Error ("No matching help topic found for : $uitem",
158
       "Use 'jats help' to provide a list of available topics"
159
        )unless ( @item_paths );
160
 
161
#
162
#   Process the required items
315 dpurdie 163
#       Programs - show help based on opt_help
164
#       Pods     - show it all
313 dpurdie 165
#
166
Verbose ( "Items", @item_paths  );
167
foreach my $item ( @item_paths )
168
{
169
    pod2usage(-input   => $item,
315 dpurdie 170
              -verbose => ($item =~ m{\.pod$}) ? 3 : $opt_help,
313 dpurdie 171
              -exitval => 'noexit' );
172
}
173
exit (0);
174
 
175
#-------------------------------------------------------------------------------
176
# Function        : display_help_items
177
#
178
# Description     : Create and display a list of help items
179
#                   This will be created based on the search path
180
#
181
#                   Append a (*) to programs that don't have any POD
182
#                   Should serve as a hint to add some helpful help
183
#
184
# Inputs          : prefix
185
#                   header
186
#                   List of files to match
187
#
188
# Returns         : Does not return
189
#
190
 
191
sub display_help_items
192
{
193
    my ($prefix, $header, @ext_list) = @_;
194
 
195
    #
196
    #   Display a list of commands
197
    #
198
    my %list;
199
    foreach my $path ( @etool_path )
200
    {
201
        Verbose2 ("Scanning: $path");
202
        foreach my $ext ( @ext_list )
203
        {
204
            foreach my $file (  glob( "$path/$ext") )
205
            {
206
                my $pod = contains_pod ($file, 0 );
207
                unless ( $opt_verbose )
208
                {
209
                    $file =~ s~.*/~~;
210
                    $file =~ s~\.pl$~~;
211
                    $file =~ s~\.pod$~~;
212
                    $file =~ s~^jats_~~;
213
                    if ( exists $subst{$file} )
214
                    {
215
                        $file = $subst{$file};
216
                        next unless ( $file );
217
                    }
218
                }
219
                $file .= ' *' unless ( $pod );
220
                $list{$file} = 1;
221
            }
222
        }
223
    }
224
 
225
    my $count = 0;
226
    my $limit = $opt_verbose ? 1 : 3;
227
    print "${prefix}Available Help $header\n", '-' x 80;
228
    foreach ( sort keys %list )
229
    {
230
        print "\n  " if ( !( $count++ % $limit) );
231
        printf "%-26s", $_;
232
    }
233
    print "\n";
234
#    print "\n",'-' x 80, "\n";
235
}
236
 
237
#-------------------------------------------------------------------------------
238
#   Documentation
239
#
240
 
241
=pod
242
 
243
=head1 NAME
244
 
245
help - Display help from the various JATS utilities
246
 
247
=head1 SYNOPSIS
248
 
249
 Usage: jats help [opts] topic
250
 
251
 Where opts:
252
    -h, -h=[n], -man=[n]    - Help messages with increasing verbosity
253
    -verbose[=n]            - Verbose operation
254
    -all                    - Also search to internal directories
255
 
256
 Where topic is one of:
257
    A help item             - Documentation on a specific aspect of JATS
258
    A JATS command          - Commands with built in help
259
 
260
=head1 OPTIONS
261
 
262
=over 8
263
 
264
=item B<-help>
265
 
266
Print a brief help message and exits.
267
 
268
=item B<-help -help>
269
 
270
Print a detailed help message with an explanation for each option.
271
 
272
=item B<-man>
273
 
274
Prints the manual page and exits.
275
 
276
=item B<-verbose[=n]>
277
 
278
This option will increase the level of verbosity of the JATS command.
279
 
280
If an argument is provided, then it will be used to set the level, otherwise the
281
existing level will be incremented. This option may be specified multiple times.
282
 
283
=item B<-all>
284
 
285
This option will extend the directories that the help utility will scan for
286
programs and documentation files to include several internal directories.
287
 
288
=back
289
 
290
=head1 DESCRIPTION
291
 
292
This program will display help information from the various JATS utility
293
programs.
294
 
295
Without any options the program will display a list of available commands with
296
built-in help and specialised items.
297
 
298
Commands may be flagged with with a '*' to indicate that the command does not
299
have any built-in help. This serves as an indication that the command needs to
300
be documented.
301
 
302
=cut
303