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 $_ =~ /\/links/ 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 (($type eq "ticket") && ( ! exists $ltypes{lc $rel})) {
909 whine "Invalid link '$rel' for type $type specified.";
912 %data = (id => $from, rel => $rel, to => $to, del => $del);
915 my $bad = @ARGV < 3 ? "few" : "many";
916 whine "Too $bad arguments specified.";
919 return suggest_help("link", $type, $bad) if $bad;
921 my $r = submit("$REST/$type/link", \%data);
926 # Take/steal a ticket
929 my ($bad, %data) = (0, ());
936 unless ($id =~ /^\d+$/) {
937 whine "Invalid ticket ID $id specified.";
942 [ "Ticket", "Action" ],
950 my $text = Form::compose([ $form ]);
951 $data{content} = $text;
954 $bad = @ARGV < 1 ? "few" : "many";
955 whine "Too $bad arguments specified.";
958 return suggest_help("take", "ticket", $bad) if $bad;
960 my $r = submit("$REST/ticket/$id/take", \%data);
965 # Grant/revoke a user's rights.
974 $revoke = 1 if $cmd->{action} eq 'revoke';
978 # Client <-> Server communication.
979 # --------------------------------
981 # This function composes and sends an HTTP request to the RT server, and
982 # interprets the response. It takes a request URI, and optional request
983 # data (a string, or a reference to a set of key-value pairs).
986 my ($uri, $content) = @_;
988 my $ua = LWP::UserAgent->new(agent => "RT/3.0b", env_proxy => 1);
989 my $h = HTTP::Headers->new;
991 # Did the caller specify any data to send with the request?
993 if (defined $content) {
994 unless (ref $content) {
995 # If it's just a string, make sure LWP handles it properly.
996 # (By pretending that it's a file!)
997 $content = [ content => [undef, "", Content => $content] ];
999 elsif (ref $content eq 'HASH') {
1001 foreach my $k (keys %$content) {
1002 if (ref $content->{$k} eq 'ARRAY') {
1003 foreach my $v (@{ $content->{$k} }) {
1007 else { push @data, $k, $content->{$k} }
1014 # Should we send authentication information to start a new session?
1015 my $how = $config{server} =~ /^https/ ? 'over SSL' : 'unencrypted';
1016 (my $server = $config{server}) =~ s/^.*\/\/([^\/]+)\/?/$1/;
1017 if ($config{externalauth}) {
1018 $h->authorization_basic($config{user}, $config{passwd} || read_passwd() );
1019 print " Password will be sent to $server $how\n",
1020 " Press CTRL-C now if you do not want to continue\n"
1021 if ! $config{passwd};
1022 } elsif ( $no_strong_auth ) {
1023 if (!defined $session->cookie) {
1024 print " Strong encryption not available, $no_strong_auth\n",
1025 " Password will be sent to $server $how\n",
1026 " Press CTRL-C now if you do not want to continue\n"
1027 if ! $config{passwd};
1028 push @$data, ( user => $config{user} );
1029 push @$data, ( pass => $config{passwd} || read_passwd() );
1033 # Now, we construct the request.
1035 $req = POST($uri, $data, Content_Type => 'form-data');
1040 $session->add_cookie_header($req);
1041 if ($config{externalauth}) {
1045 # Then we send the request and parse the response.
1046 DEBUG(3, $req->as_string);
1047 my $res = $ua->request($req);
1048 DEBUG(3, $res->as_string);
1050 if ($res->is_success) {
1051 # The content of the response we get from the RT server consists
1052 # of an HTTP-like status line followed by optional header lines,
1053 # a blank line, and arbitrary text.
1055 my ($head, $text) = split /\n\n/, $res->content, 2;
1056 my ($status, @headers) = split /\n/, $head;
1057 $text =~ s/\n*$/\n/ if ($text);
1059 # "RT/3.0.1 401 Credentials required"
1060 if ($status !~ m#^RT/\d+(?:\S+) (\d+) ([\w\s]+)$#) {
1061 warn "rt: Malformed RT response from $config{server}.\n";
1062 warn "(Rerun with RTDEBUG=3 for details.)\n" if $config{debug} < 3;
1066 # Our caller can pretend that the server returned a custom HTTP
1067 # response code and message. (Doing that directly is apparently
1068 # not sufficiently portable and uncomplicated.)
1071 $res->content($text);
1072 $session->update($res) if ($res->is_success || $res->code != 401);
1074 if (!$res->is_success) {
1075 # We can deal with authentication failures ourselves. Either
1076 # we sent invalid credentials, or our session has expired.
1077 if ($res->code == 401) {
1079 if (exists $d{user}) {
1080 warn "rt: Incorrect username or password.\n";
1083 elsif ($req->header("Cookie")) {
1084 # We'll retry the request with credentials, unless
1085 # we only wanted to logout in the first place.
1087 return submit(@_) unless $uri eq "$REST/logout";
1090 # Conflicts should be dealt with by the handler and user.
1091 # For anything else, we just die.
1092 elsif ($res->code != 409) {
1093 warn "rt: ", $res->content;
1099 warn "rt: Server error: ", $res->message, " (", $res->code, ")\n";
1106 # Session management.
1107 # -------------------
1109 # Maintains a list of active sessions in the ~/.rt_sessions file.
1114 # Initialises the session cache.
1116 my ($class, $file) = @_;
1118 file => $file || "$HOME/.rt_sessions",
1122 # The current session is identified by the currently configured
1124 ($s, $u) = @config{"server", "user"};
1126 bless $self, $class;
1132 # Returns the current session cookie.
1135 my $cookie = $self->{sids}{$s}{$u};
1136 return defined $cookie ? "RT_SID_$cookie" : undef;
1139 # Deletes the current session cookie.
1142 delete $self->{sids}{$s}{$u};
1145 # Adds a Cookie header to an outgoing HTTP request.
1146 sub add_cookie_header {
1147 my ($self, $request) = @_;
1148 my $cookie = $self->cookie();
1150 $request->header(Cookie => $cookie) if defined $cookie;
1153 # Extracts the Set-Cookie header from an HTTP response, and updates
1154 # session information accordingly.
1156 my ($self, $response) = @_;
1157 my $cookie = $response->header("Set-Cookie");
1159 if (defined $cookie && $cookie =~ /^RT_SID_(.[^;,\s]+=[0-9A-Fa-f]+);/) {
1160 $self->{sids}{$s}{$u} = $1;
1164 # Loads the session cache from the specified file.
1166 my ($self, $file) = @_;
1167 $file ||= $self->{file};
1169 open( my $handle, '<', $file ) or return 0;
1171 $self->{file} = $file;
1172 my $sids = $self->{sids} = {};
1175 next if /^$/ || /^#/;
1176 next unless m#^https?://[^ ]+ \w+ [^;,\s]+=[0-9A-Fa-f]+$#;
1177 my ($server, $user, $cookie) = split / /, $_;
1178 $sids->{$server}{$user} = $cookie;
1183 # Writes the current session cache to the specified file.
1185 my ($self, $file) = shift;
1186 $file ||= $self->{file};
1188 open( my $handle, '>', "$file" ) or return 0;
1190 my $sids = $self->{sids};
1191 foreach my $server (keys %$sids) {
1192 foreach my $user (keys %{ $sids->{$server} }) {
1193 my $sid = $sids->{$server}{$user};
1195 print $handle "$server $user $sid\n";
1213 # Forms are RFC822-style sets of (field, value) specifications with some
1214 # initial comments and interspersed blank lines allowed for convenience.
1215 # Sets of forms are separated by --\n (in a cheap parody of MIME).
1217 # Each form is parsed into an array with four elements: commented text
1218 # at the start of the form, an array with the order of keys, a hash with
1219 # key/value pairs, and optional error text if the form syntax was wrong.
1221 # Returns a reference to an array of parsed forms.
1225 my @lines = split /\n/, $_[0] if $_[0];
1226 my ($c, $o, $k, $e) = ("", [], {}, "");
1230 my $line = shift @lines;
1232 next LINE if $line eq '';
1234 if ($line eq '--') {
1235 # We reached the end of one form. We'll ignore it if it was
1236 # empty, and store it otherwise, errors and all.
1237 if ($e || $c || @$o) {
1238 push @forms, [ $c, $o, $k, $e ];
1239 $c = ""; $o = []; $k = {}; $e = "";
1243 elsif ($state != -1) {
1244 if ($state == 0 && $line =~ /^#/) {
1245 # Read an optional block of comments (only) at the start
1249 while (@lines && $lines[0] =~ /^#/) {
1250 $c .= "\n".shift @lines;
1254 elsif ($state <= 1 && $line =~ /^($field):(?:\s+(.*))?$/) {
1255 # Read a field: value specification.
1259 # Read continuation lines, if any.
1260 while (@lines && ($lines[0] eq '' || $lines[0] =~ /^\s+/)) {
1261 push @v, shift @lines;
1263 pop @v while (@v && $v[-1] eq '');
1265 # Strip longest common leading indent from text.
1267 foreach my $ls (map {/^(\s+)/} @v[1..$#v]) {
1268 $ws = $ls if (!$ws || length($ls) < length($ws));
1270 s/^$ws// foreach @v;
1272 push(@$o, $f) unless exists $k->{$f};
1273 vpush($k, $f, join("\n", @v));
1277 elsif ($line !~ /^#/) {
1278 # We've found a syntax error, so we'll reconstruct the
1279 # form parsed thus far, and add an error marker. (>>)
1281 $e = Form::compose([[ "", $o, $k, "" ]]);
1282 $e.= $line =~ /^>>/ ? "$line\n" : ">> $line\n";
1286 # We saw a syntax error earlier, so we'll accumulate the
1287 # contents of this form until the end.
1291 push(@forms, [ $c, $o, $k, $e ]) if ($e || $c || @$o);
1293 foreach my $l (keys %$k) {
1294 $k->{$l} = vsplit($k->{$l}) if (ref $k->{$l} eq 'ARRAY');
1300 # Returns text representing a set of forms.
1305 foreach my $form (@$forms) {
1306 my ($c, $o, $k, $e) = @$form;
1319 foreach my $key (@$o) {
1322 my @values = ref $v eq 'ARRAY' ? @$v : $v;
1324 $sp = " "x(length("$key: "));
1325 $sp = " "x4 if length($sp) > 16;
1327 foreach $v (@values) {
1333 push @lines, "$line\n\n";
1336 elsif (@lines && $lines[-1] !~ /\n\n$/) {
1339 push @lines, "$key: $v\n\n";
1342 length($line)+length($v)-rindex($line, "\n") >= 70)
1344 $line .= ",\n$sp$v";
1347 $line = $line ? "$line,$v" : "$key: $v";
1351 $line = "$key:" unless @values;
1353 if ($line =~ /\n/) {
1354 if (@lines && $lines[-1] !~ /\n\n$/) {
1359 push @lines, "$line\n";
1363 $text .= join "", @lines;
1371 return join "\n--\n\n", @text;
1377 # Returns configuration information from the environment.
1378 sub config_from_env {
1381 foreach my $k (qw(EXTERNALAUTH DEBUG USER PASSWD SERVER QUERY ORDERBY)) {
1383 if (exists $ENV{"RT$k"}) {
1384 $env{lc $k} = $ENV{"RT$k"};
1391 # Finds a suitable configuration file and returns information from it.
1392 sub config_from_file {
1396 # We'll use an absolute path if we were given one.
1397 return parse_config_file($rc);
1400 # Otherwise we'll use the first file we can find in the current
1401 # directory, or in one of its (increasingly distant) ancestors.
1403 my @dirs = split /\//, cwd;
1405 my $file = join('/', @dirs, $rc);
1407 return parse_config_file($file);
1410 # Remove the last directory component each time.
1414 # Still nothing? We'll fall back to some likely defaults.
1415 for ("$HOME/$rc", "/opt/rt3/local/etc/rt.conf", "/etc/rt.conf") {
1416 return parse_config_file($_) if (-r $_);
1423 # Makes a hash of the specified configuration file.
1424 sub parse_config_file {
1427 local $_; # $_ may be aliased to a constant, from line 1163
1429 open( my $handle, '<', $file ) or return;
1433 next if (/^#/ || /^\s*$/);
1435 if (/^(externalauth|user|passwd|server|query|orderby|queue)\s+(.*)\s?$/) {
1439 die "rt: $file:$.: unknown configuration directive.\n";
1450 my $sub = (caller(1))[3];
1451 $sub =~ s/^main:://;
1452 warn "rt: $sub: @_\n";
1457 eval 'require Term::ReadKey';
1459 die "No password specified (and Term::ReadKey not installed).\n";
1463 Term::ReadKey::ReadMode('noecho');
1464 chomp(my $passwd = Term::ReadKey::ReadLine(0));
1465 Term::ReadKey::ReadMode('restore');
1473 my $file = "/tmp/rt.form.$$";
1474 my $editor = $ENV{EDITOR} || $ENV{VISUAL} || "vi";
1478 open( my $handle, '>', $file ) or die "$file: $!\n";
1479 print $handle $text;
1482 system($editor, $file) && die "Couldn't run $editor.\n";
1484 open( $handle, '<', $file ) or die "$file: $!\n";
1493 # Add a value to a (possibly multi-valued) hash key.
1495 my ($hash, $key, $val) = @_;
1496 my @val = ref $val eq 'ARRAY' ? @$val : $val;
1498 if (exists $hash->{$key}) {
1499 unless (ref $hash->{$key} eq 'ARRAY') {
1500 my @v = $hash->{$key} ne '' ? $hash->{$key} : ();
1501 $hash->{$key} = \@v;
1503 push @{ $hash->{$key} }, @val;
1506 $hash->{$key} = $val;
1510 # "Normalise" a hash key that's known to be multi-valued.
1514 my @values = ref $val eq 'ARRAY' ? @$val : $val;
1516 foreach my $line (map {split /\n/} @values) {
1517 # XXX: This should become a real parser, Ã la Text::ParseWords.
1520 my ( $a, $b ) = split /\s*,\s*/, $line, 2;
1523 no warnings 'uninitialized';
1526 while ( $a !~ /'$/ || ( $a !~ /(\\\\)+'$/
1527 && $a =~ /(\\)+'$/ )) {
1528 ( $a, $b ) = split /\s*,\s*/, $b, 2;
1533 elsif ( $a =~ /^q{/ ) {
1535 while ( $a !~ /}$/ ) {
1537 split /\s*,\s*/, $b, 2;
1547 ( $a, $b ) = split /\s*,\s*/, $b, 2;
1556 # WARN: this code is duplicated in lib/RT/Interface/REST.pm
1557 # change both functions at once
1562 foreach (split /\s*,\s*/, $list) {
1563 push @elts, /^(\d+)-(\d+)$/? ($1..$2): $_;
1566 return map $_->[0], # schwartzian transform
1568 defined $a->[1] && defined $b->[1]?
1571 :!defined $a->[1] && !defined $b->[1]?
1574 # mix, number must be first
1575 :defined $a->[1]? -1: 1
1577 map [ $_, (defined( /^(\d+)$/ )? $1: undef), lc($_) ],
1581 sub get_type_argument {
1585 $type = shift @ARGV;
1586 unless ($type =~ /^[A-Za-z0-9_.-]+$/) {
1587 # We want whine to mention our caller, not us.
1588 @_ = ("Invalid type '$type' specified.");
1593 @_ = ("No type argument specified with -t.");
1597 $type =~ s/s$//; # "Plural". Ugh.
1601 sub get_var_argument {
1605 my $kv = shift @ARGV;
1606 if (my ($k, $v) = $kv =~ /^($field)=(.*)$/) {
1607 push @{ $data->{$k} }, $v;
1610 @_ = ("Invalid variable specification: '$kv'.");
1615 @_ = ("No variable argument specified with -S.");
1620 sub is_object_spec {
1621 my ($spec, $type) = @_;
1623 $spec =~ s|^(?:$type/)?|$type/| if defined $type;
1624 return $spec if ($spec =~ m{^$name/(?:$idlist|$labels)(?:/.*)?$}o);
1629 my ($action, $type, $rv) = @_;
1631 print STDERR "rt: For help, run 'rt help $action'.\n" if defined $action;
1632 print STDERR "rt: For help, run 'rt help $type'.\n" if defined $type;
1637 # simplified procedure for parsing date, avoid loading Date::Parse
1638 my %month = (Jan => 0, Feb => 1, Mar => 2, Apr => 3, May => 4, Jun => 5,
1639 Jul => 6, Aug => 7, Sep => 8, Oct => 9, Nov => 10, Dec => 11);
1641 my ($mon, $day, $hr, $min, $sec, $yr, $monstr);
1642 if ( /(\w{3})\s+(\d\d?)\s+(\d\d):(\d\d):(\d\d)\s+(\d{4})/ ) {
1643 ($monstr, $day, $hr, $min, $sec, $yr) = ($1, $2, $3, $4, $5, $6);
1644 $mon = $month{$monstr} if exists $month{$monstr};
1645 } elsif ( /(\d{4})-(\d\d)-(\d\d)\s+(\d\d):(\d\d):(\d\d)/ ) {
1646 ($yr, $mon, $day, $hr, $min, $sec) = ($1, $2-1, $3, $4, $5, $6);
1648 if ( $yr and defined $mon and $day and defined $hr and defined $sec ) {
1649 return timelocal($sec,$min,$hr,$day,$mon,$yr);
1651 print "Unknown date format in parsedate: $_\n";
1657 my ($old, $new) = @_;
1658 $new = time() if ! $new;
1659 $old = str2time($old) if $old !~ /^\d+$/;
1660 $new = str2time($new) if $new !~ /^\d+$/;
1661 return "???" if ! $old or ! $new;
1663 my %seconds = (min => 60,
1668 yr => 60*60*24*365);
1670 my $diff = $new - $old;
1672 my $howmuch = $diff;
1673 for ( sort {$seconds{$a} <=> $seconds{$b}} keys %seconds) {
1674 last if $diff < $seconds{$_};
1676 $howmuch = int($diff/$seconds{$_});
1678 return "$howmuch $what";
1683 my ($form) = grep { exists $_->[2]->{Queue} } @$forms;
1685 # dates are in local time zone
1687 print "Date: $k->{Created}\n";
1688 print "From: $k->{Requestors}\n";
1689 print "Cc: $k->{Cc}\n" if $k->{Cc};
1690 print "X-AdminCc: $k->{AdminCc}\n" if $k->{AdminCc};
1691 print "X-Queue: $k->{Queue}\n";
1692 print "Subject: [rt #$k->{id}] $k->{Subject}\n\n";
1694 # dates in these attributes are in GMT and will be converted
1695 foreach my $form (@$forms) {
1696 my ($c, $o, $k, $e) = @$form;
1697 next if ! $k->{id} or exists $k->{Queue};
1698 if ( exists $k->{Created} ) {
1699 my ($y,$m,$d,$hh,$mm,$ss) = ($k->{Created} =~ /(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/);
1701 my $created = localtime(timegm($ss,$mm,$hh,$d,$m,$y));
1702 if ( exists $k->{Description} ) {
1703 print "===> $k->{Description} on $created\n";
1706 print "$k->{Content}\n" if exists $k->{Content} and
1707 $k->{Content} !~ /to have no content$/ and
1708 ($k->{Type}||'') ne 'EmailRecord';
1709 print "$k->{Attachments}\n" if exists $k->{Attachments} and
1716 my $heading = "Ticket Owner Queue Age Told Status Requestor Subject\n";
1717 $heading .= '-' x 80 . "\n";
1719 foreach my $form (@$forms) {
1720 my ($c, $o, $k, $e) = @$form;
1722 print $heading if $heading;
1725 $id =~ s!^ticket/!!;
1726 my $owner = $k->{Owner} eq 'Nobody' ? '' : $k->{Owner};
1727 $owner = substr($owner, 0, 5);
1728 my $queue = substr($k->{Queue}, 0, 5);
1729 my $subject = substr($k->{Subject}, 0, 30);
1730 my $age = date_diff($k->{Created});
1731 my $told = $k->{Told} eq 'Not set' ? '' : date_diff($k->{Told});
1732 my $status = substr($k->{Status}, 0, 6);
1733 my $requestor = substr($k->{Requestors}, 0, 9);
1734 my $line = sprintf "%6s %5s %5s %6s %6s %-6s %-9s %-30s\n",
1735 $id, $owner, $queue, $age, $told, $status, $requestor, $subject;
1736 if ( $k->{Owner} eq 'Nobody' ) {
1738 } elsif ($k->{Owner} eq $config{user} ) {
1744 print "No matches found\n" if $heading;
1745 printf "========== my %2d open tickets ==========\n", scalar @me if @me;
1747 printf "========== %2d unowned tickets ==========\n", scalar @open if @open;
1748 print @open if @open;
1757 This is a command-line interface to RT 3.0 or newer.
1759 It allows you to interact with an RT server over HTTP, and offers an
1760 interface to RT's functionality that is better-suited to automation
1761 and integration with other tools.
1763 In general, each invocation of this program should specify an action
1764 to perform on one or more objects, and any other arguments required
1765 to complete the desired action.
1767 For more information:
1769 - rt help usage (syntax information)
1770 - rt help objects (how to specify objects)
1771 - rt help actions (a list of possible actions)
1772 - rt help types (a list of object types)
1774 - rt help config (configuration details)
1775 - rt help examples (a few useful examples)
1776 - rt help topics (a list of help topics)
1786 rt <action> [options] [arguments]
1790 Each invocation of this program must specify an action (e.g. "edit",
1791 "create"), options to modify behaviour, and other arguments required
1792 by the specified action. (For example, most actions expect a list of
1793 numeric object IDs to act upon.)
1795 The details of the syntax and arguments for each action are given by
1796 "rt help <action>". Some actions may be referred to by more than one
1797 name ("create" is the same as "new", for example).
1799 You may also call "rt shell", which will give you an 'rt>' prompt at
1800 which you can issue commands of the form "<action> [options]
1801 [arguments]". See "rt help shell" for details.
1803 Objects are identified by a type and an ID (which can be a name or a
1804 number, depending on the type). For some actions, the object type is
1805 implied (you can only comment on tickets); for others, the user must
1806 specify it explicitly. See "rt help objects" for details.
1808 In syntax descriptions, mandatory arguments that must be replaced by
1809 appropriate value are enclosed in <>, and optional arguments are
1810 indicated by [] (for example, <action> and [options] above).
1812 For more information:
1814 - rt help objects (how to specify objects)
1815 - rt help actions (a list of actions)
1816 - rt help types (a list of object types)
1817 - rt help shell (how to use the shell)
1823 Title: configuration
1826 This program has two major sources of configuration information: its
1827 configuration files, and the environment.
1829 The program looks for configuration directives in a file named .rtrc
1830 (or $RTCONFIG; see below) in the current directory, and then in more
1831 distant ancestors, until it reaches /. If no suitable configuration
1832 files are found, it will also check for ~/.rtrc, /opt/rt3/local/etc/rt.conf
1835 Configuration directives:
1837 The following directives may occur, one per line:
1839 - server <URL> URL to RT server.
1840 - user <username> RT username.
1841 - passwd <passwd> RT user's password.
1842 - query <RT Query> Default RT Query for list action
1843 - orderby <order> Default RT order for list action
1844 - queue <queuename> Default RT Queue for list action
1845 - externalauth <0|1> Use HTTP Basic authentication
1846 explicitely setting externalauth to 0 inhibits also GSSAPI based
1847 authentication, if LWP::Authen::Negotiate (and GSSAPI) is installed
1849 Blank and #-commented lines are ignored.
1851 Sample configuration file contents:
1853 server https://rt.somewhere.com/
1854 # more than one queue can be given (by adding a query expression)
1855 queue helpdesk or queue=support
1856 query Status != resolved and Owner=myaccount
1859 Environment variables:
1861 The following environment variables override any corresponding
1862 values defined in configuration files:
1868 - RTDEBUG Numeric debug level. (Set to 3 for full logs.)
1869 - RTCONFIG Specifies a name other than ".rtrc" for the
1871 - RTQUERY Default RT Query for rt list
1872 - RTORDERBY Default order for rt list
1881 <type>/<id>[/<attributes>]
1883 Every object in RT has a type (e.g. "ticket", "queue") and a numeric
1884 ID. Some types of objects can also be identified by name (like users
1885 and queues). Furthermore, objects may have named attributes (such as
1886 "ticket/1/history").
1888 An object specification is like a path in a virtual filesystem, with
1889 object types as top-level directories, object IDs as subdirectories,
1890 and named attributes as further subdirectories.
1892 A comma-separated list of names, numeric IDs, or numeric ranges can
1893 be used to specify more than one object of the same type. Note that
1894 the list must be a single argument (i.e., no spaces). For example,
1895 "user/root,1-3,5,7-10,ams" is a list of ten users; the same list
1896 can also be written as "user/ams,root,1,2,3,5,7,8-10".
1898 If just a number is given as object specification it will be
1899 interpreted as ticket/<number>
1903 1 # the same as ticket/1
1905 ticket/1/attachments
1906 ticket/1/attachments/3
1907 ticket/1/attachments/3/content
1909 ticket/1-3,5-7/history
1913 user/ams,rai,1/rights
1915 For more information:
1917 - rt help <action> (action-specific details)
1918 - rt help <type> (type-specific details)
1926 You can currently perform the following actions on all objects:
1928 - list (list objects matching some condition)
1929 - show (display object details)
1930 - edit (edit object details)
1931 - create (create a new object)
1933 Each type may define actions specific to itself; these are listed in
1934 the help item about that type.
1936 For more information:
1938 - rt help <action> (action-specific details)
1939 - rt help types (a list of possible types)
1941 The following actions on tickets are also possible:
1943 - comment Add comments to a ticket
1944 - correspond Add comments to a ticket
1945 - merge Merge one ticket into another
1946 - link Link one ticket to another
1947 - take Take a ticket (steal and untake are possible as well)
1949 For several edit set subcommands that are frequently used abbreviations
1950 have been introduced. These abbreviations are:
1952 - delete or del delete a ticket (edit set status=deleted)
1953 - resolve or res resolve a ticket (edit set status=resolved)
1954 - subject change subject of ticket (edit set subject=string)
1955 - give give a ticket to somebody (edit set owner=user)
1962 You can currently operate on the following types of objects:
1969 For more information:
1971 - rt help <type> (type-specific details)
1972 - rt help objects (how to specify objects)
1973 - rt help actions (a list of possible actions)
1980 Tickets are identified by a numeric ID.
1982 The following generic operations may be performed upon tickets:
1989 In addition, the following ticket-specific actions exist:
2005 The following attributes can be used with "rt show" or "rt edit"
2006 to retrieve or edit other information associated with tickets:
2008 links A ticket's relationships with others.
2009 history All of a ticket's transactions.
2010 history/type/<type> Only a particular type of transaction.
2011 history/id/<id> Only the transaction of the specified id.
2012 attachments A list of attachments.
2013 attachments/<id> The metadata for an individual attachment.
2014 attachments/<id>/content The content of an individual attachment.
2022 Users and groups are identified by name or numeric ID.
2024 The following generic operations may be performed upon them:
2031 In addition, the following type-specific actions exist:
2038 The following attributes can be used with "rt show" or "rt edit"
2039 to retrieve or edit other information associated with users and
2042 rights Global rights granted to this user.
2043 rights/<queue> Queue rights for this user.
2050 Queues are identified by name or numeric ID.
2052 Currently, they can be subjected to the following actions:
2065 rt subject <id> <new subject text>
2067 Change the subject of a ticket whose ticket id is given.
2076 rt give <id> <accountname>
2078 Give a ticket whose ticket id is given to another user.
2087 Steal a ticket whose ticket id is given, i.e. set the owner to myself.
2098 Take a ticket whose ticket id is given, i.e. set the owner to myself.
2109 Untake a ticket whose ticket id is given, i.e. set the owner to Nobody.
2121 Resolves a ticket whose ticket id is given.
2133 Deletes a ticket whose ticket id is given.
2144 Terminates the currently established login session. You will need to
2145 provide authentication credentials before you can continue using the
2146 server. (See "rt help config" for details about authentication.)
2157 rt <ls|list|search> [options] "query string"
2159 Displays a list of objects matching the specified conditions.
2160 ("ls", "list", and "search" are synonyms.)
2162 Conditions are expressed in the SQL-like syntax used internally by
2163 RT. (For more information, see "rt help query".) The query string
2164 must be supplied as one argument.
2166 (Right now, the server doesn't support listing anything but tickets.
2167 Other types will be supported in future; this client will be able to
2168 take advantage of that support without any changes.)
2172 The following options control how much information is displayed
2173 about each matching object:
2175 -i Numeric IDs only. (Useful for |rt edit -; see examples.)
2176 -s Short description.
2177 -l Longer description.
2178 -f <field[s] Display only the fields listed and the ticket id
2182 -o +/-<field> Orders the returned list by the specified field.
2183 -r reversed order (useful if a default was given)
2184 -q queue[s] restricts the query to the queue[s] given
2185 multiple queues are separated by comma
2186 -S var=val Submits the specified variable with the request.
2187 -t type Specifies the type of object to look for. (The
2188 default is "ticket".)
2192 rt ls "Priority > 5 and Status=new"
2193 rt ls -o +Subject "Priority > 5 and Status=new"
2194 rt ls -o -Created "Priority > 5 and Status=new"
2195 rt ls -i "Priority > 5"|rt edit - set status=resolved
2196 rt ls -t ticket "Subject like '[PATCH]%'"
2198 rt ls -f owner,subject
2207 rt show [options] <object-ids>
2209 Displays details of the specified objects.
2211 For some types, object information is further classified into named
2212 attributes (for example, "1-3/links" is a valid ticket specification
2213 that refers to the links for tickets 1-3). Consult "rt help <type>"
2214 and "rt help objects" for further details.
2216 If only a number is given it will be interpreted as the objects
2217 ticket/number and ticket/number/history
2219 This command writes a set of forms representing the requested object
2224 The following options control how much information is displayed
2225 about each matching object:
2227 Without any formatting options prettyprinted output is generated.
2228 Giving any of the two options below reverts to raw output.
2229 -s Short description (history and attachments only).
2230 -l Longer description (history and attachments only).
2233 - Read IDs from STDIN instead of the command-line.
2234 -t type Specifies object type.
2235 -f a,b,c Restrict the display to the specified fields.
2236 -S var=val Submits the specified variable with the request.
2240 rt show -t ticket -f id,subject,status 1-3
2241 rt show ticket/3/attachments/29
2242 rt show ticket/3/attachments/29/content
2243 rt show ticket/1-3/links
2244 rt show ticket/3/history
2245 rt show -l ticket/3/history
2258 rt edit [options] <object-ids> set field=value [field=value] ...
2259 add field=value [field=value] ...
2260 del field=value [field=value] ...
2262 Edits information corresponding to the specified objects.
2264 A purely numeric object id nnn is translated into ticket/nnn
2266 If, instead of "edit", an action of "new" or "create" is specified,
2267 then a new object is created. In this case, no numeric object IDs
2268 may be specified, but the syntax and behaviour remain otherwise
2271 This command typically starts an editor to allow you to edit object
2272 data in a form for submission. If you specified enough information
2273 on the command-line, however, it will make the submission directly.
2275 The command line may specify field-values in three different ways.
2276 "set" sets the named field to the given value, "add" adds a value
2277 to a multi-valued field, and "del" deletes the corresponding value.
2278 Each "field=value" specification must be given as a single argument.
2280 For some types, object information is further classified into named
2281 attributes (for example, "1-3/links" is a valid ticket specification
2282 that refers to the links for tickets 1-3). These attributes may also
2283 be edited. Consult "rt help <type>" and "rt help object" for further
2288 - Read numeric IDs from STDIN instead of the command-line.
2289 (Useful with rt ls ... | rt edit -; see examples below.)
2290 -i Read a completed form from STDIN before submitting.
2291 -o Dump the completed form to STDOUT instead of submitting.
2292 -e Allows you to edit the form even if the command-line has
2293 enough information to make a submission directly.
2295 Submits the specified variable with the request.
2296 -t type Specifies object type.
2300 # Interactive (starts $EDITOR with a form).
2305 rt edit ticket/1-3 add cc=foo@example.com set priority=3 due=tomorrow
2306 rt ls -t tickets -i 'Priority > 5' | rt edit - set status=resolved
2307 rt edit ticket/4 set priority=3 owner=bar@example.com \
2308 add cc=foo@example.com bcc=quux@example.net
2309 rt create -t ticket set subject='new ticket' priority=10 \
2310 add cc=foo@example.com
2320 rt <comment|correspond> [options] <ticket-id>
2322 Adds a comment (or correspondence) to the specified ticket (the only
2323 difference being that comments aren't sent to the requestors.)
2325 This command will typically start an editor and allow you to type a
2326 comment into a form. If, however, you specified all the necessary
2327 information on the command line, it submits the comment directly.
2329 (See "rt help forms" for more information about forms.)
2333 -m <text> Specify comment text.
2334 -a <file> Attach a file to the comment. (May be used more
2335 than once to attach multiple files.)
2336 -c <addrs> A comma-separated list of Cc addresses.
2337 -b <addrs> A comma-separated list of Bcc addresses.
2338 -w <time> Specify the time spent working on this ticket.
2339 -e Starts an editor before the submission, even if
2340 arguments from the command line were sufficient.
2344 rt comment -m 'Not worth fixing.' -a stddisclaimer.h 23
2353 rt merge <from-id> <to-id>
2355 Merges the first ticket specified into the second ticket specified.
2364 rt link [-d] <id-A> <link> <id-B>
2366 Creates (or, with -d, deletes) a link between the specified tickets.
2367 The link can (irrespective of case) be any of:
2369 DependsOn/DependedOnBy: A depends upon B (or vice versa).
2370 RefersTo/ReferredToBy: A refers to B (or vice versa).
2371 MemberOf/HasMember: A is a member of B (or vice versa).
2373 To view a ticket's links, use "rt show ticket/3/links". (See
2374 "rt help ticket" and "rt help show".)
2378 -d Deletes the specified link.
2382 rt link 2 dependson 3
2383 rt link -d 4 referredtoby 6 # 6 no longer refers to 4
2396 RT uses an SQL-like syntax to specify object selection constraints.
2397 See the <RT:...> documentation for details.
2399 (XXX: I'm going to have to write it, aren't I?)
2401 Until it exists here a short description of important constructs:
2403 The two simple forms of query expressions are the constructs
2404 Attribute like Value and
2405 Attribute = Value or Attribute != Value
2407 Whether attributes can be matched using like or using = is built into RT.
2408 The attributes id, Queue, Owner Priority and Status require the = or !=
2411 If Value is a string it must be quoted and may contain the wildcard
2412 character %. If the string does not contain white space, the quoting
2413 may however be omitted, it will be added automatically when parsing
2416 Simple query expressions can be combined using and, or and parentheses
2417 can be used to group expressions.
2419 As a special case a standalone string (which would not form a correct
2420 query) is transformed into (Owner='string' or Requestor like 'string%')
2421 and added to the default query, i.e. the query is narrowed down.
2423 If no Queue=name clause is contained in the query, a default clause
2424 Queue=$config{queue} is added.
2427 Status!='resolved' and Status!='rejected'
2428 (Owner='myaccount' or Requestor like 'myaccount%') and Status!='resolved'
2436 This program uses RFC822 header-style forms to represent object data
2437 in a form that's suitable for processing both by humans and scripts.
2439 A form is a set of (field, value) specifications, with some initial
2440 commented text and interspersed blank lines allowed for convenience.
2441 Field names may appear more than once in a form; a comma-separated
2442 list of multiple field values may also be specified directly.
2444 Field values can be wrapped as in RFC822, with leading whitespace.
2445 The longest sequence of leading whitespace common to all the lines
2446 is removed (preserving further indentation). There is no limit on
2447 the length of a value.
2449 Multiple forms are separated by a line containing only "--\n".
2451 (XXX: A more detailed specification will be provided soon. For now,
2452 the server-side syntax checking will suffice.)
2463 Get help on any of the following subjects:
2465 - tickets, users, groups, queues.
2466 - show, edit, ls/list/search, new/create.
2468 - query (search query syntax)
2469 - forms (form specification)
2471 - objects (how to specify objects)
2472 - types (a list of object types)
2473 - actions/commands (a list of actions)
2474 - usage/syntax (syntax details)
2475 - conf/config/configuration (configuration details)
2476 - examples (a few useful examples)
2484 some useful examples
2486 All the following list requests will be restricted to the default queue.
2487 That can be changed by adding the option -q queuename
2489 List all tickets that are not rejected/resolved
2491 List all tickets that are new and do not have an owner
2492 rt ls "status=new and owner=nobody"
2493 List all tickets which I have sent or of which I am the owner
2495 List all attributes for the ticket 6977 (ls -l instead of ls)
2497 Show the content of ticket 6977
2499 Show all attributes in the ticket and in the history of the ticket
2501 Comment a ticket (mail is sent to all queue watchers, i.e. AdminCc's)
2503 This will open an editor and lets you add text (attribute Text:)
2504 Other attributes may be changed as well, but usually don't do that.
2505 Correspond a ticket (like comment, but mail is also sent to requestors)
2507 Edit a ticket (generic change, interactive using the editor)
2509 Change the owner of a ticket non interactively
2510 rt edit 6977 set owner=myaccount
2512 rt give 6977 account
2515 Change the status of a ticket
2516 rt edit 6977 set status=resolved
2519 Change the status of all tickets I own to resolved !!!
2520 rt ls -i owner=myaccount | rt edit - set status=resolved
2531 Opens an interactive shell, at which you can issue commands of
2532 the form "<action> [options] [arguments]".
2534 To exit the shell, type "quit" or "exit".
2536 Commands can be given at the shell in the same form as they would
2537 be given at the command line without the leading 'rt' invocation.
2541 rt> create -t ticket set subject='new' add cc=foo@example.com
2555 rt <take|untake|steal> <ticket-id>
2557 Sets the owner of the specified ticket to the current user,
2558 assuming said user has the bits to do so, or releases the
2561 'Take' is used on tickets which are not currently owned
2562 (Owner: Nobody), 'steal' is used on tickets which *are*
2563 currently owned, and 'untake' is used to "release" a ticket
2564 (reset its Owner to Nobody). 'Take' cannot be used on
2565 tickets which are currently owned.
2568 alice$ rt create -t ticket set subject="New ticket"
2571 # Owner changed from Nobody to alice
2574 # Owner changed from alice to bob
2576 # Owner changed from bob to Nobody
2584 Use "quit" or "exit" to leave the shell. Only valid within shell
2596 rt - command-line interface to RT 3.0 or newer
2604 This script allows you to interact with an RT server over HTTP, and offers an
2605 interface to RT's functionality that is better-suited to automation and
2606 integration with other tools.
2608 In general, each invocation of this program should specify an action to
2609 perform on one or more objects, and any other arguments required to complete