Skip to content

Commit

Permalink
feat(config): add root setting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocesarato committed Jan 24, 2021
1 parent ecce109 commit 2ad49c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public function generate(InputInterface $input, SymfonyStyle $output): int

$autoBump = false;

if (empty($root) || !is_dir($root)) {
$root = $this->config->getRoot();
}

// Set working directory
chdir($root);

Expand Down
29 changes: 29 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

class Configuration
{
/**
* Working dir.
*
* @var string
*/
public $root = './';

/**
* Changelog filename.
*
Expand Down Expand Up @@ -82,6 +89,7 @@ class Configuration
*/
public function __construct(array $settings = [])
{
$this->setRoot();
$this->setTypes($this->preset);
$this->fromArray($settings);
}
Expand Down Expand Up @@ -112,6 +120,7 @@ public function fromArray(array $array)
}

$defaults = [
'root' => null,
'headerTitle' => $this->getHeaderTitle(),
'headerDescription' => $this->getHeaderDescription(),
'path' => $this->getPath(),
Expand Down Expand Up @@ -144,6 +153,7 @@ public function fromArray(array $array)
// Add breaking changes
$params['preset'] = array_merge($this->breakingPreset, $params['preset']);

$this->setRoot($params['root']);
$this->setPath($params['path']);
$this->setIgnorePatterns($params['ignorePatterns']);
$this->setIgnoreTypes($params['ignoreTypes']);
Expand Down Expand Up @@ -304,4 +314,23 @@ public function getIgnoreTypes(): array
{
return $this->ignoreTypes;
}

public function getRoot(): string
{
return $this->root;
}

/**
* @param string $root
*/
public function setRoot(?string $root = null): Configuration
{
if (empty($root) || !is_dir($root)) {
$root = getcwd();
}

$this->root = $root;

return $this;
}
}
2 changes: 1 addition & 1 deletion src/DefaultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function configure()
->setDescription('Generate changelogs and release notes from a project\'s commit messages' .
'and metadata and automate versioning with semver.org and conventionalcommits.org')
->setDefinition([
new InputArgument('path', InputArgument::OPTIONAL, 'Specify the path directory where generate changelog', getcwd()),
new InputArgument('path', InputArgument::OPTIONAL, 'Specify the path directory where generate changelog'),
new InputOption('config', null, InputOption::VALUE_REQUIRED, 'Specify the configuration file path'),
new InputOption('commit', 'c', InputOption::VALUE_NONE, 'Commit the new release once changelog is generated'),
new InputOption('amend', 'a', InputOption::VALUE_NONE, 'Amend commit the new release once changelog is generated'),
Expand Down

0 comments on commit 2ad49c5

Please sign in to comment.