diff --git a/src/Console/Commands/StarterKitInstall.php b/src/Console/Commands/StarterKitInstall.php index d7db695ef2..cf3864745a 100644 --- a/src/Console/Commands/StarterKitInstall.php +++ b/src/Console/Commands/StarterKitInstall.php @@ -52,7 +52,7 @@ public function handle() return; } - $licenseManager = StarterKitLicenseManager::validate($package, $this->option('license'), $this); + $licenseManager = StarterKitLicenseManager::validate($package, $this->option('license'), $this, $this->input->isInteractive()); if (! $licenseManager->isValid()) { return; diff --git a/src/StarterKits/LicenseManager.php b/src/StarterKits/LicenseManager.php index f5d090af1b..9e1fa4bc04 100644 --- a/src/StarterKits/LicenseManager.php +++ b/src/StarterKits/LicenseManager.php @@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Http; use Statamic\Console\NullConsole; +use function Laravel\Prompts\text; + final class LicenseManager { const OUTPOST_ENDPOINT = 'https://outpost.statamic.com/v3/starter-kits/'; @@ -13,25 +15,27 @@ final class LicenseManager private $package; private $licenseKey; private $console; + private $isInteractive; private $details; private $valid = false; /** * Instantiate starter kit license manager. */ - public function __construct(string $package, ?string $licenseKey = null, ?Command $console = null) + public function __construct(string $package, ?string $licenseKey = null, ?Command $console = null, bool $isInteractive = false) { $this->package = $package; $this->licenseKey = $licenseKey ?? config('statamic.system.license_key'); $this->console = $console ?? new NullConsole; + $this->isInteractive = $isInteractive; } /** * Instantiate starter kit license manager. */ - public static function validate(string $package, ?string $licenceKey = null, ?Command $console = null): self + public static function validate(string $package, ?string $licenceKey = null, ?Command $console = null, bool $isInteractive = false): self { - return (new self($package, $licenceKey, $console))->performValidation(); + return (new self($package, $licenceKey, $console, $isInteractive))->performValidation(); } /** @@ -74,10 +78,18 @@ private function performValidation(): self $marketplaceUrl = "https://statamic.com/starter-kits/{$sellerSlug}/{$kitSlug}"; if (! $this->licenseKey) { - return $this - ->error("License required for [{$this->package}]!") + if (! $this->isInteractive) { + return $this + ->error("License required for [{$this->package}]!") + ->comment('This is a paid starter kit. If you haven\'t already, you may purchase a license at:') + ->comment($marketplaceUrl); + } + + $this ->comment('This is a paid starter kit. If you haven\'t already, you may purchase a license at:') ->comment($marketplaceUrl); + + $this->licenseKey = text('Please enter your license key', required: true); } if ($this->outpostValidatesLicense()) {