Skip to content

Commit 81a2be8

Browse files
fix: json flag issue interactive mode (#86)
1 parent 175e15f commit 81a2be8

24 files changed

Lines changed: 658 additions & 22 deletions

File tree

src/commands/api-keys/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Permissions:
4949
let permission = opts.permission;
5050

5151
if (!name) {
52-
if (!isInteractive()) {
52+
if (!isInteractive() || globalOpts.json) {
5353
outputError(
5454
{ message: 'Missing --name flag.', code: 'missing_name' },
5555
{ json: globalOpts.json },

src/commands/auth/login.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const loginCommand = new Command('login')
5757
let apiKey = opts.key;
5858

5959
if (!apiKey) {
60-
if (!isInteractive()) {
60+
if (!isInteractive() || globalOpts.json) {
6161
outputError(
6262
{
6363
message:
@@ -174,7 +174,7 @@ export const loginCommand = new Command('login')
174174
}
175175
}
176176

177-
if (!profileName && isInteractive()) {
177+
if (!profileName && isInteractive() && !globalOpts.json) {
178178
const existingProfiles = listProfiles();
179179
if (existingProfiles.length > 0) {
180180
const options = [

src/commands/auth/remove.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function removeAction(
1313
let profileName = name;
1414

1515
if (!profileName) {
16-
if (!isInteractive()) {
16+
if (!isInteractive() || globalOpts.json) {
1717
outputError(
1818
{
1919
message:
@@ -81,7 +81,7 @@ export async function removeAction(
8181
{ success: true, removed_profile: profileName },
8282
{ json: true },
8383
);
84-
} else if (isInteractive()) {
84+
} else if (isInteractive() && !globalOpts.json) {
8585
console.log(`Profile '${profileName}' removed.`);
8686
}
8787
}

src/commands/auth/switch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function switchAction(
1717
let profileName = name;
1818

1919
if (!profileName) {
20-
if (!isInteractive()) {
20+
if (!isInteractive() || globalOpts.json) {
2121
outputError(
2222
{
2323
message:

src/commands/broadcasts/create.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Scheduling:
7878
let segmentId = opts.segmentId;
7979

8080
if (!from) {
81-
if (!isInteractive()) {
81+
if (!isInteractive() || globalOpts.json) {
8282
outputError(
8383
{ message: 'Missing --from flag.', code: 'missing_from' },
8484
{ json: globalOpts.json },
@@ -96,7 +96,7 @@ Scheduling:
9696
}
9797

9898
if (!subject) {
99-
if (!isInteractive()) {
99+
if (!isInteractive() || globalOpts.json) {
100100
outputError(
101101
{ message: 'Missing --subject flag.', code: 'missing_subject' },
102102
{ json: globalOpts.json },
@@ -114,7 +114,7 @@ Scheduling:
114114
}
115115

116116
if (!segmentId) {
117-
if (!isInteractive()) {
117+
if (!isInteractive() || globalOpts.json) {
118118
outputError(
119119
{ message: 'Missing --segment-id flag.', code: 'missing_segment' },
120120
{ json: globalOpts.json },
@@ -139,7 +139,7 @@ Scheduling:
139139
}
140140

141141
if (!html && !text) {
142-
if (!isInteractive()) {
142+
if (!isInteractive() || globalOpts.json) {
143143
outputError(
144144
{
145145
message: 'Missing body. Provide --html, --html-file, or --text.',

src/commands/contacts/add-segment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Non-interactive: --segment-id is required.`,
3535
let segmentId = opts.segmentId;
3636

3737
if (!segmentId) {
38-
if (!isInteractive()) {
38+
if (!isInteractive() || globalOpts.json) {
3939
outputError(
4040
{ message: 'Missing --segment-id flag.', code: 'missing_segment_id' },
4141
{ json: globalOpts.json },

src/commands/contacts/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Unsubscribed: setting --unsubscribed is a team-wide opt-out from all broadcasts,
6666
let firstName = opts.firstName;
6767
let lastName = opts.lastName;
6868

69-
if (isInteractive() && !opts.firstName) {
69+
if (isInteractive() && !globalOpts.json && !opts.firstName) {
7070
const result = await p.text({
7171
message: 'First name (optional)',
7272
placeholder: 'Jane',
@@ -79,7 +79,7 @@ Unsubscribed: setting --unsubscribed is a team-wide opt-out from all broadcasts,
7979
}
8080
}
8181

82-
if (isInteractive() && !opts.lastName) {
82+
if (isInteractive() && !globalOpts.json && !opts.lastName) {
8383
const result = await p.text({
8484
message: 'Last name (optional)',
8585
placeholder: 'Smith',

src/commands/contacts/update-topics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Topics not included in the array are left unchanged.`,
4949
let topicsJson = opts.topics;
5050

5151
if (!topicsJson) {
52-
if (!isInteractive()) {
52+
if (!isInteractive() || globalOpts.json) {
5353
outputError(
5454
{ message: 'Missing --topics flag.', code: 'missing_topics' },
5555
{ json: globalOpts.json },

src/commands/emails/send.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export const sendCommand = new Command('send')
141141
// Only fetch verified domains in interactive mode — non-interactive
142142
// callers (CI, agents, scripts) must pass --from explicitly.
143143
let fromAddress = opts.from;
144-
if (!fromAddress && isInteractive()) {
144+
if (!fromAddress && isInteractive() && !globalOpts.json) {
145145
const domains = await fetchVerifiedDomains(resend);
146146
if (domains.length > 0) {
147147
fromAddress = await promptForFromAddress(domains);

src/commands/templates/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Non-interactive: --name and a body (--html or --html-file) are required.`,
5959
let name = opts.name;
6060

6161
if (!name) {
62-
if (!isInteractive()) {
62+
if (!isInteractive() || globalOpts.json) {
6363
outputError(
6464
{ message: 'Missing --name flag.', code: 'missing_name' },
6565
{ json: globalOpts.json },
@@ -93,7 +93,7 @@ Non-interactive: --name and a body (--html or --html-file) are required.`,
9393
}
9494

9595
if (!html) {
96-
if (!isInteractive()) {
96+
if (!isInteractive() || globalOpts.json) {
9797
outputError(
9898
{
9999
message: 'Missing body. Provide --html or --html-file.',

0 commit comments

Comments
 (0)