Repository navigation
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·167 lines (136 loc) · 3.49 KB
/
Copy pathcli.js
File metadata and controls
executable file
·167 lines (136 loc) · 3.49 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env node
"use strict";
const { parseArgs } = require("node:util");
const path = require("node:path");
const fs = require("node:fs");
const Runner = require("./src/Runner");
// Parse command line arguments
const options = {
arazzo: {
type: "string",
short: "a",
},
input: {
type: "string",
short: "i",
},
verbose: {
type: "boolean",
},
help: {
type: "boolean",
short: "h",
},
version: {
type: "boolean",
short: "v",
},
};
function showHelp() {
console.log(`
Arazzo Runner - Execute Arazzo workflow specifications
USAGE:
arazzo-runner --arazzo <file|url> --input <file>
arazzo-runner -a <file|url> -i <file>
OPTIONS:
-a, --arazzo <file|url> Path or URL to Arazzo Document file (required)
-i, --input <file> Path to input JSON file (required)
-h, --help Show this help message
-v, --version Show version number
-vv, --verbose Verbose Logging
EXAMPLES:
# Run with local files
arazzo-runner --arazzo ./arazzo.json --input ./input.json
# Run with URL
arazzo-runner -a https://example.com/arazzo.json -i ./input.json
# Short form
arazzo-runner -a arazzo.json -i input.json
`);
}
function showVersion() {
const packageJson = require("./package.json");
console.log(`v${packageJson.version}`);
}
function isUrl(str) {
try {
new URL(str);
return true;
} catch {
return false;
}
}
function validateArazzoPath(arazzoPath) {
if (isUrl(arazzoPath)) {
return arazzoPath;
}
const resolvedPath = path.resolve(arazzoPath);
if (!fs.existsSync(resolvedPath)) {
console.error(`Error: Arazzo file not found: ${arazzoPath}`);
process.exit(1);
}
return resolvedPath;
}
function validateInputPath(inputPath) {
const resolvedPath = path.resolve(inputPath);
if (!fs.existsSync(resolvedPath)) {
console.error(`Error: Input file not found: ${inputPath}`);
process.exit(1);
}
return resolvedPath;
}
async function main() {
let values;
try {
({ values } = parseArgs({ options, allowPositionals: false }));
} catch (err) {
console.error(`Error: ${err.message}`);
console.log("Use --help for usage information");
process.exit(1);
}
// Handle help
if (values.help) {
showHelp();
process.exit(0);
}
// Handle version
if (values.version) {
showVersion();
process.exit(0);
}
// Validate required arguments
if (!values.arazzo) {
console.error("Error: --arazzo argument is required");
console.log("Use --help for usage information");
process.exit(1);
}
if (!values.input) {
console.error("Error: --input argument is required");
console.log("Use --help for usage information");
process.exit(1);
}
// Validate paths
const arazzoPath = validateArazzoPath(values.arazzo);
const inputPath = validateInputPath(values.input);
console.log(`Starting Arazzo Runner...`);
console.log(`Arazzo: ${arazzoPath}`);
console.log(`Input: ${inputPath}`);
console.log("");
try {
const runner = new Runner({ verbose: values?.verbose || false });
await runner.runArazzo(arazzoPath, inputPath);
console.log("");
console.log("✓ Arazzo execution completed successfully");
process.exit(0);
} catch (err) {
console.error("");
console.error("✗ Arazzo execution failed:");
console.error(err.message);
if (process.env.DEBUG) {
console.error("");
console.error("Stack trace:");
console.error(err.stack);
}
process.exit(1);
}
}
main();