2 # BEGIN BPS TAGGED BLOCK {{{
6 # This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
7 # <sales@bestpractical.com>
9 # (Except where explicitly superseded by other copyright notices)
14 # This work is made available to you under the terms of Version 2 of
15 # the GNU General Public License. A copy of that license should have
16 # been provided with this software, but in any event can be snarfed
19 # This work is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 # 02110-1301 or visit their web page on the internet at
28 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
31 # CONTRIBUTION SUBMISSION POLICY:
33 # (The following paragraph is not intended to limit the rights granted
34 # to you to modify and distribute this software under the terms of
35 # the GNU General Public License and is only of importance to you if
36 # you choose to contribute your changes and enhancements to the
37 # community by submitting them to Best Practical Solutions, LLC.)
39 # By intentionally submitting any modifications, corrections or
40 # derivatives to this work, or any other work intended for use with
41 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
42 # you are the copyright holder for those contributions and you grant
43 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
44 # royalty-free, perpetual, license to use, copy, create derivative
45 # works based on those contributions, and sublicense and distribute
46 # those contributions and any derivatives thereof.
48 # END BPS TAGGED BLOCK }}}
49 # Designed and implemented for Best Practical Solutions, LLC by
50 # Abhijit Menon-Sen <ams@wiw.org>
54 if ( $ARGV[0] && $ARGV[0] =~ /^(?:--help|-h)$/ ) {
56 print Pod::Usage::pod2usage( { verbose => 2 } );
60 # This program is intentionally written to have as few non-core module
61 # dependencies as possible. It should stay that way.
66 use HTTP::Request::Common;
69 use Time::Local; # used in prettyshow
71 # strong (GSSAPI based) authentication is supported if the server does provide
72 # it and the perl modules GSSAPI and LWP::Authen::Negotiate are installed
73 # it can be suppressed by setting externalauth=0 (default is undef)
74 eval { require GSSAPI };
75 my $no_strong_auth = 'missing perl module GSSAPI';
77 eval {require LWP::Authen::Negotiate};
78 $no_strong_auth = $@ ? 'missing perl module LWP::Authen::Negotiate' : 0;
81 # We derive configuration information from hardwired defaults, dotfiles,
82 # and the RT* environment variables (in increasing order of precedence).
83 # Session information is stored in ~/.rt_sessions.
86 my $HOME = eval{(getpwuid($<))[7]}
87 || $ENV{HOME} || $ENV{LOGDIR} || $ENV{HOMEPATH}
92 user => eval{(getpwuid($<))[0]} || $ENV{USER} || $ENV{USERNAME},
94 server => 'http://localhost/',
95 query => "Status!='resolved' and Status!='rejected'",
98 # to protect against unlimited searches a better choice would be
99 # queue => 'Unknown_Queue',
100 # setting externalauth => undef will try GSSAPI auth if the corresponding perl
101 # modules are installed, externalauth => 0 is the backward compatible choice
104 config_from_file($ENV{RTCONFIG} || ".rtrc"),
107 my $session = Session->new("$HOME/.rt_sessions");
108 my $REST = "$config{server}/REST/1.0";
109 $no_strong_auth = 'switched off by externalauth=0'
110 if defined $config{externalauth};
116 sub DEBUG { warn @_ if $config{debug} >= shift }
118 # These regexes are used by command handlers to parse arguments.
119 # (XXX: Ask Autrijus how i18n changes these definitions.)
121 my $name = '[\w.-]+';
122 my $CF_name = '[\sa-z0-9_ :()/-]+';
123 my $field = '(?i:[a-z][a-z0-9_-]*|C(?:ustom)?F(?:ield)?-'.$CF_name.'|CF\.\{'.$CF_name.'\})';
124 my $label = '[a-zA-Z0-9@_.+-]+';
125 my $labels = "(?:$label,)*$label";
126 my $idlist = '(?:(?:\d+-)?\d+,)*(?:\d+-)?\d+';
128 # Our command line looks like this:
130 # rt <action> [options] [arguments]
132 # We'll parse just enough of it to decide upon an action to perform, and
133 # leave the rest to per-action handlers to interpret appropriately.
136 # handler => [ ...aliases... ],
137 version => ["version", "ver"],
139 logout => ["logout"],
140 help => ["help", "man"],
141 show => ["show", "cat"],
142 edit => ["create", "edit", "new", "ed"],
143 list => ["search", "list", "ls"],
144 comment => ["comment", "correspond"],
145 link => ["link", "ln"],
147 grant => ["grant", "revoke"],
148 take => ["take", "steal", "untake"],
149 quit => ["quit", "exit"],
150 setcommand => ["del", "delete", "give", "res", "resolve",
155 foreach my $fn (keys %handlers) {
156 foreach my $alias (@{ $handlers{$fn} }) {
157 $actions{$alias} = \&{"$fn"};
161 # Once we find and call an appropriate handler, we're done.
166 push @ARGV, 'shell' if (!@ARGV); # default to shell mode
167 shift @ARGV if ($ARGV[0] eq 'rt'); # ignore a leading 'rt'
168 if (@ARGV && exists $actions{$ARGV[0]}) {
169 $action = shift @ARGV;
170 return $actions{$action}->($action);
173 print STDERR "rt: Unknown command '@ARGV'.\n";
174 print STDERR "rt: For help, run 'rt help'.\n";
184 # The following subs are handlers for each entry in %actions.
188 my $term = Term::ReadLine->new('RT CLI');
189 while ( defined ($_ = $term->readline($prompt)) ) {
190 next if /^#/ || /^\s*$/;
192 @ARGV = shellwords($_);
198 print "rt $VERSION\n";
203 submit("$REST/logout") if defined $session->cookie;
214 my ($action, $type, $rv) = @_;
215 $rv = defined $rv ? $rv : 0;
218 # What help topics do we know about?
221 foreach my $item (@{ Form::parse(<DATA>) }) {
222 my $title = $item->[2]{Title};
223 my @titles = ref $title eq 'ARRAY' ? @$title : $title;
225 foreach $title (grep $_, @titles) {
226 $help{$title} = $item->[2]{Text};
231 # What does the user want help with?
232 undef $action if ($action && $actions{$action} eq \&help);
233 unless ($action || $type) {
234 # If we don't know, we'll look for clues in @ARGV.
236 if (exists $help{$_}) { $key = $_; last; }
239 # Tolerate possibly plural words.
241 if ($_ =~ s/s$// && exists $help{$_}) { $key = $_; last; }
246 if ($type && $action) {
247 $key = "$type.$action";
249 $key ||= $type || $action || "introduction";
251 # Find a suitable topic to display.
252 while (!exists $help{$key}) {
253 if ($type && $action) {
254 if ($key eq "$type.$action") { $key = $action; }
255 elsif ($key eq $action) { $key = $type; }
256 else { $key = "introduction"; }
259 $key = "introduction";
263 print STDERR $help{$key}, "\n\n";
267 # Displays a list of objects that match some specified condition.
270 my ($q, $type, %data);
271 my $orderby = $config{orderby};
273 if ($config{orderby}) {
274 $data{orderby} = $config{orderby};
278 my $reverse_sort = 0;
279 my $queue = $config{queue};
285 $bad = 1, last unless defined($type = get_type_argument());
288 $bad = 1, last unless get_var_argument(\%data);
291 $data{'orderby'} = shift @ARGV;
293 elsif (/^-([isl])$/) {
298 $queue = shift @ARGV;
304 if ($ARGV[0] !~ /^(?:(?:$field,)*$field)$/) {
305 whine "No valid field list in '-f $ARGV[0]'.";
308 $data{fields} = shift @ARGV;
309 $data{format} = 's' if ! $data{format};
312 elsif (!defined $q && !/^-/) {
316 my $datum = /^-/ ? "option" : "argument";
317 whine "Unrecognised $datum '$_'.";
321 if ( ! $rawprint and ! exists $data{format} ) {
324 if ( $reverse_sort and $data{orderby} =~ /^-/ ) {
325 $data{orderby} =~ s/^-/+/;
326 } elsif ($reverse_sort) {
327 $data{orderby} =~ s/^\+?(.*)/-$1/;
334 $q =~ s/^#//; # get rid of leading hash
336 # only digits, must be an id, formulate a correct query
337 $q = "id=$q" if $q =~ /^\d+$/;
339 # a string only, take it as an owner or requestor (quoting done later)
340 $q = "(Owner=$q or Requestor like $q) and $config{query}"
341 if $q =~ /^[\w\-]+$/;
342 # always add a query for a specific queue or (comma separated) queues
343 $queue =~ s/,/ or Queue=/g if $queue;
344 $q .= " and (Queue=$queue)" if $queue and $q and $q !~ /Queue\s*=/i
347 # correctly quote strings in a query
348 $q =~ s/(=|like\s)\s*([^'\d\s]\S*)\b/$1\'$2\'/g;
351 unless ($type && defined $q) {
352 my $item = $type ? "query string" : "object type";
353 whine "No $item specified.";
356 #return help("list", $type) if $bad;
357 return suggest_help("list", $type, $bad) if $bad;
359 print "Query:$q\n" if ! $rawprint;
360 my $r = submit("$REST/search/$type", { query => $q, %data });
364 my $forms = Form::parse($r->content);
370 # Displays selected information about a single object.
373 my ($type, @objects, %data);
381 s/^#// if /^#\d+/; # get rid of leading hash
383 $bad = 1, last unless defined($type = get_type_argument());
386 $bad = 1, last unless get_var_argument(\%data);
388 elsif (/^-([isl])$/) {
392 elsif (/^-$/ && !$slurped) {
393 chomp(my @lines = <STDIN>);
395 unless (is_object_spec($_, $type)) {
396 whine "Invalid object on STDIN: '$_'.";
404 if ($ARGV[0] !~ /^(?:(?:$field,)*$field)$/) {
405 whine "No valid field list in '-f $ARGV[0]'.";
408 $data{fields} = shift @ARGV;
409 # option f requires short raw listing format
413 elsif (/^\d+$/ and my $spc2 = is_object_spec("ticket/$_", $type)) {
414 push @objects, $spc2;
415 $histspec = is_object_spec("ticket/$_/history", $type);
417 elsif (/^\d+\// and my $spc3 = is_object_spec("ticket/$_", $type)) {
418 push @objects, $spc3;
419 $rawprint = 1 if $_ =~ /\/content$/;
421 elsif (my $spec = is_object_spec($_, $type)) {
422 push @objects, $spec;
423 $rawprint = 1 if $_ =~ /\/content$/ or $_ !~ /^ticket/;
426 my $datum = /^-/ ? "option" : "argument";
427 whine "Unrecognised $datum '$_'.";
432 push @objects, $histspec if $histspec;
433 $data{format} = 'l' if ! exists $data{format};
437 whine "No objects specified.";
440 #return help("show", $type) if $bad;
441 return suggest_help("show", $type, $bad) if $bad;
443 my $r = submit("$REST/show", { id => \@objects, %data });
445 # if this isn't a text reply, remove the trailing newline so we
446 # don't corrupt things like tarballs when people do
447 # show ticket/id/attachments/id/content > foo.tar.gz
448 if ($r->content_type !~ /^text\//) {
455 # I do not know how to get more than one form correctly returned
456 $c =~ s!^RT/[\d\.]+ 200 Ok$!--!mg;
457 my $forms = Form::parse($c);
463 # To create a new object, we ask the server for a form with the defaults
464 # filled in, allow the user to edit it, and send the form back.
466 # To edit an object, we must ask the server for a form representing that
467 # object, make changes requested by the user (either on the command line
468 # or interactively via $EDITOR), and send the form back.
472 my (%data, $type, @objects);
473 my ($cl, $text, $edit, $input, $output);
475 use vars qw(%set %add %del);
476 %set = %add = %del = ();
482 s/^#// if /^#\d+/; # get rid of leading hash
484 if (/^-e$/) { $edit = 1 }
485 elsif (/^-i$/) { $input = 1 }
486 elsif (/^-o$/) { $output = 1 }
488 $bad = 1, last unless defined($type = get_type_argument());
491 $bad = 1, last unless get_var_argument(\%data);
493 elsif (/^-$/ && !($slurped || $input)) {
494 chomp(my @lines = <STDIN>);
496 unless (is_object_spec($_, $type)) {
497 whine "Invalid object on STDIN: '$_'.";
507 while (@ARGV && $ARGV[0] =~ /^($field)([+-]?=)(.*)$/s) {
508 my ($key, $op, $val) = ($1, $2, $3);
509 my $hash = ($op eq '=') ? \%set : ($op =~ /^\+/) ? \%add : \%del;
511 vpush($hash, lc $key, $val);
516 whine "No variables to set.";
521 elsif (/^(?:add|del)$/i) {
523 my $hash = ($_ eq "add") ? \%add : \%del;
525 while (@ARGV && $ARGV[0] =~ /^($field)=(.*)$/s) {
526 my ($key, $val) = ($1, $2);
528 vpush($hash, lc $key, $val);
533 whine "No variables to set.";
538 elsif (/^\d+$/ and my $spc2 = is_object_spec("ticket/$_", $type)) {
539 push @objects, $spc2;
541 elsif (my $spec = is_object_spec($_, $type)) {
542 push @objects, $spec;
545 my $datum = /^-/ ? "option" : "argument";
546 whine "Unrecognised $datum '$_'.";
551 if ($action =~ /^ed(?:it)?$/) {
553 whine "No objects specified.";
559 whine "You shouldn't specify objects as arguments to $action.";
563 whine "What type of object do you want to create?";
566 @objects = ("$type/new") if defined($type);
568 #return help($action, $type) if $bad;
569 return suggest_help($action, $type, $bad) if $bad;
571 # We need a form to make changes to. We usually ask the server for
572 # one, but we can avoid that if we are fed one on STDIN, or if the
573 # user doesn't want to edit the form by hand, and the command line
574 # specifies only simple variable assignments. We *should* get a
575 # form if we're creating a new ticket, so that the default values
576 # get filled in properly.
578 my @new_objects = grep /\/new$/, @objects;
584 elsif ($edit || %add || %del || !$cl || @new_objects) {
585 my $r = submit("$REST/show", { id => \@objects, format => 'l' });
589 # If any changes were specified on the command line, apply them.
592 # We're updating forms from the server.
593 my $forms = Form::parse($text);
595 foreach my $form (@$forms) {
596 my ($c, $o, $k, $e) = @$form;
599 next if ($e || !@$o);
605 # Make changes to existing fields.
607 if (exists $add{lc $key}) {
608 $val = delete $add{lc $key};
609 vpush($k, $key, $val);
610 $k->{$key} = vsplit($k->{$key}) if $val =~ /[,\n]/;
612 if (exists $del{lc $key}) {
613 $val = delete $del{lc $key};
614 my %val = map {$_=>1} @{ vsplit($val) };
615 $k->{$key} = vsplit($k->{$key});
616 @{$k->{$key}} = grep {!exists $val{$_}} @{$k->{$key}};
618 if (exists $set{lc $key}) {
619 $k->{$key} = delete $set{lc $key};
623 # Then update the others.
624 foreach $key (keys %set) { vpush($k, $key, $set{$key}) }
625 foreach $key (keys %add) {
626 vpush($k, $key, $add{$key});
627 $k->{$key} = vsplit($k->{$key});
629 push @$o, (keys %add, keys %set);
632 $text = Form::compose($forms);
635 # We're rolling our own set of forms.
638 my ($type, $ids, $args) =
639 m{^($name)/($idlist|$labels)(?:(/.*))?$}o;
642 foreach my $obj (expand_list($ids)) {
643 my %set = (%set, id => "$type/$obj$args");
644 push @forms, ["", [keys %set], \%set];
647 $text = Form::compose(\@forms);
659 # We'll let the user edit the form before sending it to the server,
660 # unless we have enough information to submit it non-interactively.
661 if ($edit || (!$input && !$cl)) {
662 my $newtext = vi($text);
663 # We won't resubmit a bad form unless it was changed.
664 $text = ($synerr && $newtext eq $text) ? undef : $newtext;
668 my $r = submit("$REST/edit", {content => $text, %data});
669 if ($r->code == 409) {
670 # If we submitted a bad form, we'll give the user a chance
671 # to correct it and resubmit.
672 if ($edit || (!$input && !$cl)) {
687 # handler for special edit commands. A valid edit command is constructed and
688 # further work is delegated to the edit handler
692 my ($id, $bad, $what);
695 $id = $1 if (m|^(?:ticket/)?($idlist)$|);
699 whine "No ticket number specified.";
702 if ($action eq 'subject') {
703 my $subject = '"'.join (" ", @ARGV).'"';
705 $what = "subject=$subject";
706 } elsif ($action eq 'give') {
707 my $owner = shift @ARGV;
708 $what = "owner=$owner";
711 if ( $action eq 'delete' or $action eq 'del' ) {
712 $what = "status=deleted";
713 } elsif ($action eq 'resolve' or $action eq 'res' ) {
714 $what = "status=resolved";
715 } elsif ($action eq 'take' ) {
716 $what = "owner=$config{user}";
717 } elsif ($action eq 'untake') {
718 $what = "owner=Nobody";
723 whine "Extraneous arguments for action $action: @ARGV.";
727 whine "unrecognized action $action.";
729 return help("edit", undef, $bad) if $bad;
730 @ARGV = ( $id, "set", $what );
731 print "Executing: rt edit @ARGV\n";
735 # We roll "comment" and "correspond" into the same handler.
739 my (%data, $id, @files, @bcc, @cc, $msg, $wtime, $edit);
748 elsif (/^-[abcmw]$/) {
750 whine "No argument specified with $_.";
755 unless (-f $ARGV[0] && -r $ARGV[0]) {
756 whine "Cannot read attachment: '$ARGV[0]'.";
759 push @files, shift @ARGV;
762 my $a = $_ eq "-b" ? \@bcc : \@cc;
763 @$a = split /\s*,\s*/, shift @ARGV;
767 if ( $msg =~ /^-$/ ) {
769 while (<STDIN>) { $msg .= $_ }
773 elsif (/-w/) { $wtime = shift @ARGV }
775 elsif (!$id && m|^(?:ticket/)?($idlist)$|) {
779 my $datum = /^-/ ? "option" : "argument";
780 whine "Unrecognised $datum '$_'.";
786 whine "No object specified.";
789 #return help($action, "ticket") if $bad;
790 return suggest_help($action, "ticket") if $bad;
794 [ "Ticket", "Action", "Cc", "Bcc", "Attachment", "TimeWorked", "Text" ],
800 Attachment => [ @files ],
801 TimeWorked => $wtime || '',
807 my $text = Form::compose([ $form ]);
809 if ($edit || !$msg) {
814 my $ntext = vi($text);
815 return if ($error && $ntext eq $text);
817 $form = Form::parse($text);
820 ($c, $o, $k, $e) = @{ $form->[0] };
823 $c = "# Syntax error.";
829 @files = @{ vsplit($k->{Attachment}) };
832 $text = Form::compose([[$c, $o, $k, $e]]);
837 foreach my $file (@files) {
838 $data{"attachment_$i"} = bless([ $file ], "Attachment");
841 $data{content} = $text;
843 my $r = submit("$REST/ticket/$id/comment", \%data);
848 # Merge one ticket into another.
856 s/^#// if /^#\d+/; # get rid of leading hash
862 whine "Unrecognised argument: '$_'.";
868 my $evil = @id > 2 ? "many" : "few";
869 whine "Too $evil arguments specified.";
872 #return help("merge", "ticket") if $bad;
873 return suggest_help("merge", "ticket", $bad) if $bad;
875 my $r = submit("$REST/ticket/$id[0]/merge/$id[1]");
880 # Link one ticket to another.
883 my ($bad, $del, %data) = (0, 0, ());
886 my %ltypes = map { lc $_ => $_ } qw(DependsOn DependedOnBy RefersTo
887 ReferredToBy HasMember MemberOf);
889 while (@ARGV && $ARGV[0] =~ /^-/) {
896 $bad = 1, last unless defined($type = get_type_argument());
899 whine "Unrecognised option: '$_'.";
904 $type = "ticket" unless $type; # default type to tickets
907 my ($from, $rel, $to) = @ARGV;
908 if ($from !~ /^\d+$/ || $to !~ /^\d+$/) {
909 my $bad = $from =~ /^\d+$/ ? $to : $from;
910 whine "Invalid $type ID '$bad' specified.";
913 if (($type eq "ticket") && ( ! exists $ltypes{lc $rel})) {
914 whine "Invalid link '$rel' for type $type specified.";
917 %data = (id => $from, rel => $rel, to => $to, del => $del);
920 my $bad = @ARGV < 3 ? "few" : "many";
921 whine "Too $bad arguments specified.";
924 return suggest_help("link", $type, $bad) if $bad;
926 my $r = submit("$REST/$type/link", \%data);
931 # Take/steal a ticket
934 my ($bad, %data) = (0, ());
941 unless ($id =~ /^\d+$/) {
942 whine "Invalid ticket ID $id specified.";
947 [ "Ticket", "Action" ],
955 my $text = Form::compose([ $form ]);
956 $data{content} = $text;
959 $bad = @ARGV < 1 ? "few" : "many";
960 whine "Too $bad arguments specified.";
963 return suggest_help("take", "ticket", $bad) if $bad;
965 my $r = submit("$REST/ticket/$id/take", \%data);
970 # Grant/revoke a user's rights.
979 $revoke = 1 if $cmd->{action} eq 'revoke';
983 # Client <-> Server communication.
984 # --------------------------------
986 # This function composes and sends an HTTP request to the RT server, and
987 # interprets the response. It takes a request URI, and optional request
988 # data (a string, or a reference to a set of key-value pairs).
991 my ($uri, $content) = @_;
993 my $ua = LWP::UserAgent->new(agent => "RT/3.0b", env_proxy => 1);
994 my $h = HTTP::Headers->new;
996 # Did the caller specify any data to send with the request?
998 if (defined $content) {
999 unless (ref $content) {
1000 # If it's just a string, make sure LWP handles it properly.
1001 # (By pretending that it's a file!)
1002 $content = [ content => [undef, "", Content => $content] ];
1004 elsif (ref $content eq 'HASH') {
1006 foreach my $k (keys %$content) {
1007 if (ref $content->{$k} eq 'ARRAY') {
1008 foreach my $v (@{ $content->{$k} }) {
1012 else { push @data, $k, $content->{$k} }
1019 # Should we send authentication information to start a new session?
1020 my $how = $config{server} =~ /^https/ ? 'over SSL' : 'unencrypted';
1021 (my $server = $config{server}) =~ s/^.*\/\/([^\/]+)\/?/$1/;
1022 if ($config{externalauth}) {
1023 $h->authorization_basic($config{user}, $config{passwd} || read_passwd() );
1024 print " Password will be sent to $server $how\n",
1025 " Press CTRL-C now if you do not want to continue\n"
1026 if ! $config{passwd};
1027 } elsif ( $no_strong_auth ) {
1028 if (!defined $session->cookie) {
1029 print " Strong encryption not available, $no_strong_auth\n",
1030 " Password will be sent to $server $how\n",
1031 " Press CTRL-C now if you do not want to continue\n"
1032 if ! $config{passwd};
1033 push @$data, ( user => $config{user} );
1034 push @$data, ( pass => $config{passwd} || read_passwd() );
1038 # Now, we construct the request.
1040 $req = POST($uri, $data, Content_Type => 'form-data');
1045 $session->add_cookie_header($req);
1046 if ($config{externalauth}) {
1050 # Then we send the request and parse the response.
1051 DEBUG(3, $req->as_string);
1052 my $res = $ua->request($req);
1053 DEBUG(3, $res->as_string);
1055 if ($res->is_success) {
1056 # The content of the response we get from the RT server consists
1057 # of an HTTP-like status line followed by optional header lines,
1058 # a blank line, and arbitrary text.
1060 my ($head, $text) = split /\n\n/, $res->content, 2;
1061 my ($status, @headers) = split /\n/, $head;
1062 $text =~ s/\n*$/\n/ if ($text);
1064 # "RT/3.0.1 401 Credentials required"
1065 if ($status !~ m#^RT/\d+(?:\S+) (\d+) ([\w\s]+)$#) {
1066 warn "rt: Malformed RT response from $config{server}.\n";
1067 warn "(Rerun with RTDEBUG=3 for details.)\n" if $config{debug} < 3;
1071 # Our caller can pretend that the server returned a custom HTTP
1072 # response code and message. (Doing that directly is apparently
1073 # not sufficiently portable and uncomplicated.)
1076 $res->content($text);
1077 $session->update($res) if ($res->is_success || $res->code != 401);
1079 if (!$res->is_success) {
1080 # We can deal with authentication failures ourselves. Either
1081 # we sent invalid credentials, or our session has expired.
1082 if ($res->code == 401) {
1084 if (exists $d{user}) {
1085 warn "rt: Incorrect username or password.\n";
1088 elsif ($req->header("Cookie")) {
1089 # We'll retry the request with credentials, unless
1090 # we only wanted to logout in the first place.
1092 return submit(@_) unless $uri eq "$REST/logout";
1095 # Conflicts should be dealt with by the handler and user.
1096 # For anything else, we just die.
1097 elsif ($res->code != 409) {
1098 warn "rt: ", $res->content;
1104 warn "rt: Server error: ", $res->message, " (", $res->code, ")\n";
1111 # Session management.
1112 # -------------------
1114 # Maintains a list of active sessions in the ~/.rt_sessions file.
1119 # Initialises the session cache.
1121 my ($class, $file) = @_;
1123 file => $file || "$HOME/.rt_sessions",
1127 # The current session is identified by the currently configured
1129 ($s, $u) = @config{"server", "user"};
1131 bless $self, $class;
1137 # Returns the current session cookie.
1140 my $cookie = $self->{sids}{$s}{$u};
1141 return defined $cookie ? "RT_SID_$cookie" : undef;
1144 # Deletes the current session cookie.
1147 delete $self->{sids}{$s}{$u};
1150 # Adds a Cookie header to an outgoing HTTP request.
1151 sub add_cookie_header {
1152 my ($self, $request) = @_;
1153 my $cookie = $self->cookie();
1155 $request->header(Cookie => $cookie) if defined $cookie;
1158 # Extracts the Set-Cookie header from an HTTP response, and updates
1159 # session information accordingly.
1161 my ($self, $response) = @_;
1162 my $cookie = $response->header("Set-Cookie");
1164 if (defined $cookie && $cookie =~ /^RT_SID_(.[^;,\s]+=[0-9A-Fa-f]+);/) {
1165 $self->{sids}{$s}{$u} = $1;
1169 # Loads the session cache from the specified file.
1171 my ($self, $file) = @_;
1172 $file ||= $self->{file};
1174 open( my $handle, '<', $file ) or return 0;
1176 $self->{file} = $file;
1177 my $sids = $self->{sids} = {};
1180 next if /^$/ || /^#/;
1181 next unless m#^https?://[^ ]+ \w+ [^;,\s]+=[0-9A-Fa-f]+$#;
1182 my ($server, $user, $cookie) = split / /, $_;
1183 $sids->{$server}{$user} = $cookie;
1188 # Writes the current session cache to the specified file.
1190 my ($self, $file) = shift;
1191 $file ||= $self->{file};
1193 open( my $handle, '>', "$file" ) or return 0;
1195 my $sids = $self->{sids};
1196 foreach my $server (keys %$sids) {
1197 foreach my $user (keys %{ $sids->{$server} }) {
1198 my $sid = $sids->{$server}{$user};
1200 print $handle "$server $user $sid\n";
1218 # Forms are RFC822-style sets of (field, value) specifications with some
1219 # initial comments and interspersed blank lines allowed for convenience.
1220 # Sets of forms are separated by --\n (in a cheap parody of MIME).
1222 # Each form is parsed into an array with four elements: commented text
1223 # at the start of the form, an array with the order of keys, a hash with
1224 # key/value pairs, and optional error text if the form syntax was wrong.
1226 # Returns a reference to an array of parsed forms.
1230 my @lines = split /\n/, $_[0] if $_[0];
1231 my ($c, $o, $k, $e) = ("", [], {}, "");
1235 my $line = shift @lines;
1237 next LINE if $line eq '';
1239 if ($line eq '--') {
1240 # We reached the end of one form. We'll ignore it if it was
1241 # empty, and store it otherwise, errors and all.
1242 if ($e || $c || @$o) {
1243 push @forms, [ $c, $o, $k, $e ];
1244 $c = ""; $o = []; $k = {}; $e = "";
1248 elsif ($state != -1) {
1249 if ($state == 0 && $line =~ /^#/) {
1250 # Read an optional block of comments (only) at the start
1254 while (@lines && $lines[0] =~ /^#/) {
1255 $c .= "\n".shift @lines;
1259 elsif ($state <= 1 && $line =~ /^($field):(?:\s+(.*))?$/) {
1260 # Read a field: value specification.
1264 # Read continuation lines, if any.
1265 while (@lines && ($lines[0] eq '' || $lines[0] =~ /^\s+/)) {
1266 push @v, shift @lines;
1268 pop @v while (@v && $v[-1] eq '');
1270 # Strip longest common leading indent from text.
1272 foreach my $ls (map {/^(\s+)/} @v[1..$#v]) {
1273 $ws = $ls if (!$ws || length($ls) < length($ws));
1275 s/^$ws// foreach @v;
1277 push(@$o, $f) unless exists $k->{$f};
1278 vpush($k, $f, join("\n", @v));
1282 elsif ($line !~ /^#/) {
1283 # We've found a syntax error, so we'll reconstruct the
1284 # form parsed thus far, and add an error marker. (>>)
1286 $e = Form::compose([[ "", $o, $k, "" ]]);
1287 $e.= $line =~ /^>>/ ? "$line\n" : ">> $line\n";
1291 # We saw a syntax error earlier, so we'll accumulate the
1292 # contents of this form until the end.
1296 push(@forms, [ $c, $o, $k, $e ]) if ($e || $c || @$o);
1298 foreach my $l (keys %$k) {
1299 $k->{$l} = vsplit($k->{$l}) if (ref $k->{$l} eq 'ARRAY');
1305 # Returns text representing a set of forms.
1310 foreach my $form (@$forms) {
1311 my ($c, $o, $k, $e) = @$form;
1324 foreach my $key (@$o) {
1327 my @values = ref $v eq 'ARRAY' ? @$v : $v;
1329 $sp = " "x(length("$key: "));
1330 $sp = " "x4 if length($sp) > 16;
1332 foreach $v (@values) {
1338 push @lines, "$line\n\n";
1341 elsif (@lines && $lines[-1] !~ /\n\n$/) {
1344 push @lines, "$key: $v\n\n";
1347 length($line)+length($v)-rindex($line, "\n") >= 70)
1349 $line .= ",\n$sp$v";
1352 $line = $line ? "$line,$v" : "$key: $v";
1356 $line = "$key:" unless @values;
1358 if ($line =~ /\n/) {
1359 if (@lines && $lines[-1] !~ /\n\n$/) {
1364 push @lines, "$line\n";
1368 $text .= join "", @lines;
1376 return join "\n--\n\n", @text;
1382 # Returns configuration information from the environment.
1383 sub config_from_env {
1386 foreach my $k (qw(EXTERNALAUTH DEBUG USER PASSWD SERVER QUERY ORDERBY)) {
1388 if (exists $ENV{"RT$k"}) {
1389 $env{lc $k} = $ENV{"RT$k"};
1396 # Finds a suitable configuration file and returns information from it.
1397 sub config_from_file {
1401 # We'll use an absolute path if we were given one.
1402 return parse_config_file($rc);
1405 # Otherwise we'll use the first file we can find in the current
1406 # directory, or in one of its (increasingly distant) ancestors.
1408 my @dirs = split /\//, cwd;
1410 my $file = join('/', @dirs, $rc);
1412 return parse_config_file($file);
1415 # Remove the last directory component each time.
1419 # Still nothing? We'll fall back to some likely defaults.
1420 for ("$HOME/$rc", "local/etc/rt.conf", "/etc/rt.conf") {
1421 return parse_config_file($_) if (-r $_);
1428 # Makes a hash of the specified configuration file.
1429 sub parse_config_file {
1432 local $_; # $_ may be aliased to a constant, from line 1163
1434 open( my $handle, '<', $file ) or return;
1438 next if (/^#/ || /^\s*$/);
1440 if (/^(externalauth|user|passwd|server|query|orderby|queue)\s+(.*)\s?$/) {
1444 die "rt: $file:$.: unknown configuration directive.\n";
1455 my $sub = (caller(1))[3];
1456 $sub =~ s/^main:://;
1457 warn "rt: $sub: @_\n";
1462 eval 'require Term::ReadKey';
1464 die "No password specified (and Term::ReadKey not installed).\n";
1468 Term::ReadKey::ReadMode('noecho');
1469 chomp(my $passwd = Term::ReadKey::ReadLine(0));
1470 Term::ReadKey::ReadMode('restore');
1478 my $file = "/tmp/rt.form.$$";
1479 my $editor = $ENV{EDITOR} || $ENV{VISUAL} || "vi";
1483 open( my $handle, '>', $file ) or die "$file: $!\n";
1484 print $handle $text;
1487 system($editor, $file) && die "Couldn't run $editor.\n";
1489 open( $handle, '<', $file ) or die "$file: $!\n";
1498 # Add a value to a (possibly multi-valued) hash key.
1500 my ($hash, $key, $val) = @_;
1501 my @val = ref $val eq 'ARRAY' ? @$val : $val;
1503 if (exists $hash->{$key}) {
1504 unless (ref $hash->{$key} eq 'ARRAY') {
1505 my @v = $hash->{$key} ne '' ? $hash->{$key} : ();
1506 $hash->{$key} = \@v;
1508 push @{ $hash->{$key} }, @val;
1511 $hash->{$key} = $val;
1515 # "Normalise" a hash key that's known to be multi-valued.
1519 my @values = ref $val eq 'ARRAY' ? @$val : $val;
1521 foreach my $line (map {split /\n/} @values) {
1522 # XXX: This should become a real parser, Ã la Text::ParseWords.
1525 my ( $a, $b ) = split /\s*,\s*/, $line, 2;
1528 no warnings 'uninitialized';
1531 while ( $a !~ /'$/ || ( $a !~ /(\\\\)+'$/
1532 && $a =~ /(\\)+'$/ )) {
1533 ( $a, $b ) = split /\s*,\s*/, $b, 2;
1538 elsif ( $a =~ /^q{/ ) {
1540 while ( $a !~ /}$/ ) {
1542 split /\s*,\s*/, $b, 2;
1552 ( $a, $b ) = split /\s*,\s*/, $b, 2;
1561 # WARN: this code is duplicated in lib/RT/Interface/REST.pm
1562 # change both functions at once
1567 foreach (split /\s*,\s*/, $list) {
1568 push @elts, /^(\d+)-(\d+)$/? ($1..$2): $_;
1571 return map $_->[0], # schwartzian transform
1573 defined $a->[1] && defined $b->[1]?
1576 :!defined $a->[1] && !defined $b->[1]?
1579 # mix, number must be first
1580 :defined $a->[1]? -1: 1
1582 map [ $_, (defined( /^(\d+)$/ )? $1: undef), lc($_) ],
1586 sub get_type_argument {
1590 $type = shift @ARGV;
1591 unless ($type =~ /^[A-Za-z0-9_.-]+$/) {
1592 # We want whine to mention our caller, not us.
1593 @_ = ("Invalid type '$type' specified.");
1598 @_ = ("No type argument specified with -t.");
1602 $type =~ s/s$//; # "Plural". Ugh.
1606 sub get_var_argument {
1610 my $kv = shift @ARGV;
1611 if (my ($k, $v) = $kv =~ /^($field)=(.*)$/) {
1612 push @{ $data->{$k} }, $v;
1615 @_ = ("Invalid variable specification: '$kv'.");
1620 @_ = ("No variable argument specified with -S.");
1625 sub is_object_spec {
1626 my ($spec, $type) = @_;
1628 $spec =~ s|^(?:$type/)?|$type/| if defined $type;
1629 return $spec if ($spec =~ m{^$name/(?:$idlist|$labels)(?:/.*)?$}o);
1634 my ($action, $type, $rv) = @_;
1636 print STDERR "rt: For help, run 'rt help $action'.\n" if defined $action;
1637 print STDERR "rt: For help, run 'rt help $type'.\n" if defined $type;
1642 # simplified procedure for parsing date, avoid loading Date::Parse
1643 my %month = (Jan => 0, Feb => 1, Mar => 2, Apr => 3, May => 4, Jun => 5,
1644 Jul => 6, Aug => 7, Sep => 8, Oct => 9, Nov => 10, Dec => 11);
1646 my ($mon, $day, $hr, $min, $sec, $yr, $monstr);
1647 if ( /(\w{3})\s+(\d\d?)\s+(\d\d):(\d\d):(\d\d)\s+(\d{4})/ ) {
1648 ($monstr, $day, $hr, $min, $sec, $yr) = ($1, $2, $3, $4, $5, $6);
1649 $mon = $month{$monstr} if exists $month{$monstr};
1650 } elsif ( /(\d{4})-(\d\d)-(\d\d)\s+(\d\d):(\d\d):(\d\d)/ ) {
1651 ($yr, $mon, $day, $hr, $min, $sec) = ($1, $2-1, $3, $4, $5, $6);
1653 if ( $yr and defined $mon and $day and defined $hr and defined $sec ) {
1654 return timelocal($sec,$min,$hr,$day,$mon,$yr);
1656 print "Unknown date format in parsedate: $_\n";
1662 my ($old, $new) = @_;
1663 $new = time() if ! $new;
1664 $old = str2time($old) if $old !~ /^\d+$/;
1665 $new = str2time($new) if $new !~ /^\d+$/;
1666 return "???" if ! $old or ! $new;
1668 my %seconds = (min => 60,
1673 yr => 60*60*24*365);
1675 my $diff = $new - $old;
1677 my $howmuch = $diff;
1678 for ( sort {$seconds{$a} <=> $seconds{$b}} keys %seconds) {
1679 last if $diff < $seconds{$_};
1681 $howmuch = int($diff/$seconds{$_});
1683 return "$howmuch $what";
1688 my ($form) = grep { exists $_->[2]->{Queue} } @$forms;
1690 # dates are in local time zone
1692 print "Date: $k->{Created}\n";
1693 print "From: $k->{Requestors}\n";
1694 print "Cc: $k->{Cc}\n" if $k->{Cc};
1695 print "X-AdminCc: $k->{AdminCc}\n" if $k->{AdminCc};
1696 print "X-Queue: $k->{Queue}\n";
1697 print "Subject: [rt #$k->{id}] $k->{Subject}\n\n";
1699 # dates in these attributes are in GMT and will be converted
1700 foreach my $form (@$forms) {
1701 my ($c, $o, $k, $e) = @$form;
1702 next if ! $k->{id} or exists $k->{Queue};
1703 if ( exists $k->{Created} ) {
1704 my ($y,$m,$d,$hh,$mm,$ss) = ($k->{Created} =~ /(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/);
1706 my $created = localtime(timegm($ss,$mm,$hh,$d,$m,$y));
1707 if ( exists $k->{Description} ) {
1708 print "===> $k->{Description} on $created\n";
1711 print "$k->{Content}\n" if exists $k->{Content} and
1712 $k->{Content} !~ /to have no content$/ and
1713 $k->{Type} ne 'EmailRecord';
1714 print "$k->{Attachments}\n" if exists $k->{Attachments} and
1721 my $heading = "Ticket Owner Queue Age Told Status Requestor Subject\n";
1722 $heading .= '-' x 80 . "\n";
1724 foreach my $form (@$forms) {
1725 my ($c, $o, $k, $e) = @$form;
1727 print $heading if $heading;
1730 $id =~ s!^ticket/!!;
1731 my $owner = $k->{Owner} eq 'Nobody' ? '' : $k->{Owner};
1732 $owner = substr($owner, 0, 5);
1733 my $queue = substr($k->{Queue}, 0, 5);
1734 my $subject = substr($k->{Subject}, 0, 30);
1735 my $age = date_diff($k->{Created});
1736 my $told = $k->{Told} eq 'Not set' ? '' : date_diff($k->{Told});
1737 my $status = substr($k->{Status}, 0, 6);
1738 my $requestor = substr($k->{Requestors}, 0, 9);
1739 my $line = sprintf "%6s %5s %5s %6s %6s %-6s %-9s %-30s\n",
1740 $id, $owner, $queue, $age, $told, $status, $requestor, $subject;
1741 if ( $k->{Owner} eq 'Nobody' ) {
1743 } elsif ($k->{Owner} eq $config{user} ) {
1749 print "No matches found\n" if $heading;
1750 printf "========== my %2d open tickets ==========\n", scalar @me if @me;
1752 printf "========== %2d unowned tickets ==========\n", scalar @open if @open;
1753 print @open if @open;
1762 This is a command-line interface to RT 3.0 or newer.
1764 It allows you to interact with an RT server over HTTP, and offers an
1765 interface to RT's functionality that is better-suited to automation
1766 and integration with other tools.
1768 In general, each invocation of this program should specify an action
1769 to perform on one or more objects, and any other arguments required
1770 to complete the desired action.
1772 For more information:
1774 - rt help usage (syntax information)
1775 - rt help objects (how to specify objects)
1776 - rt help actions (a list of possible actions)
1777 - rt help types (a list of object types)
1779 - rt help config (configuration details)
1780 - rt help examples (a few useful examples)
1781 - rt help topics (a list of help topics)
1791 rt <action> [options] [arguments]
1795 Each invocation of this program must specify an action (e.g. "edit",
1796 "create"), options to modify behaviour, and other arguments required
1797 by the specified action. (For example, most actions expect a list of
1798 numeric object IDs to act upon.)
1800 The details of the syntax and arguments for each action are given by
1801 "rt help <action>". Some actions may be referred to by more than one
1802 name ("create" is the same as "new", for example).
1804 You may also call "rt shell", which will give you an 'rt>' prompt at
1805 which you can issue commands of the form "<action> [options]
1806 [arguments]". See "rt help shell" for details.
1808 Objects are identified by a type and an ID (which can be a name or a
1809 number, depending on the type). For some actions, the object type is
1810 implied (you can only comment on tickets); for others, the user must
1811 specify it explicitly. See "rt help objects" for details.
1813 In syntax descriptions, mandatory arguments that must be replaced by
1814 appropriate value are enclosed in <>, and optional arguments are
1815 indicated by [] (for example, <action> and [options] above).
1817 For more information:
1819 - rt help objects (how to specify objects)
1820 - rt help actions (a list of actions)
1821 - rt help types (a list of object types)
1822 - rt help shell (how to use the shell)
1828 Title: configuration
1831 This program has two major sources of configuration information: its
1832 configuration files, and the environment.
1834 The program looks for configuration directives in a file named .rtrc
1835 (or $RTCONFIG; see below) in the current directory, and then in more
1836 distant ancestors, until it reaches /. If no suitable configuration
1837 files are found, it will also check for ~/.rtrc, local/etc/rt.conf
1840 Configuration directives:
1842 The following directives may occur, one per line:
1844 - server <URL> URL to RT server.
1845 - user <username> RT username.
1846 - passwd <passwd> RT user's password.
1847 - query <RT Query> Default RT Query for list action
1848 - orderby <order> Default RT order for list action
1849 - queue <queuename> Default RT Queue for list action
1850 - externalauth <0|1> Use HTTP Basic authentication
1851 explicitely setting externalauth to 0 inhibits also GSSAPI based
1852 authentication, if LWP::Authen::Negotiate (and GSSAPI) is installed
1854 Blank and #-commented lines are ignored.
1856 Sample configuration file contents:
1858 server https://rt.somewhere.com/
1859 # more than one queue can be given (by adding a query expression)
1860 queue helpdesk or queue=support
1861 query Status != resolved and Owner=myaccount
1864 Environment variables:
1866 The following environment variables override any corresponding
1867 values defined in configuration files:
1873 - RTDEBUG Numeric debug level. (Set to 3 for full logs.)
1874 - RTCONFIG Specifies a name other than ".rtrc" for the
1876 - RTQUERY Default RT Query for rt list
1877 - RTORDERBY Default order for rt list
1886 <type>/<id>[/<attributes>]
1888 Every object in RT has a type (e.g. "ticket", "queue") and a numeric
1889 ID. Some types of objects can also be identified by name (like users
1890 and queues). Furthermore, objects may have named attributes (such as
1891 "ticket/1/history").
1893 An object specification is like a path in a virtual filesystem, with
1894 object types as top-level directories, object IDs as subdirectories,
1895 and named attributes as further subdirectories.
1897 A comma-separated list of names, numeric IDs, or numeric ranges can
1898 be used to specify more than one object of the same type. Note that
1899 the list must be a single argument (i.e., no spaces). For example,
1900 "user/root,1-3,5,7-10,ams" is a list of ten users; the same list
1901 can also be written as "user/ams,root,1,2,3,5,7,8-10".
1903 If just a number is given as object specification it will be
1904 interpreted as ticket/<number>
1908 1 # the same as ticket/1
1910 ticket/1/attachments
1911 ticket/1/attachments/3
1912 ticket/1/attachments/3/content
1914 ticket/1-3,5-7/history
1918 user/ams,rai,1/rights
1920 For more information:
1922 - rt help <action> (action-specific details)
1923 - rt help <type> (type-specific details)
1931 You can currently perform the following actions on all objects:
1933 - list (list objects matching some condition)
1934 - show (display object details)
1935 - edit (edit object details)
1936 - create (create a new object)
1938 Each type may define actions specific to itself; these are listed in
1939 the help item about that type.
1941 For more information:
1943 - rt help <action> (action-specific details)
1944 - rt help types (a list of possible types)
1946 The following actions on tickets are also possible:
1948 - comment Add comments to a ticket
1949 - correspond Add comments to a ticket
1950 - merge Merge one ticket into another
1951 - link Link one ticket to another
1952 - take Take a ticket (steal and untake are possible as well)
1954 For several edit set subcommands that are frequently used abbreviations
1955 have been introduced. These abbreviations are:
1957 - delete or del delete a ticket (edit set status=deleted)
1958 - resolve or res resolve a ticket (edit set status=resolved)
1959 - subject change subject of ticket (edit set subject=string)
1960 - give give a ticket to somebody (edit set owner=user)
1967 You can currently operate on the following types of objects:
1974 For more information:
1976 - rt help <type> (type-specific details)
1977 - rt help objects (how to specify objects)
1978 - rt help actions (a list of possible actions)
1985 Tickets are identified by a numeric ID.
1987 The following generic operations may be performed upon tickets:
1994 In addition, the following ticket-specific actions exist:
2010 The following attributes can be used with "rt show" or "rt edit"
2011 to retrieve or edit other information associated with tickets:
2013 links A ticket's relationships with others.
2014 history All of a ticket's transactions.
2015 history/type/<type> Only a particular type of transaction.
2016 history/id/<id> Only the transaction of the specified id.
2017 attachments A list of attachments.
2018 attachments/<id> The metadata for an individual attachment.
2019 attachments/<id>/content The content of an individual attachment.
2027 Users and groups are identified by name or numeric ID.
2029 The following generic operations may be performed upon them:
2036 In addition, the following type-specific actions exist:
2043 The following attributes can be used with "rt show" or "rt edit"
2044 to retrieve or edit other information associated with users and
2047 rights Global rights granted to this user.
2048 rights/<queue> Queue rights for this user.
2055 Queues are identified by name or numeric ID.
2057 Currently, they can be subjected to the following actions:
2070 rt subject <id> <new subject text>
2072 Change the subject of a ticket whose ticket id is given.
2081 rt give <id> <accountname>
2083 Give a ticket whose ticket id is given to another user.
2092 Steal a ticket whose ticket id is given, i.e. set the owner to myself.
2103 Take a ticket whose ticket id is given, i.e. set the owner to myself.
2114 Untake a ticket whose ticket id is given, i.e. set the owner to Nobody.
2126 Resolves a ticket whose ticket id is given.
2138 Deletes a ticket whose ticket id is given.
2149 Terminates the currently established login session. You will need to
2150 provide authentication credentials before you can continue using the
2151 server. (See "rt help config" for details about authentication.)
2162 rt <ls|list|search> [options] "query string"
2164 Displays a list of objects matching the specified conditions.
2165 ("ls", "list", and "search" are synonyms.)
2167 Conditions are expressed in the SQL-like syntax used internally by
2168 RT. (For more information, see "rt help query".) The query string
2169 must be supplied as one argument.
2171 (Right now, the server doesn't support listing anything but tickets.
2172 Other types will be supported in future; this client will be able to
2173 take advantage of that support without any changes.)
2177 The following options control how much information is displayed
2178 about each matching object:
2180 -i Numeric IDs only. (Useful for |rt edit -; see examples.)
2181 -s Short description.
2182 -l Longer description.
2183 -f <field[s] Display only the fields listed and the ticket id
2187 -o +/-<field> Orders the returned list by the specified field.
2188 -r reversed order (useful if a default was given)
2189 -q queue[s] restricts the query to the queue[s] given
2190 multiple queues are separated by comma
2191 -S var=val Submits the specified variable with the request.
2192 -t type Specifies the type of object to look for. (The
2193 default is "ticket".)
2197 rt ls "Priority > 5 and Status=new"
2198 rt ls -o +Subject "Priority > 5 and Status=new"
2199 rt ls -o -Created "Priority > 5 and Status=new"
2200 rt ls -i "Priority > 5"|rt edit - set status=resolved
2201 rt ls -t ticket "Subject like '[PATCH]%'"
2203 rt ls -f owner,subject
2212 rt show [options] <object-ids>
2214 Displays details of the specified objects.
2216 For some types, object information is further classified into named
2217 attributes (for example, "1-3/links" is a valid ticket specification
2218 that refers to the links for tickets 1-3). Consult "rt help <type>"
2219 and "rt help objects" for further details.
2221 If only a number is given it will be interpreted as the objects
2222 ticket/number and ticket/number/history
2224 This command writes a set of forms representing the requested object
2229 The following options control how much information is displayed
2230 about each matching object:
2232 Without any formatting options prettyprinted output is generated.
2233 Giving any of the two options below reverts to raw output.
2234 -s Short description (history and attachments only).
2235 -l Longer description (history and attachments only).
2238 - Read IDs from STDIN instead of the command-line.
2239 -t type Specifies object type.
2240 -f a,b,c Restrict the display to the specified fields.
2241 -S var=val Submits the specified variable with the request.
2245 rt show -t ticket -f id,subject,status 1-3
2246 rt show ticket/3/attachments/29
2247 rt show ticket/3/attachments/29/content
2248 rt show ticket/1-3/links
2249 rt show ticket/3/history
2250 rt show -l ticket/3/history
2263 rt edit [options] <object-ids> set field=value [field=value] ...
2264 add field=value [field=value] ...
2265 del field=value [field=value] ...
2267 Edits information corresponding to the specified objects.
2269 A purely numeric object id nnn is translated into ticket/nnn
2271 If, instead of "edit", an action of "new" or "create" is specified,
2272 then a new object is created. In this case, no numeric object IDs
2273 may be specified, but the syntax and behaviour remain otherwise
2276 This command typically starts an editor to allow you to edit object
2277 data in a form for submission. If you specified enough information
2278 on the command-line, however, it will make the submission directly.
2280 The command line may specify field-values in three different ways.
2281 "set" sets the named field to the given value, "add" adds a value
2282 to a multi-valued field, and "del" deletes the corresponding value.
2283 Each "field=value" specification must be given as a single argument.
2285 For some types, object information is further classified into named
2286 attributes (for example, "1-3/links" is a valid ticket specification
2287 that refers to the links for tickets 1-3). These attributes may also
2288 be edited. Consult "rt help <type>" and "rt help object" for further
2293 - Read numeric IDs from STDIN instead of the command-line.
2294 (Useful with rt ls ... | rt edit -; see examples below.)
2295 -i Read a completed form from STDIN before submitting.
2296 -o Dump the completed form to STDOUT instead of submitting.
2297 -e Allows you to edit the form even if the command-line has
2298 enough information to make a submission directly.
2300 Submits the specified variable with the request.
2301 -t type Specifies object type.
2305 # Interactive (starts $EDITOR with a form).
2310 rt edit ticket/1-3 add cc=foo@example.com set priority=3 due=tomorrow
2311 rt ls -t tickets -i 'Priority > 5' | rt edit - set status=resolved
2312 rt edit ticket/4 set priority=3 owner=bar@example.com \
2313 add cc=foo@example.com bcc=quux@example.net
2314 rt create -t ticket set subject='new ticket' priority=10 \
2315 add cc=foo@example.com
2325 rt <comment|correspond> [options] <ticket-id>
2327 Adds a comment (or correspondence) to the specified ticket (the only
2328 difference being that comments aren't sent to the requestors.)
2330 This command will typically start an editor and allow you to type a
2331 comment into a form. If, however, you specified all the necessary
2332 information on the command line, it submits the comment directly.
2334 (See "rt help forms" for more information about forms.)
2338 -m <text> Specify comment text.
2339 -a <file> Attach a file to the comment. (May be used more
2340 than once to attach multiple files.)
2341 -c <addrs> A comma-separated list of Cc addresses.
2342 -b <addrs> A comma-separated list of Bcc addresses.
2343 -w <time> Specify the time spent working on this ticket.
2344 -e Starts an editor before the submission, even if
2345 arguments from the command line were sufficient.
2349 rt comment -m 'Not worth fixing.' -a stddisclaimer.h 23
2358 rt merge <from-id> <to-id>
2360 Merges the first ticket specified into the second ticket specified.
2369 rt link [-d] <id-A> <link> <id-B>
2371 Creates (or, with -d, deletes) a link between the specified tickets.
2372 The link can (irrespective of case) be any of:
2374 DependsOn/DependedOnBy: A depends upon B (or vice versa).
2375 RefersTo/ReferredToBy: A refers to B (or vice versa).
2376 MemberOf/HasMember: A is a member of B (or vice versa).
2378 To view a ticket's links, use "rt show ticket/3/links". (See
2379 "rt help ticket" and "rt help show".)
2383 -d Deletes the specified link.
2387 rt link 2 dependson 3
2388 rt link -d 4 referredtoby 6 # 6 no longer refers to 4
2401 RT uses an SQL-like syntax to specify object selection constraints.
2402 See the <RT:...> documentation for details.
2404 (XXX: I'm going to have to write it, aren't I?)
2406 Until it exists here a short description of important constructs:
2408 The two simple forms of query expressions are the constructs
2409 Attribute like Value and
2410 Attribute = Value or Attribute != Value
2412 Whether attributes can be matched using like or using = is built into RT.
2413 The attributes id, Queue, Owner Priority and Status require the = or !=
2416 If Value is a string it must be quoted and may contain the wildcard
2417 character %. If the string does not contain white space, the quoting
2418 may however be omitted, it will be added automatically when parsing
2421 Simple query expressions can be combined using and, or and parentheses
2422 can be used to group expressions.
2424 As a special case a standalone string (which would not form a correct
2425 query) is transformed into (Owner='string' or Requestor like 'string%')
2426 and added to the default query, i.e. the query is narrowed down.
2428 If no Queue=name clause is contained in the query, a default clause
2429 Queue=$config{queue} is added.
2432 Status!='resolved' and Status!='rejected'
2433 (Owner='myaccount' or Requestor like 'myaccount%') and Status!='resolved'
2441 This program uses RFC822 header-style forms to represent object data
2442 in a form that's suitable for processing both by humans and scripts.
2444 A form is a set of (field, value) specifications, with some initial
2445 commented text and interspersed blank lines allowed for convenience.
2446 Field names may appear more than once in a form; a comma-separated
2447 list of multiple field values may also be specified directly.
2449 Field values can be wrapped as in RFC822, with leading whitespace.
2450 The longest sequence of leading whitespace common to all the lines
2451 is removed (preserving further indentation). There is no limit on
2452 the length of a value.
2454 Multiple forms are separated by a line containing only "--\n".
2456 (XXX: A more detailed specification will be provided soon. For now,
2457 the server-side syntax checking will suffice.)
2468 Get help on any of the following subjects:
2470 - tickets, users, groups, queues.
2471 - show, edit, ls/list/search, new/create.
2473 - query (search query syntax)
2474 - forms (form specification)
2476 - objects (how to specify objects)
2477 - types (a list of object types)
2478 - actions/commands (a list of actions)
2479 - usage/syntax (syntax details)
2480 - conf/config/configuration (configuration details)
2481 - examples (a few useful examples)
2489 some useful examples
2491 All the following list requests will be restricted to the default queue.
2492 That can be changed by adding the option -q queuename
2494 List all tickets that are not rejected/resolved
2496 List all tickets that are new and do not have an owner
2497 rt ls "status=new and owner=nobody"
2498 List all tickets which I have sent or of which I am the owner
2500 List all attributes for the ticket 6977 (ls -l instead of ls)
2502 Show the content of ticket 6977
2504 Show all attributes in the ticket and in the history of the ticket
2506 Comment a ticket (mail is sent to all queue watchers, i.e. AdminCc's)
2508 This will open an editor and lets you add text (attribute Text:)
2509 Other attributes may be changed as well, but usually don't do that.
2510 Correspond a ticket (like comment, but mail is also sent to requestors)
2512 Edit a ticket (generic change, interactive using the editor)
2514 Change the owner of a ticket non interactively
2515 rt edit 6977 set owner=myaccount
2517 rt give 6977 account
2520 Change the status of a ticket
2521 rt edit 6977 set status=resolved
2524 Change the status of all tickets I own to resolved !!!
2525 rt ls -i owner=myaccount | rt edit - set status=resolved
2536 Opens an interactive shell, at which you can issue commands of
2537 the form "<action> [options] [arguments]".
2539 To exit the shell, type "quit" or "exit".
2541 Commands can be given at the shell in the same form as they would
2542 be given at the command line without the leading 'rt' invocation.
2546 rt> create -t ticket set subject='new' add cc=foo@example.com
2560 rt <take|untake|steal> <ticket-id>
2562 Sets the owner of the specified ticket to the current user,
2563 assuming said user has the bits to do so, or releases the
2566 'Take' is used on tickets which are not currently owned
2567 (Owner: Nobody), 'steal' is used on tickets which *are*
2568 currently owned, and 'untake' is used to "release" a ticket
2569 (reset its Owner to Nobody). 'Take' cannot be used on
2570 tickets which are currently owned.
2573 alice$ rt create -t ticket set subject="New ticket"
2576 # Owner changed from Nobody to alice
2579 # Owner changed from alice to bob
2581 # Owner changed from bob to Nobody
2589 Use "quit" or "exit" to leave the shell. Only valid within shell
2601 rt - command-line interface to RT 3.0 or newer
2609 This script allows you to interact with an RT server over HTTP, and offers an
2610 interface to RT's functionality that is better-suited to automation and
2611 integration with other tools.
2613 In general, each invocation of this program should specify an action to
2614 perform on one or more objects, and any other arguments required to complete