ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/CommandLineInterface.pm
Revision: 1.1
Committed: Thu Sep 2 12:33:50 1999 UTC (25 years, 8 months ago) by williamc
Content type: text/plain
Branch: MAIN
Log Message:
Option Parser Set and tested

File Contents

# Content
1 #
2 # CommandLineInterface.pm
3 #
4 # Originally Written by Christopher Williams
5 #
6 # Description
7 # Do all the setting up required for the InputQuery based on an input hash
8 # --- defaults taken from activedoc configuration setup
9 #
10 # Interface
11 # ---------
12 # new(UserInterface) : A new CommandLineInterface object
13 # define userinterface for any CL querys
14 # parseoptions(optionhashref, @args) : parse the options, setting the UserQuery
15 # appropriately as indicated by optionhash
16 # The option hash ref should have the
17 # format as given in example below
18 # $ohr={
19 # '-I'=> [ qw(dir >>) ],
20 # '-g'=> [ qw(debug true) ] }
21 # ( >> means take next argument as value)
22
23 package ActiveDoc::CommandLineInterface;
24 use ActiveDoc::UserQuery;
25 require 5.001;
26
27 sub new {
28 my $class=shift;
29 $self={};
30 bless $self, $class;
31 $self->init(@_);
32 return $self;
33 }
34
35 # --------------- Support Routines --------------------
36 sub init {
37 my $self=shift;
38 my $UI=shift;
39
40 $self->{UI}=$UI;
41 $self->{InputQuery}=ActiveDoc::UserQuery->new($self->{UI});
42
43 $self->{errormessg}="Error : ";
44 }
45
46
47 sub error {
48 my $self=shift;
49 my $string=shift;
50
51 die $self->{errormessg}.$string."\n";
52 }
53
54
55 # --------------- Interface routines --------------------
56
57 sub getDOChandler {
58 my $self=shift;
59 $self->{dochandler}=ActiveDoc::DOChandler->new($self->{InputQuery});
60 return $self->{dochandler};
61 }
62
63 sub parseoptions {
64 my $self=shift;
65 my $optionhashref=shift;
66 my @args=@_;
67
68 my $option;
69
70 $option=shift @args;
71
72 while ( defined $option ) {
73 # deal with options
74 if ( $option=~/^\-/ ) {
75 if ( ! exists $$optionhashref{$option} ) {
76 $self->error("Unknown Option $option");
77 }
78 else {
79 # take next word as argument -- indicate by >
80 if ( $$optionhashref{$option}[1]=~/^\>\>/ ) {
81 $self->{InputQuery}->setparam($$optionhashref{$option}[0],
82 (shift @args));
83 }
84 else { # simply set value as in hashref
85 $self->{InputQuery}->setparam($$optionhashref{$option}[0],
86 $$optionhashref{$option}[1]);
87 }
88 }
89 }
90 else { # deal with commands
91 unshift @args, $option;
92 last;
93 }
94 $option=shift @args;
95 } # end while
96 }
97