[Bps-public-commit] RT-Client-CLI branch, master, updated. 35feab0e4946b691ad10fd000e0d1f226719fb8d
Thomas Sibley
trs at bestpractical.com
Thu Jul 25 12:55:27 EDT 2013
The branch, master has been updated
via 35feab0e4946b691ad10fd000e0d1f226719fb8d (commit)
via c9955344d99d1438fbf4dd461e1e13409aa760e0 (commit)
from 0b28f844d4c72836d4bdb98e92164c9dde20309f (commit)
Summary of changes:
Changes | 4 ++
META.json | 2 +-
Makefile.PL | 2 +-
lib/RT/Client/CLI.pm | 2 +-
script/rt | 133 +++++++++++++++++++++++++++++++++++++--------------
5 files changed, 105 insertions(+), 38 deletions(-)
- Log -----------------------------------------------------------------
commit c9955344d99d1438fbf4dd461e1e13409aa760e0
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Jul 25 09:49:18 2013 -0700
Update to 4.0.14
diff --git a/script/rt b/script/rt
index 165a758..4100d1f 100644
--- a/script/rt
+++ b/script/rt
@@ -472,7 +472,7 @@ sub show {
sub edit {
my ($action) = @_;
my (%data, $type, @objects);
- my ($cl, $text, $edit, $input, $output);
+ my ($cl, $text, $edit, $input, $output, $content_type);
use vars qw(%set %add %del);
%set = %add = %del = ();
@@ -486,6 +486,7 @@ sub edit {
if (/^-e$/) { $edit = 1 }
elsif (/^-i$/) { $input = 1 }
elsif (/^-o$/) { $output = 1 }
+ elsif (/^-ct$/) { $content_type = shift @ARGV }
elsif (/^-t$/) {
$bad = 1, last unless defined($type = get_type_argument());
}
@@ -655,24 +656,54 @@ sub edit {
return 0;
}
+ my @files;
+ @files = @{ vsplit($set{'attachment'}) } if exists $set{'attachment'};
+
my $synerr = 0;
EDIT:
# We'll let the user edit the form before sending it to the server,
# unless we have enough information to submit it non-interactively.
+ if ( $type && $type eq 'ticket' && $text !~ /^Content-Type:/m ) {
+ $text .= "Content-Type: $content_type\n"
+ if $content_type and $content_type ne "text/plain";
+ }
+
if ($edit || (!$input && !$cl)) {
- my $newtext = vi($text);
+ my ($newtext) = vi_form_while(
+ $text,
+ sub {
+ my ($text, $form) = @_;
+ return 1 unless exists $form->[2]{'Attachment'};
+
+ foreach my $f ( @{ vsplit($form->[2]{'Attachment'}) } ) {
+ return (0, "File '$f' doesn't exist") unless -f $f;
+ }
+ @files = @{ vsplit($form->[2]{'Attachment'}) };
+ return 1;
+ },
+ );
+ return $newtext unless $newtext;
# We won't resubmit a bad form unless it was changed.
$text = ($synerr && $newtext eq $text) ? undef : $newtext;
}
+ delete @data{ grep /^attachment_\d+$/, keys %data };
+ my $i = 1;
+ foreach my $file (@files) {
+ $data{"attachment_$i"} = bless([ $file ], "Attachment");
+ $i++;
+ }
+
if ($text) {
my $r = submit("$REST/edit", {content => $text, %data});
if ($r->code == 409) {
# If we submitted a bad form, we'll give the user a chance
# to correct it and resubmit.
if ($edit || (!$input && !$cl)) {
- $text = $r->content;
+ my $content = $r->content . "\n";
+ $content =~ s/^(?!#)/# /mg;
+ $text = $content . $text;
$synerr = 1;
goto EDIT;
}
@@ -738,7 +769,7 @@ sub setcommand {
sub comment {
my ($action) = @_;
- my (%data, $id, @files, @bcc, @cc, $msg, $wtime, $edit);
+ my (%data, $id, @files, @bcc, @cc, $msg, $content_type, $wtime, $edit);
my $bad = 0;
while (@ARGV) {
@@ -747,7 +778,7 @@ sub comment {
if (/^-e$/) {
$edit = 1;
}
- elsif (/^-[abcmw]$/) {
+ elsif (/^-(?:[abcmw]|ct)$/) {
unless (@ARGV) {
whine "No argument specified with $_.";
$bad = 1; last;
@@ -760,6 +791,9 @@ sub comment {
}
push @files, shift @ARGV;
}
+ elsif (/-ct/) {
+ $content_type = shift @ARGV;
+ }
elsif (/-([bc])/) {
my $a = $_ eq "-b" ? \@bcc : \@cc;
@$a = split /\s*,\s*/, shift @ARGV;
@@ -771,7 +805,6 @@ sub comment {
while (<STDIN>) { $msg .= $_ }
}
}
-
elsif (/-w/) { $wtime = shift @ARGV }
}
elsif (!$id && m|^(?:ticket/)?($idlist)$|) {
@@ -793,7 +826,7 @@ sub comment {
my $form = [
"",
- [ "Ticket", "Action", "Cc", "Bcc", "Attachment", "TimeWorked", "Text" ],
+ [ "Ticket", "Action", "Cc", "Bcc", "Attachment", "TimeWorked", "Content-Type", "Text" ],
{
Ticket => $id,
Action => $action,
@@ -801,6 +834,7 @@ sub comment {
Bcc => [ @bcc ],
Attachment => [ @files ],
TimeWorked => $wtime || '',
+ 'Content-Type' => $content_type || 'text/plain',
Text => $msg || '',
Status => ''
}
@@ -809,30 +843,19 @@ sub comment {
my $text = Form::compose([ $form ]);
if ($edit || !$msg) {
- my $error = 0;
- my ($c, $o, $k, $e);
-
- do {
- my $ntext = vi($text);
- return if ($error && $ntext eq $text);
- $text = $ntext;
- $form = Form::parse($text);
- $error = 0;
-
- ($c, $o, $k, $e) = @{ $form->[0] };
- if ($e) {
- $error = 1;
- $c = "# Syntax error.";
- goto NEXT;
- }
- elsif (!@$o) {
- return 0;
- }
- @files = @{ vsplit($k->{Attachment}) };
-
- NEXT:
- $text = Form::compose([[$c, $o, $k, $e]]);
- } while ($error);
+ my ($tmp) = vi_form_while(
+ $text,
+ sub {
+ my ($text, $form) = @_;
+ foreach my $f ( @{ vsplit($form->[2]{'Attachment'}) } ) {
+ return (0, "File '$f' doesn't exist") unless -f $f;
+ }
+ @files = @{ vsplit($form->[2]{'Attachment'}) };
+ return 1;
+ },
+ );
+ return $tmp unless $tmp;
+ $text = $tmp;
}
my $i = 1;
@@ -1466,6 +1489,43 @@ sub read_passwd {
return $passwd;
}
+sub vi_form_while {
+ my $text = shift;
+ my $cb = shift;
+
+ my $error = 0;
+ my ($c, $o, $k, $e);
+ do {
+ my $ntext = vi($text);
+ return undef if ($error && $ntext eq $text);
+
+ $text = $ntext;
+
+ my $form = Form::parse($text);
+ $error = 0;
+ ($c, $o, $k, $e) = @{ $form->[0] };
+ if ( $e ) {
+ $error = 1;
+ $c = "# Syntax error.";
+ goto NEXT;
+ }
+ elsif (!@$o) {
+ return 0;
+ }
+
+ my ($status, $msg) = $cb->( $text, [$c, $o, $k, $e] );
+ unless ( $status ) {
+ $error = 1;
+ $c = "# $msg";
+ }
+
+ NEXT:
+ $text = Form::compose([[$c, $o, $k, $e]]);
+ } while ($error);
+
+ return $text;
+}
+
sub vi {
my ($text) = @_;
my $editor = $ENV{EDITOR} || $ENV{VISUAL} || "vi";
@@ -1525,15 +1585,15 @@ sub vsplit {
}
push @words, $s;
}
- elsif ( $a =~ /^q{/ ) {
+ elsif ( $a =~ /^q\{/ ) {
my $s = $a;
- while ( $a !~ /}$/ ) {
+ while ( $a !~ /\}$/ ) {
( $a, $b ) =
split /\s*,\s*/, $b, 2;
$s .= ',' . $a;
}
- $s =~ s/^q{/'/;
- $s =~ s/}/'/;
+ $s =~ s/^q\{/'/;
+ $s =~ s/\}/'/;
push @words, $s;
}
else {
@@ -2273,12 +2333,14 @@ Text:
-S var=val
Submits the specified variable with the request.
-t type Specifies object type.
+ -ct content-type Specifies content type of message(tickets only).
Examples:
# Interactive (starts $EDITOR with a form).
rt edit ticket/3
rt create -t ticket
+ rt create -t ticket -ct text/html
# Non-interactive.
rt edit ticket/1-3 add cc=foo at example.com set priority=3 due=tomorrow
@@ -2310,6 +2372,7 @@ Text:
Options:
-m <text> Specify comment text.
+ -ct <content-type> Specify content-type of comment text.
-a <file> Attach a file to the comment. (May be used more
than once to attach multiple files.)
-c <addrs> A comma-separated list of Cc addresses.
commit 35feab0e4946b691ad10fd000e0d1f226719fb8d
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Jul 25 09:55:25 2013 -0700
4.0.14
diff --git a/Changes b/Changes
index d2b7c5e..063aa62 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,10 @@ Revision history for RT-Client-CLI
{{$NEXT}}
+4.0.14 2013-07-25 09:53:19 PDT
+ - Allow creation of text/html correspondence/comments via -ct
+ - Support for attaching files on create
+
4.0.13.1 2013-06-21 17:18:58 PDT
- Switch installer to ExtUtils::MakeMaker for less deps
diff --git a/META.json b/META.json
index b5017a6..514628c 100644
--- a/META.json
+++ b/META.json
@@ -80,7 +80,7 @@
"web" : "https://github.com/bestpractical/rt-client-cli"
}
},
- "version" : "4.0.13.1",
+ "version" : "4.0.14",
"x_contributors" : [
"Thomas Sibley <trs at bestpractical.com>"
]
diff --git a/Makefile.PL b/Makefile.PL
index dbf0e84..ecfb30c 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -36,7 +36,7 @@ my %WriteMakefileArgs = (
"TEST_REQUIRES" => {
"Test::More" => "0.88"
},
- "VERSION" => "4.0.13.1",
+ "VERSION" => "4.0.14",
"test" => {
"TESTS" => "t/*.t"
}
diff --git a/lib/RT/Client/CLI.pm b/lib/RT/Client/CLI.pm
index 1d99ef5..9f64288 100644
--- a/lib/RT/Client/CLI.pm
+++ b/lib/RT/Client/CLI.pm
@@ -3,7 +3,7 @@ package RT::Client::CLI;
use strict;
use warnings;
use 5.008_005;
-our $VERSION = '4.0.13.1';
+our $VERSION = '4.0.14';
1;
__END__
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list