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

Adds DIRECTORY_SEPARATOR and USERPROFILE for Windows usage. #57

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 5 additions & 2 deletions src/Cli/AcquiaCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(
InputInterface $input = null,
OutputInterface $output = null
) {
if ($file = file_get_contents(dirname(dirname(__DIR__)) . '/VERSION')) {
if ($file = file_get_contents(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'VERSION')) {
$version = trim($file);
} else {
throw new \Exception('No VERSION file');
Expand Down Expand Up @@ -108,7 +108,10 @@ public function __construct(

$discovery = new CommandFileDiscovery();
$discovery->setSearchPattern('*Command.php');
$commandClasses = $discovery->discover(dirname(__DIR__) . '/Commands', '\AcquiaCli\Commands');
$commandClasses = $discovery->discover(
dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Commands',
'\AcquiaCli\Commands'
);

// Instantiate Robo Runner.
$this->runner = new RoboRunner();
Expand Down
24 changes: 22 additions & 2 deletions src/Cli/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public function __construct($root)
$loader = new YamlConfigLoader();
$processor = new ConfigProcessor();

$homeDir = getenv('HOME');
$home = self::getHome();

$defaultConfig = join(DIRECTORY_SEPARATOR, [dirname(dirname(__DIR__)), 'default.acquiacli.yml']);
$globalConfig = join(DIRECTORY_SEPARATOR, [$homeDir, '.acquiacli', 'acquiacli.yml']);
$globalConfig = join(DIRECTORY_SEPARATOR, [$home, '.acquiacli', 'acquiacli.yml']);
$projectConfig = join(DIRECTORY_SEPARATOR, [$root, 'acquiacli.yml']);

$processor->extend($loader->load($defaultConfig));
Expand All @@ -34,4 +35,23 @@ public function __construct($root)
$this->set('config.project', $projectConfig);
$this->set('config.global', $globalConfig);
}

public static function isWindows()
{
return stripos(PHP_OS, 'WIN') === 0;
}

public static function getHome()
{
$home = getenv('HOME');
if (self::isWindows()) {
$home = getenv('USERPROFILE');
}

if (!$home) {
throw new \Exception('Home directory not found.');
}

return $home;
}
}
2 changes: 1 addition & 1 deletion src/Commands/DbBackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function dbBackupDownload(
throw new \Exception('Unable to make temporary file.');
}
} else {
$location = sprintf("%s/%s.sql.gz", $opts['path'], $backupName);
$location = sprintf("%s%s%s.sql.gz", $opts['path'], DIRECTORY_SEPARATOR, $backupName);
}

$this->say(sprintf('Downloading database backup to %s', $location));
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/DrushAliasesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AcquiaCli\Commands;

use AcquiaCloudApi\Endpoints\Account;
use AcquiaCli\Cli\Config;

/**
* Class DrushAliasesCommand
Expand Down Expand Up @@ -33,10 +34,9 @@ public function downloadDrushAliases(Account $accountAdapter, $options = ['insta
)
)
) {
if (!$home = getenv('HOME')) {
throw new \Exception('Home directory not found.');
}
$drushDirectory = $home . '/.drush';
$home = Config::getHome();

$drushDirectory = join(DIRECTORY_SEPARATOR, [$home, '.drush']);
if (!is_dir($drushDirectory)) {
mkdir($drushDirectory, 0700);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/LogsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function logDownload(
throw new \Exception('Unable to make temporary file.');
}
} else {
$location = sprintf("%s/%s.tar.gz", $opts['path'], $backupName);
$location = sprintf("%s%s%s.tar.gz", $opts['path'], DIRECTORY_SEPARATOR, $backupName);
}

if (file_put_contents($location, $log, LOCK_EX)) {
Expand Down
10 changes: 6 additions & 4 deletions src/Commands/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ class SetupCommand extends Tasks
*/
public function setup(Config $config)
{
$configFiles = [
'global' => $config->get('config.global'),
'project' => $config->get('config.project'),
];
$configFiles = ['global' => $config->get('config.global')];

// Do not include project configuration if this is running in a Phar.
if (!\Phar::running()) {
$configFiles['project'] = $config->get('config.project');
}

foreach ($configFiles as $type => $location) {
$this->say(sprintf('Checking %s configuration at %s', $type, $location));
Expand Down