Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Create Install Command #118

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0cb1cae
Compile Assets
AlexJump24 Oct 13, 2024
3a983bb
Compile Assets
AlexJump24 Oct 13, 2024
b2f527a
Initial work on the install command to save app settings
AlexJump24 Oct 13, 2024
c21b990
Minor tweaks
AlexJump24 Oct 14, 2024
299e1d9
Add config item ready to set up configuring own database connection f…
AlexJump24 Oct 14, 2024
c32bc4f
Move items out of testbech to install command itself.
AlexJump24 Oct 14, 2024
2fc0720
move migrations higher in chain at least for now
AlexJump24 Oct 14, 2024
a42fea2
Compile Assets
AlexJump24 Oct 14, 2024
760bd43
update
AlexJump24 Oct 15, 2024
c08c450
Write to env file if prompted for configuration
AlexJump24 Oct 16, 2024
a3aeab4
tidy up
AlexJump24 Oct 17, 2024
44c3478
changes from feedback
AlexJump24 Oct 17, 2024
6b153a1
fix pipeline issue
AlexJump24 Oct 17, 2024
0305ec8
Pipeline before passed oddly so not needed
AlexJump24 Oct 18, 2024
44bb282
feedback + tidy up
AlexJump24 Oct 18, 2024
f001b7a
Compile Assets
AlexJump24 Oct 13, 2024
0971029
Initial work on the install command to save app settings
AlexJump24 Oct 13, 2024
fe389a3
Minor tweaks
AlexJump24 Oct 14, 2024
67769aa
Add config item ready to set up configuring own database connection f…
AlexJump24 Oct 14, 2024
419249e
Move items out of testbech to install command itself.
AlexJump24 Oct 14, 2024
612e94e
move migrations higher in chain at least for now
AlexJump24 Oct 14, 2024
5f87f58
Compile Assets
AlexJump24 Oct 14, 2024
9d2411b
update
AlexJump24 Oct 15, 2024
d5c85b4
Write to env file if prompted for configuration
AlexJump24 Oct 16, 2024
4331b0d
tidy up
AlexJump24 Oct 17, 2024
c8baa93
changes from feedback
AlexJump24 Oct 17, 2024
9d7bc2f
fix pipeline issue
AlexJump24 Oct 17, 2024
da9f994
Pipeline before passed oddly so not needed
AlexJump24 Oct 18, 2024
c628bc5
feedback + tidy up
AlexJump24 Oct 18, 2024
fd95eba
Merge branch 'main' into feature/issue-104-install-command
jbrooksuk Nov 30, 2024
e84e1c7
Merge branch 'feature/issue-104-install-command' of https://github.co…
AlexJump24 Dec 27, 2024
3aea0e0
Merge branch 'main' into feature/issue-104-install-command
AlexJump24 Dec 27, 2024
7aecf3e
Merge branch 'main' of https://github.com/AlexJump24/core
AlexJump24 Dec 27, 2024
fccf60f
Merge branch 'main' into feature/issue-104-install-command
AlexJump24 Dec 27, 2024
af31e0a
Add optional create user command
AlexJump24 Dec 27, 2024
790926c
change default
AlexJump24 Dec 27, 2024
4ff5de2
fix stan issues
AlexJump24 Dec 27, 2024
4184a49
Prevent user table being truncated on install in another Laravel project
AlexJump24 Dec 29, 2024
470e982
Change order of things to prevent issues with database connection
AlexJump24 Dec 29, 2024
1c0c332
Add trait to models to overload connection name to use config value f…
AlexJump24 Jan 1, 2025
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
19 changes: 16 additions & 3 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,23 @@ protected function configureDatabaseSettings(AppSettings $settings): AppSettings
)
->filter(fn (ReflectionProperty $property) => array_key_exists($property->getName(), $settings->installable()) )
->each(function (ReflectionProperty $property) use ($settings) {
$description = $property->getAttributes(Description::class)[0]->getArguments()[0];
$descriptionAttribute = $property->getAttributes(Description::class);

if (empty($descriptionAttribute)) {
return;
}

$descriptionAttributeClass = $descriptionAttribute[0]->newInstance();
$default = $descriptionAttributeClass->getDefault();
$required = $descriptionAttributeClass->getRequired();
jbrooksuk marked this conversation as resolved.
Show resolved Hide resolved

if ($required === false) {
return;
}

$value = match($property->getType()?->getName()) {
'bool' => confirm($description ?? $property->getName()),
default => text($description ?? $property->getName(), default: $property->getDefaultValue() ?? '', required: true),
'bool' => confirm($default ?? $property->getName()),
default => text($default ?? $property->getName(), default: $property->getDefaultValue() ?? '', required: true),
};

$settings->{$property->getName()} = $value;
Expand Down
4 changes: 2 additions & 2 deletions src/Settings/AppSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppSettings extends Settings
#[Description('What is the name of your application?')]
public ?string $name = 'Cachet';

#[Description('What is your application about?')]
#[Description('What is your application about?', required: false)]
public ?string $about;

#[Description('Do you want to show support for Cachet?')]
Expand All @@ -32,7 +32,7 @@ class AppSettings extends Settings
#[Description('How many incident days should be shown in the timeline?')]
public int $incident_days = 7;

#[Description('After how many seconds should the status page automatically refresh?')]
#[Description('After how many seconds should the status page automatically refresh?', required: false)]
public ?int $refresh_rate;

#[Description('Should the dashboard login link be shown?')]
Expand Down
12 changes: 11 additions & 1 deletion src/Settings/Attributes/Description.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@
#[Attribute(Attribute::TARGET_PROPERTY)]
final class Description
{
public function __construct(private string $description) {}
public function __construct(private readonly string $default, private readonly bool $required = true) {}

public function getDefault(): string
jbrooksuk marked this conversation as resolved.
Show resolved Hide resolved
{
return $this->default;
}

public function getRequired(): bool
jbrooksuk marked this conversation as resolved.
Show resolved Hide resolved
{
return $this->required;
}
}
4 changes: 0 additions & 4 deletions tests/Unit/Commands/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
->expectsQuestion('Which database connection do you wish to use for Cachet?', 'default')
->expectsQuestion('Do you wish to send anonymous data to cachet to help us understand how Cachet is used?', true)
->expectsQuestion('What is the name of your application?', 'Laravel Envoyer')
->expectsQuestion('What is your application about?', 'Zero downtime deployment tool.')
->expectsConfirmation('Do you want to show support for Cachet?', 'yes')
->expectsQuestion('What timezone is is the application located in?', 'America/New_York')
->expectsConfirmation('Would you like to show your timezone on the status page?', 'yes')
->expectsConfirmation('Would you like to only show the days with disruption?', 'yes')
->expectsQuestion('How many incident days should be shown in the timeline?', 14)
->expectsQuestion('After how many seconds should the status page automatically refresh?', 10)
->expectsConfirmation('Should the dashboard login link be shown?', 'no')
->expectsQuestion('Major outage threshold %', 50)
->expectsOutputToContain('Installing Cachet...')
Expand All @@ -49,13 +47,11 @@

$settings = app(AppSettings::class);
expect($settings->name)->toBe('Laravel Envoyer')
->and($settings->about)->toBe('Zero downtime deployment tool.')
->and($settings->show_support)->toBeTrue()
->and($settings->timezone)->toBe('America/New_York')
->and($settings->show_timezone)->toBeTrue()
->and($settings->only_disrupted_days)->toBeTrue()
->and($settings->incident_days)->toBe(14)
->and($settings->refresh_rate)->toBe(10)
->and($settings->dashboard_login_link)->toBeFalse()
->and($settings->major_outage_threshold)->toBe(50);
});
Expand Down