-
Notifications
You must be signed in to change notification settings - Fork 2
/
rx
executable file
·61 lines (54 loc) · 1.66 KB
/
rx
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
#!/usr/bin/env php
<?php declare(strict_types=1);
include_once("vendor/autoload.php");
if (! isset($argv[1]) || ! isset($argv[2]) || ! file_exists($argv[1]) || ! file_exists($argv[2])) {
echo " ❌ Unable to find file(s) in argument(s).\n";
echo " Usage: ./rx <yaml/json> <schema> [\"<glob of custom types>\"]\n";
exit(1);
}
try {
$credentialsFile = Rx\RxLoader::load($argv[1]);
} catch (Exception $e) {
echo " ❌ Unable to parse yaml/json file.\n";
echo " {$e->getMessage()}\n";
exit(1);
}
try {
$schemaFile = Rx\RxLoader::load($argv[2]);
} catch (Exception $e) {
echo " ❌ Unable to parse schema file.\n";
echo " {$e->getMessage()}\n";
exit(1);
}
$rx = new Rx\Rx();
// Add custom types
if (isset($argv[3])) {
foreach (glob($argv[3]) as $type) {
try {
$typeFile = Rx\RxLoader::load($type);
$rx->learnType($typeFile->uri, $typeFile->schema);
echo " ✅ Added {$typeFile->uri}.\n";
} catch (Exception $e) {
echo " ❌ Unable to add custom types via glob.\n";
echo " {$e->getMessage()}\n";
exit(1);
}
}
}
try {
$schema = $rx->makeSchema($schemaFile);
echo " ✅ Schema loaded successfully.\n";
} catch (Exception $e) {
echo " ❌ An error occurred loading the schema.\n";
echo " {$e->getMessage()}\n";
exit(1);
}
try {
$schema->check($credentialsFile);
echo " ✅ File is correct according to the schema.\n";
} catch (Exception $e) {
echo " ❌ An error occurred validating the file against the schema.\n";
echo " {$e->getMessage()}\n";
exit(1);
}
exit(0);