Skip to content

Commit

Permalink
Migrate to namespaced argv
Browse files Browse the repository at this point in the history
Split module config from global config
  • Loading branch information
ralflang committed Dec 27, 2023
1 parent cd8d802 commit dadc2fe
Show file tree
Hide file tree
Showing 35 changed files with 551 additions and 474 deletions.
96 changes: 96 additions & 0 deletions src/Cli/ArgvParserBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

declare(strict_types=1);

namespace Horde\Components\Cli;

use Horde\Components\Constants;
use Horde\Argv\Parser;
use Horde\Argv\Option;
use Horde\Argv\OptionGroup;
use Horde\Argv\Values;
use Horde\Components\Module;
/**
* The Global Argv Parser with the fixed, always present options.
*
* It seals the actual horde/argv Parser and only hands out copies.
*/
class ArgvParserBuilder
{
public function __construct(
/**
* The command line argument parser.
*/
) {
$this->reset();
}

public function reset(): self
{
$this->parser = new Parser;
return $this;
}

public function withGlobalOptions(): self
{
$this->parser->addOption(
new Option(
'-c',
'--config',
['action' => 'store', 'help' => sprintf(
'the path to the configuration file for the components script (default : %s).',
Constants::getConfigFile()
), 'default' => Constants::getConfigFile()]
)
);
$this->parser->addOption(
new Option(
'-q',
'--quiet',
['action' => 'store_true', 'help' => 'Reduce output to a minimum']
)
);
$this->parser->addOption(
new Option(
'-v',
'--verbose',
['action' => 'store_true', 'help' => 'Reduce output to a maximum']
)
);
$this->parser->addOption(
new Option(
'-P',
'--pretend',
['action' => 'store_true', 'help' => 'Just pretend and indicate what would be done rather than performing the action.']
)
);
$this->parser->addOption(
new Option(
'-N',
'--nocolor',
['action' => 'store_true', 'help' => 'Avoid colors in the output']
)
);
$this->parser->addOption(
new Option(
'-d',
'--working-dir',
['action' => 'store', 'help' => 'The working directory for the command']
)
);
return $this;
}

public function withModuleOptions(Module $module): self
{
$group = new OptionGroup($this->parser, $module->getOptionGroupTitle(), $module->getOptionGroupDescription());
$group->addOptions($module->getOptionGroupOptions());
$this->parser->addOptionGroup($group);
return $this;
}

public function build(): Parser
{
return $this->parser;
}
}
127 changes: 0 additions & 127 deletions src/Cli/GlobalArgvParser.php

This file was deleted.

6 changes: 5 additions & 1 deletion src/Cli/ModuleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Horde\Cli\Modular\ModuleProvider as CliModuleProvider;
use Horde\Cli\Modular\Module;
use Horde\Cli\Modular\Modules;
use Horde\Components\Module\Composer;
use Horde\Components\Module\Package;

/**
* Components tool specific, context aware module provider
Expand Down Expand Up @@ -39,8 +41,10 @@ public function getModules(): Modules
{
return new Modules([
$this->injector->get(ConfigModule::class),
$this->injector->get(Composer::class),
$this->injector->get(Git::class),
$this->injector->get(Help::class)
$this->injector->get(Help::class),
$this->injector->get(Package::class)
]);
}
}
9 changes: 7 additions & 2 deletions src/Component/ComponentDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use Horde\Components\Helper\Root as HelperRoot;
use Horde\Components\Pear\Environment as PearEnvironment;
use Horde\Components\RuntimeContext\CurrentWorkingDirectory;
use stdClass;
use Stringable;

class ComponentDirectory
class ComponentDirectory implements Stringable
{
private string $fullPath;

Expand All @@ -31,4 +31,9 @@ public function hasComposerJson(): bool
{
return is_file($this->fullPath . '/composer.json');
}

public function __toString()
{
return $this->fullPath;
}
}
Loading

0 comments on commit dadc2fe

Please sign in to comment.