-
Notifications
You must be signed in to change notification settings - Fork 5
Add create
command
#139
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
Open
grandeljay
wants to merge
24
commits into
RobinTheHood:feat/mmlc-cli
Choose a base branch
from
grandeljay:create
base: feat/mmlc-cli
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add create
command
#139
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
bf31e7e
feat: add `create` command
grandeljay 693b496
feat: add `archiveName` interaction
grandeljay e496d39
chore: merge `feat/mmlc-cli` into `create`
grandeljay 69a029b
fix: refactor to match newest upstream changes
grandeljay a3b796d
fix: missing arguments
grandeljay badc16a
chore: merge `feat/mmlc-cli` into `create`
grandeljay d6d5d58
refactor: add `HelpRenderer`
grandeljay 8a562e7
refactor: fix indentation
grandeljay 8f87634
chore: merge `feat/mmlc-cli` into `create`
grandeljay 80a5786
refactor: add specialised methods, rename `getPadding`
grandeljay 3ae50ce
fix: remove duplicate command
grandeljay 6f44386
refactor: remove unused method `renderLogo`
grandeljay 208e135
fix: re-add required render methods
grandeljay 118a28f
feat: automatically pad options and description
grandeljay d76011c
refactor: rename property `arguments` to `sections`
grandeljay 42be461
refactor: simply code
grandeljay 38a7d1e
feat: improve `HelpRenderer`
grandeljay d7c3ac7
refactor: remove unused method `leftPad`
grandeljay 1d3e3c7
refactor: remove test option
grandeljay ff06fcd
refactor: let caller print new lines
grandeljay e4c0a99
Merge `feat/mmlc-cli` into `create`
grandeljay 7b12d1e
chore: merge `feat/mmlc-cli` into `create`
grandeljay 63f0497
refactor: move `rightPad` back where it was
grandeljay 1efe045
feat: add create command
grandeljay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,105 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of MMLC - ModifiedModuleLoaderClient. | ||
* | ||
* (c) Robin Wieschendorf <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace RobinTheHood\ModifiedModuleLoaderClient\Cli\Command; | ||
|
||
use RobinTheHood\ModifiedModuleLoaderClient\Cli\HelpRenderer; | ||
use RobinTheHood\ModifiedModuleLoaderClient\Cli\MmlcCli; | ||
use RobinTheHood\ModifiedModuleLoaderClient\ModuleCreator; | ||
|
||
class CommandCreate implements CommandInterface | ||
{ | ||
private const ARGUMENT_ARCHIVE_NAME = 0; | ||
private const ARGUMENT_VENDOR_PREFIX = 1; | ||
|
||
public function __construct() | ||
{ | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return 'create'; | ||
} | ||
|
||
public function run(MmlcCli $cli): void | ||
{ | ||
if ($cli->hasOption('-i') || $cli->hasOption('--interactive')) { | ||
$this->createInteractive($cli); | ||
} else { | ||
$this->create($cli); | ||
} | ||
} | ||
|
||
private function create(MmlcCli $cli): void | ||
{ | ||
$archiveName = $cli->getFilteredArgument(self::ARGUMENT_ARCHIVE_NAME); | ||
$archiveParts = explode('/', $archiveName); | ||
$vendorName = $archiveParts[0] ?? 'MyCompany'; | ||
$moduleName = $archiveParts[1] ?? 'My First Module'; | ||
|
||
if ($cli->hasOption('--prefix')) { | ||
echo $cli->getOption('--prefix'); | ||
} | ||
$vendorPrefix = $cli->getFilteredArgument(self::ARGUMENT_VENDOR_PREFIX); | ||
|
||
$moduleCreator = new ModuleCreator(); | ||
$moduleCreator->createModule($vendorPrefix, $vendorName, $moduleName); | ||
} | ||
|
||
private function createInteractive(MmlcCli $cli): void | ||
{ | ||
$archiveName = $cli->getFilteredArgument(self::ARGUMENT_ARCHIVE_NAME); | ||
|
||
if (!$archiveName) { | ||
$vendorName = ''; | ||
|
||
while (!$vendorName) { | ||
echo "1. What is the vendor name?\n"; | ||
echo " Vendor name: "; | ||
|
||
$vendorName = readline(); | ||
|
||
echo "\n"; | ||
} | ||
|
||
$moduleName = ''; | ||
|
||
while (!$moduleName) { | ||
echo "2. What is the module name?\n"; | ||
echo " Module name: "; | ||
|
||
$moduleName = readline(); | ||
|
||
echo "\n"; | ||
} | ||
|
||
$archiveName = $vendorName . '/' . $moduleName; | ||
|
||
$arguments['archiveName'] = $archiveName; | ||
} | ||
|
||
$this->create($cli); | ||
} | ||
|
||
public function getHelp(MmlcCli $cli): string | ||
{ | ||
$renderer = new HelpRenderer(); | ||
$renderer->setDescription('Creates a new module. Can be done interactively. Read more at https://module-loader.de/documentation.php.'); | ||
$renderer->setUsage('create', '[options] <archiveName>'); | ||
$renderer->addArgument('archiveName', 'The name of the archive (vendorName/moduleName).'); | ||
$renderer->addOption('', 'prefix=VENDOR_PREFIX', 'Usually an abbreviated vendorName. Can also be vendorName.'); | ||
$renderer->addOption('i', 'interactive', 'Whether to create the module interactively (by answering questions).'); | ||
|
||
return $renderer->render(); | ||
grandeljay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
grandeljay marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.