diff options
Diffstat (limited to 'rt/bin/rt.in')
-rw-r--r-- | rt/bin/rt.in | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/rt/bin/rt.in b/rt/bin/rt.in index 90369b5b3..b44e04158 100644 --- a/rt/bin/rt.in +++ b/rt/bin/rt.in @@ -46,6 +46,8 @@ my %config = ( user => eval{(getpwuid($<))[0]} || $ENV{USER} || $ENV{USERNAME}, passwd => undef, server => 'http://localhost/rt/', + query => undef, + orderby => undef, ), config_from_file($ENV{RTCONFIG} || ".rtrc"), config_from_env() @@ -123,9 +125,9 @@ sub help { my $title = $item->[2]{Title}; my @titles = ref $title eq 'ARRAY' ? @$title : $title; - foreach $title (grep $_, @titles) { - $help{$title} = $item->[2]{Text}; - } + foreach $title (grep $_, @titles) { + $help{$title} = $item->[2]{Text}; + } } # What does the user want help with? @@ -167,6 +169,9 @@ sub help { sub list { my ($q, $type, %data, $orderby); + if ($config{orderby}) { + $data{orderby} = $config{orderby}; + } my $bad = 0; while (@ARGV) { @@ -179,7 +184,7 @@ sub list { $bad = 1, last unless get_var_argument(\%data); } elsif (/^-o$/) { - $orderby = shift @ARGV; + $data{'orderby'} = shift @ARGV; } elsif (/^-([isl])$/) { $data{format} = $1; @@ -200,7 +205,11 @@ sub list { $bad = 1; last; } } - + + if (!defined $q) { + $q = $config{query}; + } + $type ||= "ticket"; unless ($type && defined $q) { my $item = $type ? "query string" : "object type"; @@ -209,7 +218,7 @@ sub list { } return help("list", $type) if $bad; - my $r = submit("$REST/search/$type", { query => $q, %data, orderby => $orderby || "" }); + my $r = submit("$REST/search/$type", { query => $q, %data }); print $r->content; } @@ -514,7 +523,14 @@ sub comment { my $a = $_ eq "-b" ? \@bcc : \@cc; @$a = split /\s*,\s*/, shift @ARGV; } - elsif (/-m/) { $msg = shift @ARGV } + elsif (/-m/) { + $msg = shift @ARGV; + if ( $msg =~ /^-$/ ) { + undef $msg; + while (<STDIN>) { $msg .= $_ } + } + } + elsif (/-w/) { $wtime = shift @ARGV } } elsif (!$id && m|^(?:ticket/)?($idlist)$|) { @@ -733,10 +749,10 @@ sub submit { my ($head, $text) = split /\n\n/, $res->content, 2; my ($status, @headers) = split /\n/, $head; - $text =~ s/\n*$/\n/; + $text =~ s/\n*$/\n/ if ($text); # "RT/3.0.1 401 Credentials required" - if ($status !~ m#^RT/\d+(?:\.\d+)+(?:-?\w+)? (\d+) ([\w\s]+)$#) { + if ($status !~ m#^RT/\d+(?:\S+) (\d+) ([\w\s]+)$#) { warn "rt: Malformed RT response from $config{server}.\n"; warn "(Rerun with RTDEBUG=3 for details.)\n" if $config{debug} < 3; exit -1; @@ -812,7 +828,7 @@ sub submit { sub cookie { my ($self) = @_; my $cookie = $self->{sids}{$s}{$u}; - return defined $cookie ? "RT_SID=$cookie" : undef; + return defined $cookie ? "RT_SID_$cookie" : undef; } # Deletes the current session cookie. @@ -835,7 +851,7 @@ sub submit { my ($self, $response) = @_; my $cookie = $response->header("Set-Cookie"); - if (defined $cookie && $cookie =~ /^RT_SID=([0-9A-Fa-f]+);/) { + if (defined $cookie && $cookie =~ /^RT_SID_(.[^;,\s]+=[0-9A-Fa-f]+);/) { $self->{sids}{$s}{$u} = $1; } } @@ -852,7 +868,7 @@ sub submit { while (<F>) { chomp; next if /^$/ || /^#/; - next unless m#^https?://[^ ]+ \w+ [0-9A-Fa-f]+$#; + next unless m#^https?://[^ ]+ \w+ [^;,\s]+=[0-9A-Fa-f]+$#; my ($server, $user, $cookie) = split / /, $_; $sids->{$server}{$user} = $cookie; } @@ -1061,7 +1077,7 @@ sub Form::compose { sub config_from_env { my %env; - foreach my $k ("DEBUG", "USER", "PASSWD", "SERVER") { + foreach my $k ("DEBUG", "USER", "PASSWD", "SERVER", "QUERY", "ORDERBY") { if (exists $ENV{"RT$k"}) { $env{lc $k} = $ENV{"RT$k"}; } @@ -1112,7 +1128,7 @@ sub parse_config_file { chomp; next if (/^#/ || /^\s*$/); - if (/^(user|passwd|server)\s+([^ ]+)$/) { + if (/^(user|passwd|server|query|orderby)\s+(.*)\s?$/) { $cfg{$1} = $2; } else { @@ -1343,6 +1359,8 @@ Text: - server <URL> URL to RT server. - user <username> RT username. - passwd <passwd> RT user's password. + - query <RT Query> Default RT Query for list action + - orderby <order> Default RT order for list action Blank and #-commented lines are ignored. @@ -1357,6 +1375,8 @@ Text: - RTDEBUG Numeric debug level. (Set to 3 for full logs.) - RTCONFIG Specifies a name other than ".rtrc" for the configuration file. + - RTQUERY Default RT Query for rt list + - RTORDERBY Default order for rt list -- @@ -1380,7 +1400,7 @@ Text: be used to specify more than one object of the same type. Note that the list must be a single argument (i.e., no spaces). For example, "user/root,1-3,5,7-10,ams" is a list of ten users; the same list - can also be written as "user/ams,root,1,2,3,5,7,8-20". + can also be written as "user/ams,root,1,2,3,5,7,8-10". Examples: |