| 1499 | ); |
| 1500 | }, |
| 1501 | async add( |
| 1502 | key: string, |
| 1503 | options: { |
| 1504 | name: string | undefined; |
| 1505 | config: string | undefined; |
| 1506 | preview: string | undefined; |
| 1507 | } |
| 1508 | ) { |
| 1509 | // get user details |
| 1510 | const user = await getUser(); |
| 1511 | |
| 1512 | const config = getConfig(options.config, { |
| 1513 | name: options.name |
| 1514 | }); |
| 1515 | if (!config.name) { |
| 1516 | throw new ConfigurationError(MissingProjectNameError); |
| 1517 | } |
| 1518 | |
| 1519 | const { default: prompt } = await import("prompts"); |
| 1520 | |
| 1521 | const { value } = !process.stdin.isTTY |
| 1522 | ? // the value is being piped in |
| 1523 | await new Promise<{ value: string }>((resolve, reject) => { |
| 1524 | const stdin = process.stdin; |
| 1525 | |
| 1526 | let data = ""; |
| 1527 | |
| 1528 | stdin.on("data", function (chunk) { |
| 1529 | data += chunk; |
| 1530 | }); |
| 1531 | |
| 1532 | stdin.on("end", function () { |
| 1533 | resolve({ value: data }); |
| 1534 | }); |
| 1535 | |
| 1536 | stdin.on("error", function (err) { |
| 1537 | reject(err); |
| 1538 | }); |
| 1539 | }) |
| 1540 | : // the value is being entered manually |
| 1541 | await prompt({ |
| 1542 | type: "password", |
| 1543 | name: "value", |
| 1544 | message: `Enter the value for ${key}` |
| 1545 | }); |
| 1546 | |
| 1547 | const urlSearchParams = new URLSearchParams(); |
| 1548 | if (options.preview) { |
| 1549 | urlSearchParams.set("preview", options.preview); |
| 1550 | } |
| 1551 | |
| 1552 | await fetchResult( |
| 1553 | // eslint-disable-next-line deprecation/deprecation |
| 1554 | `/parties/${config.team || user.login}/${config.name}/env/${key}${ |
| 1555 | options.preview ? `?${urlSearchParams.toString()}` : "" |
| 1556 | }`, |
| 1557 | { |
| 1558 | user, |