From e6dfc633959ce399e2350556b7162ef2985e7817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannu=20Po=CC=88lo=CC=88nen?= Date: Tue, 28 Mar 2017 12:13:52 +0300 Subject: [PATCH] Add possibility to define package name as a cmd argument --- src/Magazine/Command.php | 8 +++++++- src/Magazine/Magazine.php | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Magazine/Command.php b/src/Magazine/Command.php index dd24105..d7264ec 100644 --- a/src/Magazine/Command.php +++ b/src/Magazine/Command.php @@ -35,6 +35,11 @@ protected function configure() 'version', InputArgument::OPTIONAL, 'Version number of the package' + ) + ->addArgument( + 'name', + InputArgument::OPTIONAL, + 'The name of the package' ); } @@ -48,13 +53,14 @@ protected function execute(InputInterface $input, OutputInterface $output) { $path = $input->getArgument('path'); $version = $input->getArgument('version'); + $package_name = $input->getArgument('name'); if (!file_exists($path) && !is_file($input->getArgument('path'))) { self::error($output, "The specified path is missing or a directory"); } else { if (json_decode(file_get_contents($path)) == null) { self::error($output, "The specified file is not a valid JSON file"); } else { - $packager = new Magazine($path, $version, $output); + $packager = new Magazine($path, $version, $output, $package_name); $packager->package(); } } diff --git a/src/Magazine/Magazine.php b/src/Magazine/Magazine.php index 180f7e5..d3935d0 100644 --- a/src/Magazine/Magazine.php +++ b/src/Magazine/Magazine.php @@ -22,19 +22,24 @@ class Magazine private $targets; private $output; private $package_version; + private $package_name; /** * Constructor for initializing the Magazine packager that initializes the * base and temporary directories and validates that a file exists. * - * @param $path string the absolute path to the package.json file - * @param $version string the version of the package, e.g. 2.9.1 - * @param OutputInterface $output The output interface for logging messages + * @param string $path the absolute path to the package.json file + * @param string $version the version of the package, e.g. 2.9.1 * @param OutputInterface $output The output interface for logging messages + * @param string $packageName optional name of the package * @throws \Exception When the package.json file was not found or malformed */ - public function __construct($path, $version, OutputInterface $output) - { + public function __construct( + $path, + $version, + OutputInterface $output, + $package_name = null + ) { $this->output = $output; if (!file_exists(realpath($path)) && !is_file(realpath($path))) { @@ -42,6 +47,7 @@ public function __construct($path, $version, OutputInterface $output) } else { $this->pkg_json = $path; $this->package_version = $version; + $this->package_name = $package_name; $this->base_dir = dirname(realpath($path)); $this->temp_dir = self::getTempDir(); $this->targets = new \Mage_Connect_Package_Target(); @@ -229,6 +235,9 @@ private function amendDynamicAttributesToJson(array &$json) { $json['version'] = array(); $json['version']['release'] = $this->package_version; } + if (!is_null($this->package_name)) { + $json['name'] = $this->package_name; + } } /**