Skip to content

Commit f1a37f7

Browse files
committed
Handles differing Unix tree command behaviour
1 parent 5e073c6 commit f1a37f7

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

peck.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"analyser",
88
"analyse",
99
"windowsish",
10+
"macish",
1011
"lpv",
1112
"readme",
1213
"pathnames",

src/Helpers/Str.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,28 @@ class Str
1111
*
1212
* @return boolean
1313
*/
14-
public function isWindows($os = PHP_OS): bool
14+
public function isWindows(string $os = PHP_OS): bool
1515
{
1616
if (\strtoupper(\substr($os, 0, 3)) !== 'WIN') {
1717
return false;
1818
}
1919

2020
return true;
2121
}
22+
23+
/**
24+
* Check if the operating system is macish.
25+
*
26+
* @param string $os
27+
*
28+
* @return boolean
29+
*/
30+
public function isMacOs(string $os = PHP_OS): bool
31+
{
32+
if (\strtoupper(\substr($os, 0, 3)) !== 'DAR') {
33+
return false;
34+
}
35+
36+
return true;
37+
}
2238
}

src/Tree.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ public function __construct(Archive $archive)
2929

3030
public function getTreeForSrc(string $directory): string
3131
{
32-
\exec(
33-
'tree -aL 1 --dirsfirst ' . \escapeshellarg($directory) . ' --gitignore -I .git 2>&1',
34-
$output
35-
);
32+
$command = 'tree -aL 1 --dirsfirst ' . \escapeshellarg($directory) . ' -I .git 2>&1';
33+
34+
if ((new OsHelper())->isMacOs()) {
35+
$command = 'tree -aL 1 --dirsfirst ' . \escapeshellarg($directory) . ' --gitignore -I .git 2>&1';
36+
}
37+
38+
\exec($command, $output);
3639

3740
$output[0] = '.';
3841

@@ -43,10 +46,13 @@ public function getTreeForDistPackage(string $directory): string
4346
{
4447
$this->archive->createArchive();
4548

46-
\exec(
47-
'tar --list --exclude="*/*" --file ' . \escapeshellarg($this->archive->getFilename()) . ' | tree -aL 1 --dirsfirst --fromfile . 2>&1',
48-
$output
49-
);
49+
$command = 'tar --list --exclude="*/*" --file ' . \escapeshellarg($this->archive->getFilename()) . ' | tree -aL 1 --dirsfirst --fromfile . 2>&1';
50+
51+
if ((new OsHelper())->isMacOs()) {
52+
$command = 'tar --list --file ' . \escapeshellarg($this->archive->getFilename()) . ' | tree -aL 1 --dirsfirst --fromfile . 2>&1';
53+
}
54+
55+
\exec($command, $output);
5056

5157
$this->archive->removeArchive();
5258

0 commit comments

Comments
 (0)