-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split module config from global config
- Loading branch information
Showing
35 changed files
with
551 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.