Skip to content

Commit

Permalink
Fix setup (#133)
Browse files Browse the repository at this point in the history
* Fixes first time invocation of config files.

* Switches logic in setup to prevent asking questions twice.
  • Loading branch information
typhonius authored Nov 20, 2020
1 parent 3370841 commit f8a549a
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/Commands/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,14 @@ public function setup(Config $config)
foreach ($configFiles as $type => $location) {
$this->yell(sprintf('%s configuration (%s)', ucfirst($type), $location));

if (
file_exists($location) && $this->confirm(
sprintf('Would you like to regenerate the %s configuration file', $type)
)
) {
$this->createConfigYaml($location);
} elseif (
$this->confirm(
sprintf('%s configuration file not found. Would you like to add one?', ucfirst($type))
)
) {
$this->createConfigYaml($location);
if (file_exists($location)) {
if ($this->confirm(sprintf('Would you like to regenerate the %s configuration file', $type))) {
$this->createConfigYaml($location);
}
} else {
if ($this->confirm(sprintf('%s configuration file not found. Would you like to add one?', ucfirst($type)))) {
$this->createConfigYaml($location);
}
}
}
}
Expand Down Expand Up @@ -112,19 +108,18 @@ private function createConfigYaml($location)
'format' => 'Y-m-d H:i:s',
'taskwait' => 5,
'timeout' => 300,
'configsyncdir' => 'sync',
],
];

$yaml = Yaml::dump($config, 3, 2);

if (!is_dir(dirname($location))) {
mkdir(dirname($location), 700);
mkdir(dirname($location), 0700);
}

if (!is_writable($location) && !@chmod($location, 0644)) {
$this->yell(sprintf('%s is not writeable', ucfirst($location)), 40, 'red');
} elseif (file_put_contents($location, $yaml)) {
if (!is_writable(dirname($location)) && !@chmod(dirname($location), 0700)) {
$this->yell(sprintf('%s is not writeable', dirname($location)), 40, 'red');
} elseif (file_put_contents($location, $yaml) && @chmod($location, 0644)) {
$this->say(sprintf('Configuration file written to %s', $location));
} else {
$this->say('Unable to write configuration file.');
Expand Down

0 comments on commit f8a549a

Please sign in to comment.