Skip to content

Commit 60ef21d

Browse files
Add possibility to set name for downloaded files
This commit allows to rename the downloaded asset to the name that is used as key. That is triggered by setting the key "rename" to `true` for the element like this: "tool" : { "url" : "https://.../tool-v1.0.0.phar", "rename" : true } This will downloda the file tool-v1.0.0.phar and rename it to the key of the entry, so in this case "tool". So it can be invoked using "./vendor/bin/tool"
1 parent 53cc055 commit 60ef21d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/Factory/ToolFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static function createTool($name, $directory, array $parameters)
2323
'sign-url' => null,
2424
'only-dev' => true,
2525
'force-replace' => false,
26+
'rename' => false,
2627
];
2728

2829
$parameters = array_merge($defaults, $parameters);
@@ -42,6 +43,10 @@ public static function createTool($name, $directory, array $parameters)
4243
$tool->disableOnlyDev();
4344
}
4445

46+
if (true === $parameters['rename']) {
47+
$tool->setNameToToolKey();
48+
}
49+
4550
return $tool;
4651
}
4752

src/Model/Tool.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class Tool
3737
*/
3838
private $onlyDev = true;
3939

40+
/**
41+
* @var bool
42+
*/
43+
private $rename = false;
44+
4045
/**
4146
* @param string $name
4247
* @param string $filename
@@ -116,4 +121,20 @@ public function forceReplace()
116121
{
117122
return $this->forceReplace;
118123
}
124+
125+
/**
126+
* @return void
127+
*/
128+
public function setNameToToolKey()
129+
{
130+
$this->rename = true;
131+
}
132+
133+
/**
134+
* @return bool
135+
*/
136+
public function renameToConfigKey()
137+
{
138+
return $this->rename;
139+
}
119140
}

src/Script/Processor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ public function symlink(Tool $tool)
100100
}
101101

102102
$filename = $tool->getFilename();
103+
if ($tool->renameToConfigKey()) {
104+
$filename = $tool->getName();
105+
}
103106
$composerDir = $this->configuration->getComposerBinDirectory();
104107
$composerPath = $composerDir . DIRECTORY_SEPARATOR . basename($filename);
105108

0 commit comments

Comments
 (0)