[Bps-public-commit] Prophet branch, master, updated. 0.69_01-40-g624bfa8
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Thu Sep 3 11:16:20 EDT 2009
The branch, master has been updated
via 624bfa8a956d74a802fe06722f2086e67f17f99d (commit)
from 91e23eafc9923049b833c6a87ccebb8c0c412e39 (commit)
Summary of changes:
lib/Prophet/CLI.pm | 72 +++-------------------------------------------------
1 files changed, 4 insertions(+), 68 deletions(-)
- Log -----------------------------------------------------------------
commit 624bfa8a956d74a802fe06722f2086e67f17f99d
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Sep 3 23:16:14 2009 +0800
remove the wheels I reinvented: there is Text::ParseWords
diff --git a/lib/Prophet/CLI.pm b/lib/Prophet/CLI.pm
index e371faf..5146cbb 100644
--- a/lib/Prophet/CLI.pm
+++ b/lib/Prophet/CLI.pm
@@ -100,74 +100,10 @@ sub run_one_command {
# we don't want to recursively call if people stupidly write
# alias pull --local = pull --local
next if ( $command eq $ori_cmd );
- my @args;
-
- # parse command string to @args
- # e.g. "ticket search --regex='foo bar'" should be parsed to
- # ['ticket', 'search', '--regex=foo bar']
- # "ticket search --regex 'foo bar'" should be parsed to
- # ['ticket', 'search', '--regex', 'foo bar']
-
- # TODO the following parse stuff is ugly,
- # but I haven't found a better way.
- # may the force be with you
- {
- my $text = $command;
- $text =~ s/^\s+//g;
-
- # \\\\ is too ambiguous, let's substitute it
- $text =~ s/\\\\/LLLUUUPPPIIINNNIII/g;
-
- # we only handle ' and "
- my %need_balance = ( single => 0, double => 0 );
- my $deep;
- while ($text) {
- $deep++;
- my ( $extracted, $remainder );
- if ( $text =~ /^(\S+)(.*)/ ) {
- $extracted = $1;
- $remainder = $2;
- }
- $need_balance{single}++ while $extracted =~ /(?<!\\)'/g;
- $need_balance{double}++ while $extracted =~ /(?<!\\)"/g;
-
- # search $reminder to make $extracted balanced.
- while ($need_balance{single} % 2
- || $need_balance{double} % 2 )
- {
- $deep++;
- die "parse $command error: unbalanced quotes"
- unless $remainder =~ /\S/;
- my ( $e, $r );
- if ( $remainder =~ /^(\s*\S+)(.*)/ ) {
- $e = $1;
- $r = $2;
- }
- $need_balance{single}++ while $e =~ /(?<!\\)'/g;
- $need_balance{double}++ while $e =~ /(?<!\\)"/g;
- $extracted .= $e;
- $remainder = $r;
- die "too deep to parse $command" if $deep > 100;
- }
- $text = $remainder;
- $text =~ s/^\s+//g;
- push @args, $extracted;
- die "too deep to parse $command" if $deep > 100;
- }
-
- for (@args) {
-
- # e.g. remove ' in --regex='foo bar'
- s{=(['"])(.*)\1$}{=$2};
-
- # e.g. remove ' in --regex 'foo bar'
- s{^(['"])(.*)\1$}{$2};
-
- # substitute back
- s/LLLUUUPPPIIINNNIII/\\\\/g;
- }
- }
- return $self->run_one_command( @args );
+ require Text::ParseWords; qw(shellwords);
+ my @args = Text::ParseWords::shellwords( $command );
+ return $self->run_one_command(
+ Text::ParseWords::shellwords($command) );
}
}
# really, we shouldn't be doing this stuff from the command dispatcher
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list