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

CLI-1191: Support XDG Base Dir #1619

Merged
merged 2 commits into from
Oct 31, 2023
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
3 changes: 3 additions & 0 deletions bin/acli
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ $input = new ArgvInput();
if (!getenv('HOME')) {
putenv('HOME=' . LocalMachineHelper::getHomeDir());
}
if (!getenv('ACLI_HOME')) {
putenv('ACLI_HOME=' . LocalMachineHelper::getConfigDir());
}
$kernel = new Kernel('prod', false);

// Handle a clear-kernel-cache pseudo command. This isn't implemented as a true console
Expand Down
2 changes: 1 addition & 1 deletion config/prod/services.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
parameters:
env(ACLI_REPO_ROOT): "%kernel.project_dir%"
app.data_dir: "%env(HOME)%/.acquia"
app.data_dir: "%env(ACLI_HOME)%"
app.project_dir: "%env(ACLI_REPO_ROOT)%"
app.ssh_dir: "%env(HOME)%/.ssh"
app.acli_config_filename: '.acquia-cli.yml'
Expand Down
12 changes: 12 additions & 0 deletions src/Helpers/LocalMachineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,18 @@ public static function getHomeDir(): string {
return $home;
}

public static function getConfigDir(): string {
$home = self::getHomeDir();
$legacyDir = Path::join($home, '.acquia');
if (file_exists($legacyDir)) {
return $legacyDir;
}
if ($xdgHome = getenv('XDG_CONFIG_HOME')) {
return Path::join($xdgHome, 'acquia');
}
return Path::join($home, '.config', 'acquia');
}

/**
* Get the project root directory for the working directory.
*
Expand Down
21 changes: 21 additions & 0 deletions tests/phpunit/src/Misc/LocalMachineHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,25 @@ public function testHomeDirWindowsMing(): void {
LocalMachineHelper::getHomeDir();
}

public function testConfigDirLegacy(): void {
self::setEnvVars(['HOME' => 'vfs://root']);
$configDir = LocalMachineHelper::getConfigDir();
$this->assertEquals('vfs://root/.acquia', $configDir);
}

public function testConfigDirFromXdg(): void {
self::setEnvVars(['XDG_CONFIG_HOME' => 'vfs://root/.config']);
$configDir = LocalMachineHelper::getConfigDir();
$this->assertEquals('vfs://root/.config/acquia', $configDir);
}

public function testConfigDirDefault(): void {
self::setEnvVars(['HOME' => 'vfs://root']);
self::unsetEnvVars(['XDG_CONFIG_HOME']);
unlink('vfs://root/.acquia/cloud_api.conf');
rmdir('vfs://root/.acquia');
$configDir = LocalMachineHelper::getConfigDir();
$this->assertEquals('vfs://root/.config/acquia', $configDir);
}

}
2 changes: 1 addition & 1 deletion tests/phpunit/src/TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected function setUp(): void {
$this->vfsRoot = vfsStream::setup();
$this->projectDir = vfsStream::newDirectory('project')->at($this->vfsRoot)->url();
$this->sshDir = vfsStream::newDirectory('ssh')->at($this->vfsRoot)->url();
$this->dataDir = vfsStream::newDirectory('data')->at($this->vfsRoot)->url();
$this->dataDir = vfsStream::newDirectory('.acquia')->at($this->vfsRoot)->url();
$this->cloudConfigFilepath = Path::join($this->dataDir, 'cloud_api.conf');
$this->acliConfigFilename = '.acquia-cli.yml';
$this->acliConfigFilepath = Path::join($this->projectDir, $this->acliConfigFilename);
Expand Down