Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Statamic\Cli;

class Config
{
public static function get($key, $default = null)
{
return static::all()[$key] ?? $default;
}

public static function set($key, $value)
{
if (! $path = static::path()) {
return;
}

$config = array_merge(static::all(), [$key => $value]);

if (! is_dir($dir = dirname($path))) {
@mkdir($dir, 0755, true);
}

@file_put_contents($path, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).PHP_EOL);
}

public static function all()
{
if (! ($path = static::path()) || ! is_file($path)) {
return [];
}

$config = json_decode(@file_get_contents($path), true);

return is_array($config) ? $config : [];
}

public static function path()
{
if (PHP_OS_FAMILY === 'Windows') {
$base = getenv('APPDATA') ?: null;
} elseif ($xdg = getenv('XDG_CONFIG_HOME')) {
$base = $xdg;
} elseif ($home = getenv('HOME')) {
$base = $home.'/.config';
} else {
return null;
}

return $base ? $base.DIRECTORY_SEPARATOR.'statamic'.DIRECTORY_SEPARATOR.'cli.json' : null;
}
}
11 changes: 10 additions & 1 deletion src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -1124,15 +1124,24 @@ protected function showPostInstallInstructions()
*/
protected function askToSpreadJoy()
{
if (! $this->input->isInteractive()) {
if (! $this->input->isInteractive() || Config::get('starred')) {
return $this;
}

$response = select('Would you like to spread the joy of Statamic by starring the repo?', [
$yes = 'Absolutely',
$no = 'Maybe later',
$already = "I've already starred it",
], $no);

if ($response === $already) {
Config::set('starred', true);

$this->output->write(" Thank you! We almost definitely won't ask you next time.".PHP_EOL.PHP_EOL);

return $this;
}

if ($response === $yes) {
if (PHP_OS_FAMILY == 'Darwin') {
exec('open https://github.com/statamic/cms');
Expand Down
Loading