Skip to content

Commit 22aee9b

Browse files
jasonvargaclaude
andauthored
Add option to remember stars (#119)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent bbcd5d4 commit 22aee9b

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

‎src/Config.php‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Statamic\Cli;
4+
5+
class Config
6+
{
7+
public static function get($key, $default = null)
8+
{
9+
return static::all()[$key] ?? $default;
10+
}
11+
12+
public static function set($key, $value)
13+
{
14+
if (! $path = static::path()) {
15+
return;
16+
}
17+
18+
$config = array_merge(static::all(), [$key => $value]);
19+
20+
if (! is_dir($dir = dirname($path))) {
21+
@mkdir($dir, 0755, true);
22+
}
23+
24+
@file_put_contents($path, json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).PHP_EOL);
25+
}
26+
27+
public static function all()
28+
{
29+
if (! ($path = static::path()) || ! is_file($path)) {
30+
return [];
31+
}
32+
33+
$config = json_decode(@file_get_contents($path), true);
34+
35+
return is_array($config) ? $config : [];
36+
}
37+
38+
public static function path()
39+
{
40+
if (PHP_OS_FAMILY === 'Windows') {
41+
$base = getenv('APPDATA') ?: null;
42+
} elseif ($xdg = getenv('XDG_CONFIG_HOME')) {
43+
$base = $xdg;
44+
} elseif ($home = getenv('HOME')) {
45+
$base = $home.'/.config';
46+
} else {
47+
return null;
48+
}
49+
50+
return $base ? $base.DIRECTORY_SEPARATOR.'statamic'.DIRECTORY_SEPARATOR.'cli.json' : null;
51+
}
52+
}

‎src/NewCommand.php‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,15 +1124,24 @@ protected function showPostInstallInstructions()
11241124
*/
11251125
protected function askToSpreadJoy()
11261126
{
1127-
if (! $this->input->isInteractive()) {
1127+
if (! $this->input->isInteractive() || Config::get('starred')) {
11281128
return $this;
11291129
}
11301130

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

1137+
if ($response === $already) {
1138+
Config::set('starred', true);
1139+
1140+
$this->output->write(" Thank you! We almost definitely won't ask you next time.".PHP_EOL.PHP_EOL);
1141+
1142+
return $this;
1143+
}
1144+
11361145
if ($response === $yes) {
11371146
if (PHP_OS_FAMILY == 'Darwin') {
11381147
exec('open https://github.com/statamic/cms');

0 commit comments

Comments
 (0)