-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgenerate-readme
More file actions
executable file
·64 lines (55 loc) · 1.8 KB
/
generate-readme
File metadata and controls
executable file
·64 lines (55 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env php
<?php
declare(strict_types=1);
error_reporting(E_ALL);
probeForAutoloader($argv[0]);
use PHPLRPM\ConfigurationValidator;
$sections = [
'config' => [
'marker' => "// AUTOGENERATED BLOCK: CONFIGURATION\n",
'text' => ''
]
];
$configValidator = new ConfigurationValidator([]);
$configFields = $configValidator->getFields();
foreach ($configFields as $configField => $v) {
$sections['config']['text'] .= "===== $configField" . PHP_EOL . PHP_EOL;
$sections['config']['text'] .= $v['description'] . PHP_EOL . PHP_EOL;
$sections['config']['text'] .= 'Mandatory: ' . ($v['mandatory'] ? 'yes' : 'no');
if (!$v['mandatory']) {
$sections['config']['text'] .= ' +' . PHP_EOL . 'Default value: ' . $v['default'];
}
$sections['config']['text'] .= PHP_EOL . PHP_EOL;
}
$readmeIn = $argc > 1 ? $argv[1] : __DIR__ . '/README.in.adoc';
$in = fopen($readmeIn, 'r');
$out = STDOUT;
if ($in) {
while (($line = fgets($in)) !== false) {
foreach ($sections as $section) {
if ($line === $section['marker']) {
fwrite($out, $section['text']);
} else {
fwrite($out, $line);
}
}
}
fclose($in);
} else {
fwrite(STDERR, "Error opening input file $readmeIn for reading" . PHP_EOL);
}
function probeForAutoloader($programName): void
{
$autoload_locations = [
__DIR__ . '/vendor/autoload.php',
__DIR__ . '/../../autoload.php'
];
foreach ($autoload_locations as $autoload_file) {
if (file_exists($autoload_file)) {
require_once($autoload_file);
return;
}
}
fwrite(STDERR, $programName . ': could not find autoload.php, use PHP Composer to generate autoloader code' . PHP_EOL);
exit(EXIT_AUTOLOADER_NOT_FOUND);
}