aboutsummaryrefslogtreecommitdiff
path: root/Plugin
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2019-03-30 15:36:17 +1300
committerDavid Phillips <david@sighup.nz>2019-03-30 15:43:16 +1300
commitf42b0ba740d6a1ec11404e707c4b047e34b9013c (patch)
tree5c2e78b54075b4b3922d47b09cb13ff1867b740e /Plugin
parent9a920fb861b87e63066b068cdc105993d93f5bbf (diff)
downloadidalius-f42b0ba740d6a1ec11404e707c4b047e34b9013c.tar.xz
Convert: Don't use interactive mode
Diffstat (limited to 'Plugin')
-rwxr-xr-xPlugin/Convert.pm19
1 files changed, 14 insertions, 5 deletions
diff --git a/Plugin/Convert.pm b/Plugin/Convert.pm
index c830628..75f4ba0 100755
--- a/Plugin/Convert.pm
+++ b/Plugin/Convert.pm
@@ -19,21 +19,30 @@ sub convert {
my $from = (split / to /, $rest)[0];
my $to = (split / to /, $rest)[1];
- return "Syntax: convert <from> to <to>\n" unless ($from and $to);
+ return "Syntax: convert <from> [to <to>]\n" unless ($from);
my ($out, $in);
- my $pid = open2($out, $in, 'units', '-1', '--compact', '--quiet');
+ my $pid;
+ if ($to) {
+ $pid = open2($out, $in, 'units', '-1', '--compact', '--quiet', $from, $to);
+ } else {
+ $pid = open2($out, $in, 'units', '-1', '--compact', '--quiet', $from);
+ }
- print $in "$from\n$to\n";
my $converted = <$out>;
chomp $converted;
close($in);
waitpid($pid, 0);
+
my $exit_status = $? >> 8;
# `units` doesn't actually seem to set this non-zero, but use it anyway
- return "Conversion error" if $exit_status;
+ return "Error: $converted" if $exit_status;
- return "Converted: $converted\n";
+ if ($to) {
+ return "Convert $from -> $to: $converted\n";
+ } else {
+ return "Define $from: $converted\n";
+ }
}
1;