From 774642c6f27cc6a6428787f378656ac144daefcf Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 12 Feb 2022 03:59:21 -0800 Subject: [PATCH 1/3] InitCommand - If the new `key` and `` don't match, prompt for confirmation --- src/CRM/CivixBundle/Command/InitCommand.php | 33 +++++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/CRM/CivixBundle/Command/InitCommand.php b/src/CRM/CivixBundle/Command/InitCommand.php index 9aa9317a..af55b033 100644 --- a/src/CRM/CivixBundle/Command/InitCommand.php +++ b/src/CRM/CivixBundle/Command/InitCommand.php @@ -32,11 +32,13 @@ protected function configure() { "Create a new CiviCRM Module-Extension (Regenerate module.civix.php if ext.name not specified)\n" . "\n" . "Identification:\n" . - " Keys must be lowercase alphanumeric (with dashes and underscores allowed).\n" . + " Keys should be lowercase alphanumeric with underscores. Additionally, dots and dashes\n" . + " are also legal - but they are discouraged for new extensions.\n" . "\n" . - " Optionally, you may use a Java-style prefix (reverse domain name).\n" . + " Historically, the key often included a Java-style prefix (reverse domain name).\n" . + " The benefit of the prefix was mostly cosmetic. It did not provide consistent\n" . + " isolation between similarly named extensions. It is now recommended to skip\n" . "\n" . - " However, the prefix is mostly cosmetic. The base part of the key should be globally unique.\n" . "\n" . "Examples:\n" . " civix generate:module foo-bar\n" . @@ -103,6 +105,31 @@ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Unrecognized license (' . $ctx['license'] . ')'); return; } + + if ($ctx['fullName'] !== $ctx['mainFile']) { + $output->writeln(""); + $output->writeln("Simpler names are simpler."); + $output->writeln(""); + $output->writeln("CiviCRM extensions formally have two names, the \"key\" and the \"file\"."); + $output->writeln("Some APIs require the \"file\", and others require the \"key\"."); + $output->writeln(""); + $output->writeln(" Key: {$ctx['fullName']}"); + $output->writeln(" File: {$ctx['mainFile']}"); + $output->writeln(""); + $output->writeln("\"File\" names must meet tighter constraints than \"key\" names."); + $output->writeln(""); + $output->writeln("With the current request, the names will be different. This is"); + $output->writeln("entirely valid, although you need to know which is which."); + $output->writeln(""); + $output->writeln("Many developers find it simpler to use matching names. If you would"); + $output->writeln("like matching names, then cancel and try another name (without any"); + $output->writeln("dots or dashes)."); + $output->writeln(""); + if (!$this->confirm($input, $output, "Continue with current name? [Y/n] ")) { + return 1; + } + } + $ext = new Collection(); $output->writeln("Initalize module " . $ctx['fullName'] . ""); From d01c164d1d34e329e87d42e72a32d547ae62a23d Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 14 Feb 2022 13:49:18 -0800 Subject: [PATCH 2/3] InitCommand - Copy-editing --- src/CRM/CivixBundle/Command/InitCommand.php | 49 +++++++++++---------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/CRM/CivixBundle/Command/InitCommand.php b/src/CRM/CivixBundle/Command/InitCommand.php index af55b033..f8aea824 100644 --- a/src/CRM/CivixBundle/Command/InitCommand.php +++ b/src/CRM/CivixBundle/Command/InitCommand.php @@ -22,27 +22,29 @@ protected function configure() { Services::templating(); $this ->setName('generate:module') - ->setDescription('Create a new CiviCRM Module-Extension (Regenerate module.civix.php if ext.name not specified)') - ->addArgument('key', InputArgument::OPTIONAL, "Extension identifier (Ex: \"foo-bar\" or \"org.example.foo-bar\")") + ->setDescription('Create a new CiviCRM Module-Extension (Regenerate module.civix.php if \"key\" not specified)') + ->addArgument('key', InputArgument::OPTIONAL, "Extension identifier (Ex: \"foo_bar\" or \"org.example.foo-bar\")") ->addOption('enable', NULL, InputOption::VALUE_REQUIRED, 'Whether to auto-enable the new module (yes/no/ask)', 'ask') ->addOption('license', NULL, InputOption::VALUE_OPTIONAL, 'License for the extension (' . implode(', ', $this->getLicenses()) . ')', $this->getDefaultLicense()) ->addOption('author', NULL, InputOption::VALUE_REQUIRED, 'Name of the author', $this->getDefaultAuthor()) ->addOption('email', NULL, InputOption::VALUE_OPTIONAL, 'Email of the author', $this->getDefaultEmail()) ->setHelp( - "Create a new CiviCRM Module-Extension (Regenerate module.civix.php if ext.name not specified)\n" . + "Create a new CiviCRM Module-Extension (Regenerate module.civix.php if \"key\" is not specified)\n" . "\n" . "Identification:\n" . - " Keys should be lowercase alphanumeric with underscores. Additionally, dots and dashes\n" . - " are also legal - but they are discouraged for new extensions.\n" . + " Keys should be lowercase alphanumeric with underscores. Dots and dashes may be used with caveats.\n" . "\n" . - " Historically, the key often included a Java-style prefix (reverse domain name).\n" . - " The benefit of the prefix was mostly cosmetic. It did not provide consistent\n" . - " isolation between similarly named extensions. It is now recommended to skip\n" . + " CiviCRM extensions formally have two names, the \"key\" and the \"file\".\n" . + " Some APIs use the \"key\" name, and other APIs use the \"file\" name.\n" . + " The \"key\" allows a Java-style prefix (reverse domain name), but \"file\" does not.\n" . "\n" . + " If you use a Java-style prefix (dots and dashes), then the extension will have split names.\n" . + "\n" . + " If you omit a Java-style prefix (dots and dashes), then the extension will have a single (matching) name.\n" . "\n" . "Examples:\n" . - " civix generate:module foo-bar\n" . - " civix generate:module foo-bar --license=AGPL-3.0 --author=\"Alice\" --email=\"alice@example.org\"\n" . + " civix generate:module foo_bar\n" . + " civix generate:module foo_bar --license=AGPL-3.0 --author=\"Alice\" --email=\"alice@example.org\"\n" . " civix generate:module org.example.foo-bar \n" . "\n" ); @@ -108,24 +110,23 @@ protected function execute(InputInterface $input, OutputInterface $output) { if ($ctx['fullName'] !== $ctx['mainFile']) { $output->writeln(""); - $output->writeln("Simpler names are simpler."); - $output->writeln(""); - $output->writeln("CiviCRM extensions formally have two names, the \"key\" and the \"file\"."); - $output->writeln("Some APIs require the \"file\", and others require the \"key\"."); - $output->writeln(""); - $output->writeln(" Key: {$ctx['fullName']}"); - $output->writeln(" File: {$ctx['mainFile']}"); + $output->writeln("ALERT: The requested command requires split-naming."); $output->writeln(""); - $output->writeln("\"File\" names must meet tighter constraints than \"key\" names."); + $output->writeln("CiviCRM extensions formally have two names, the \"key\" and the \"file\"."); + $output->writeln("Some APIs use the \"key\" name, and other APIs use the \"file\" name."); $output->writeln(""); - $output->writeln("With the current request, the names will be different. This is"); - $output->writeln("entirely valid, although you need to know which is which."); + $output->writeln(" \"Key\": Appears in many strings+indices. Allows Java-style prefix."); + $output->writeln(" Requested Value: {$ctx['fullName']}"); + $output->writeln(" Example Usage: addStyleFile('{$ctx['fullName']}', 'example.css')"); + $output->writeln(" \"File\": Appears in PHP files+functions. No Java-style prefix."); + $output->writeln(" Requested Value: {$ctx['mainFile']}"); + $output->writeln(" Example Usage: function {$ctx['mainFile']}_civicrm_config() {}"); $output->writeln(""); - $output->writeln("Many developers find it simpler to use matching names. If you would"); - $output->writeln("like matching names, then cancel and try another name (without any"); - $output->writeln("dots or dashes)."); + $output->writeln("Many developers find it easier to use matching names, but the"); + $output->writeln("requested command requires splitting the names. You may continue with"); + $output->writeln("split names, or you may cancel and try again with a simpler name."); $output->writeln(""); - if (!$this->confirm($input, $output, "Continue with current name? [Y/n] ")) { + if (!$this->confirm($input, $output, "Continue with current (split) name? [Y/n] ")) { return 1; } } From c0edbd4094636f4ee59da5b6f8016c643142fcc2 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 14 Feb 2022 14:29:45 -0800 Subject: [PATCH 3/3] InitCommand - Tweak styling --- src/CRM/CivixBundle/Command/InitCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CRM/CivixBundle/Command/InitCommand.php b/src/CRM/CivixBundle/Command/InitCommand.php index f8aea824..923b6d39 100644 --- a/src/CRM/CivixBundle/Command/InitCommand.php +++ b/src/CRM/CivixBundle/Command/InitCommand.php @@ -110,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { if ($ctx['fullName'] !== $ctx['mainFile']) { $output->writeln(""); - $output->writeln("ALERT: The requested command requires split-naming."); + $output->writeln("ALERT: The requested command requires split-naming."); $output->writeln(""); $output->writeln("CiviCRM extensions formally have two names, the \"key\" and the \"file\"."); $output->writeln("Some APIs use the \"key\" name, and other APIs use the \"file\" name.");