From b512dd6ba4f8b809bba797ed9260b78f2ffe6822 Mon Sep 17 00:00:00 2001 From: Dmitri Gopkalo Date: Fri, 9 Aug 2019 00:07:46 +0300 Subject: - add ability get-binary command to skip the same version downloading --- bin/rr | 16 ++++++++++++---- cmd/rr/cmd/root.go | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) mode change 100644 => 100755 bin/rr diff --git a/bin/rr b/bin/rr old mode 100644 new mode 100755 index 71670ff4..d0363601 --- a/bin/rr +++ b/bin/rr @@ -197,12 +197,20 @@ class RRHelper } if (is_file($finalFile)) { + $version = RRHelper::getVersion(); + $previousVersion = shell_exec($finalFile . ' | awk \'/\'Version:\'/ { gsub(/[^[:digit:]\.]+/, "", $2); printf $2}\''); $output->writeln('RoadRunner binary file already exists!'); $helper = $this->getHelper('question'); - $question = new ConfirmationQuestion('Do you want overwrite it? [Y/n] '); - - if (!$helper->ask($input, $output, $question)) { - return; + if (version_compare($previousVersion, $version) === 0) { + $output->writeln(sprintf('Current version: %s', $previousVersion)); + $question = new ConfirmationQuestion(sprintf('Skip update to the same version: %s ? [Y/n]', $version)); + if ($helper->ask($input, $output, $question)) { + return; + } + } else { + if (!$helper->ask($input, $output, new ConfirmationQuestion('Do you want overwrite it? [Y/n] '))) { + return; + } } } diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go index d6929473..3c2cb8b0 100644 --- a/cmd/rr/cmd/root.go +++ b/cmd/rr/cmd/root.go @@ -52,7 +52,7 @@ var ( SilenceErrors: true, SilenceUsage: true, Short: util.Sprintf( - "RoadRunner, PHP Application Server\nVersion: %s, %s", + "RoadRunner, PHP Application Server\nVersion: %s, %s", Version, BuildTime, ), -- cgit v1.2.3 From 79f7983f1a8f2e0c4743cfcecd8d14c3aa0a6c4d Mon Sep 17 00:00:00 2001 From: Dmitri Gopkalo Date: Fri, 9 Aug 2019 01:06:07 +0300 Subject: - remembered about windows compatibility :) and move solution from shell awk to Perl based regex. --- bin/rr | 11 ++++++++--- cmd/rr/cmd/root.go | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/rr b/bin/rr index d0363601..b62a9851 100755 --- a/bin/rr +++ b/bin/rr @@ -198,17 +198,22 @@ class RRHelper if (is_file($finalFile)) { $version = RRHelper::getVersion(); - $previousVersion = shell_exec($finalFile . ' | awk \'/\'Version:\'/ { gsub(/[^[:digit:]\.]+/, "", $2); printf $2}\''); + $previousVersion = + preg_match('#Version:.+(\d+\.\d+\.\d+)#', (string)shell_exec($finalFile), $mathes) ? + $mathes[1] : ""; $output->writeln('RoadRunner binary file already exists!'); $helper = $this->getHelper('question'); if (version_compare($previousVersion, $version) === 0) { $output->writeln(sprintf('Current version: %s', $previousVersion)); - $question = new ConfirmationQuestion(sprintf('Skip update to the same version: %s ? [Y/n]', $version)); + $question = new ConfirmationQuestion( + sprintf('Skip update to the same version: %s ? [Y/n]', $version) + ); if ($helper->ask($input, $output, $question)) { return; } } else { - if (!$helper->ask($input, $output, new ConfirmationQuestion('Do you want overwrite it? [Y/n] '))) { + $question = new ConfirmationQuestion('Do you want overwrite it? [Y/n]'); + if (!$helper->ask($input, $output, $question)) { return; } } diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go index 3c2cb8b0..d6929473 100644 --- a/cmd/rr/cmd/root.go +++ b/cmd/rr/cmd/root.go @@ -52,7 +52,7 @@ var ( SilenceErrors: true, SilenceUsage: true, Short: util.Sprintf( - "RoadRunner, PHP Application Server\nVersion: %s, %s", + "RoadRunner, PHP Application Server\nVersion: %s, %s", Version, BuildTime, ), -- cgit v1.2.3