9 =head1 NAME $RCSfile: cqaction.pl,v $
13 This script attempt to apply an action to a statefull Clearquest record.
21 Andrew DeFaria <Andrew@ClearSCM.com>
29 Mon Jul 30 12:05:45 PDT 2012
33 $Date: 2012/12/18 19:44:10 $
39 Usage: cqaction.pl [-u|sage] [-v|erbose] [-d|ebug]
40 [-username <username>] [-password <password>]
41 [-database <dbname>] [-dbset <dbset>]
42 [-record <record>] [-key <key>]
44 [-module] [-server <server>] [-port <port>]
48 -u|sage: Displays usage
50 -de|bug: Output debug messages
52 -record: Record to apply the action to (Default: Defect)
53 -key: Key to locate the record with (Note that if you supply simply
54 a number (e.g. 1234) then we will expand that with leading
55 zeroes to the length of 8 digits and prepend the database name)
56 -action: Action to apply (Default: Modify)
58 -use|rname: Username to open database with (Default: from config file)
59 -p|assword: Password to open database with (Default: from config file)
60 -da|tabase: Database to open (Default: from config file)
61 -db|set: Database Set to use (Default: from config file)
62 -m|odule: Type of Clearquest module to use. Must be one of 'api',
63 'client', or 'rest'. The 'api' module can only be used if
64 Clearquest is installed locally. The 'client' module can
65 only be successful if a corresponding server is running. And
66 the 'rest' module can only be used if a CQ Web server has
67 been set up and configured (Default: rest)
68 -s|erver: For module = client or rest this is the name of the server
69 that will be providing the service
70 -p|ort: For module = client, this is the point on the server to talk
75 Options are keep in the cq.conf file in etc. They specify the default options
76 listed below. Or you can export the option name to the env(1) to override the
77 defaults in cq.conf. Finally you can programmatically set the options when you
78 call new by passing in a %parms hash. To specify the %parms hash key remove the
79 CQ_ portion and lc the rest.
81 =for html <blockquote>
87 The web host to contact with leading http://
91 Name of database to connect to (Default: from config file)
95 User name to connect as (Default: from config file)
99 Password for CQ_USERNAME
103 Database Set name (Default: from config file)
107 Clearquest::Server name to connect to (Default: from config file)
111 Clearquest::Server port to connect to (Default: from config file)
115 =head1 Modifying fields while changing state
117 If you need to modify fields while changing state then feed them to this
118 script's stdin in the form of:
122 B<Note:> Don't forget that you will be prompted field=value and you'll need
123 to signal that you have entered all of the field/value pairs you intended with
124 Ctrl-D (or Ctrl-Z on Windows). You can short circut this by feeding something
125 like /dev/null to stdin like so:
127 $ cat /dev/null > cqaction.pl <parms>
134 use lib "$FindBin::Bin/../lib";
144 verbose "Enter <field>=<value> pairs and Ctrl-D to end input";
147 if (/^(\s+)(=|:)(\.*)/) {
152 verbose "All <field>=<value> pairs accepted";
157 $opts{module} = 'rest';
161 usage => sub { Usage },
162 verbose => sub { set_verbose },
163 debug => sub { set_debug },
176 Usage "You must specify -key" unless $opts{key};
179 my $record = delete $opts{record} || 'Defect';
180 my $key = delete $opts{key};
181 my $action = delete $opts{action} || 'Modify';
183 # Translate any options to ones that the lib understands
184 $opts{CQ_USERNAME} = delete $opts{username};
185 $opts{CQ_PASSWORD} = delete $opts{password};
186 $opts{CQ_DATABASE} = delete $opts{database};
187 $opts{CQ_DBSET} = delete $opts{dbset};
188 $opts{CQ_SERVER} = delete $opts{server};
189 $opts{CQ_PORT} = delete $opts{port};
193 my $module = lc delete $opts{module};
195 if ($module eq 'rest') {
196 require Clearquest::REST;
198 $cq = Clearquest::REST->new (%opts);
199 } elsif ($module eq 'client') {
200 require Clearquest::Client;
202 $cq = Clearquest::Client->new (%opts);
205 } elsif ($module eq 'api') {
208 $cq = Clearquest->new (%opts);
212 Usage "Invalid module - $opts{module}";
215 # Fix key if necessary
216 if ($key =~ /^(\d+)$/) {
217 $key = $cq->{database} . 0 x (8 - length $1) . $1;
220 my %values = getFields;
222 my $errmsg = $cq->modify ($record, $key, $action, %values);
224 unless ($cq->cqerror) {
225 verbose "Successfully applied $action to $record:$key";
229 error "Unable to apply $action to $record:$key\n" . $cq->cqerrmsg, $cq->cqerror;