]> git.proxmox.com Git - pve-common.git/blobdiff - data/PVE/Tools.pm
add split_args helper function
[pve-common.git] / data / PVE / Tools.pm
index 78d7b9f2140026d4d6d1d4142773a768a05b017d..5cd8460db707bbef381a02611afa188ba982a6a0 100644 (file)
@@ -709,4 +709,30 @@ sub shellquote {
     return $str;
 }
 
+# a clumsy way to split an shell argument string into an array,
+# we simply pass it to the cli (exec call)
+# fixme: use Text::ParseWords::shellwords() ?
+sub split_args {
+    my ($str) = @_;
+
+    my $args = [];
+
+    return $args if !$str;
+
+    my $cmd = 'perl -e \'foreach my $a (@ARGV) { print "$a\n"; } \' -- ' . $str;
+
+    eval {
+       run_command($cmd, outfunc => sub {
+           my $data = shift;
+           push @$args, $data;
+       });
+    };
+
+    my $err = $@;
+
+    die "unable to parse args: $str\n" if $err;
+
+    return $args;
+}
+
 1;