@cloud-copilot/iam-lens
Version:
Visibility in IAM in and across AWS accounts
25 lines • 986 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringOrFileArgument = void 0;
const cli_1 = require("@cloud-copilot/cli");
const fs_1 = require("fs");
exports.stringOrFileArgument = (0, cli_1.singleValueArgument)((rawValue) => {
try {
return { valid: true, value: JSON.parse(rawValue) };
}
catch {
// Not a JSON string, try to read as file
}
const fileExists = (0, fs_1.existsSync)(rawValue);
if (!fileExists) {
return { valid: false, message: `Value is not valid JSON and file does not exist: ${rawValue}` };
}
const fileContents = (0, fs_1.readFileSync)(rawValue, 'utf-8');
try {
const parsed = JSON.parse(fileContents);
return { valid: true, value: parsed };
}
catch { }
return { valid: false, message: `File contents are not valid JSON: ${rawValue}` };
}, '. A JSON string or a file path containing JSON.');
//# sourceMappingURL=stringOrFileArgument.js.map