Skip to content

Commit

Permalink
Merge pull request #2 from hannunosto/feature/optional-package-name-a…
Browse files Browse the repository at this point in the history
…s-cmd-argument

Add possibility to define package name as a cmd argument
  • Loading branch information
mridang authored Mar 28, 2017
2 parents 6078e45 + e6dfc63 commit 5b3cfec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/Magazine/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ protected function configure()
'version',
InputArgument::OPTIONAL,
'Version number of the package'
)
->addArgument(
'name',
InputArgument::OPTIONAL,
'The name of the package'
);
}

Expand All @@ -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();
}
}
Expand Down
19 changes: 14 additions & 5 deletions src/Magazine/Magazine.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,32 @@ 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))) {
throw new \Exception("Missing file or was a directory");
} 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();
Expand Down Expand Up @@ -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;
}
}

/**
Expand Down

0 comments on commit 5b3cfec

Please sign in to comment.