Skip to content

Commit 3024374

Browse files
committed
Make output nicer
1 parent 4e62919 commit 3024374

File tree

1 file changed

+89
-74
lines changed

1 file changed

+89
-74
lines changed

src/index.ts

Lines changed: 89 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,22 @@ yargs(hideBin(process.argv))
2121
},
2222
},
2323
async (args) => {
24-
let key: string | null = args.key;
25-
if (!key) {
26-
key = (
27-
await prompts({
28-
type: "text",
29-
name: "value",
30-
message: "Please enter your API key:",
31-
})
32-
).value as string;
33-
}
24+
try {
25+
let key: string | null = args.key;
26+
if (!key) {
27+
key = (
28+
await prompts({
29+
type: "password",
30+
name: "value",
31+
message: "Please enter your API key:",
32+
})
33+
).value as string;
34+
}
3435

35-
await upload(args.manifest as string, key);
36+
await upload(args.manifest as string, key);
37+
} catch (e) {
38+
console.error(e);
39+
}
3640
},
3741
)
3842
.command(
@@ -54,40 +58,45 @@ yargs(hideBin(process.argv))
5458
},
5559
},
5660
async (args) => {
57-
if (!fs.existsSync(args.video as string)) {
58-
throw new Error("The specified video file does not exist!");
59-
}
61+
try {
62+
if (!fs.existsSync(args.video as string)) {
63+
console.error("The specified video file does not exist!");
64+
return;
65+
}
6066

61-
const output =
62-
args.output ||
63-
Path.join(
64-
Path.dirname(args.video as string),
65-
Path.parse(args.video as string).name + ".ogg",
66-
);
67+
const output =
68+
args.output ||
69+
Path.join(
70+
Path.dirname(args.video as string),
71+
Path.parse(args.video as string).name + ".ogg",
72+
);
6773

68-
// Make sure that the user knows that they're overriding a file.
69-
if (
70-
fs.existsSync(output) &&
71-
!args.yes &&
72-
!(
73-
await prompts({
74-
type: "confirm",
75-
name: "value",
76-
message:
77-
'The file "' +
78-
output +
79-
'" already exists. Please confirm that you want to override it:',
80-
})
81-
).value
82-
) {
83-
return;
84-
}
74+
// Make sure that the user knows that they're overriding a file.
75+
if (
76+
fs.existsSync(output) &&
77+
!args.yes &&
78+
!(
79+
await prompts({
80+
type: "confirm",
81+
name: "value",
82+
message:
83+
'The file "' +
84+
output +
85+
'" already exists. Please confirm that you want to override it:',
86+
})
87+
).value
88+
) {
89+
return;
90+
}
8591

86-
fs.writeFileSync(
87-
output,
88-
videoToAudio(fs.readFileSync(args.video as string)),
89-
);
90-
console.log('Wrote audio to "' + output + '".');
92+
fs.writeFileSync(
93+
output,
94+
videoToAudio(fs.readFileSync(args.video as string)),
95+
);
96+
console.log('Wrote audio to "' + output + '".');
97+
} catch (e) {
98+
console.error(e);
99+
}
91100
},
92101
)
93102
.command(
@@ -109,41 +118,47 @@ yargs(hideBin(process.argv))
109118
},
110119
},
111120
async (args) => {
112-
if (!fs.existsSync(args.video as string)) {
113-
throw new Error("The specified video file does not exist!");
114-
}
115-
if (!fs.existsSync(args.audio as string)) {
116-
throw new Error("The specified audio file does not exist!");
117-
}
121+
try {
122+
if (!fs.existsSync(args.video as string)) {
123+
console.error("The specified video file does not exist!");
124+
return;
125+
}
126+
if (!fs.existsSync(args.audio as string)) {
127+
console.error("The specified audio file does not exist!");
128+
return;
129+
}
118130

119-
const output = args.output || (args.video as string);
131+
const output = args.output || (args.video as string);
120132

121-
// Make sure that the user knows that they're overriding a file.
122-
if (
123-
fs.existsSync(output) &&
124-
!args.yes &&
125-
!(
126-
await prompts({
127-
type: "confirm",
128-
name: "value",
129-
message:
130-
'The file "' +
131-
output +
132-
'" already exists. Please confirm that you want to override it:',
133-
})
134-
).value
135-
) {
136-
return;
137-
}
133+
// Make sure that the user knows that they're overriding a file.
134+
if (
135+
fs.existsSync(output) &&
136+
!args.yes &&
137+
!(
138+
await prompts({
139+
type: "confirm",
140+
name: "value",
141+
message:
142+
'The file "' +
143+
output +
144+
'" already exists. Please confirm that you want to override it:',
145+
})
146+
).value
147+
) {
148+
return;
149+
}
138150

139-
fs.writeFileSync(
140-
output,
141-
createVideo(
142-
fs.readFileSync(args.video as string),
143-
fs.readFileSync(args.audio as string),
144-
),
145-
);
146-
console.log('Wrote video with new audio to "' + output + '".');
151+
fs.writeFileSync(
152+
output,
153+
createVideo(
154+
fs.readFileSync(args.video as string),
155+
fs.readFileSync(args.audio as string),
156+
),
157+
);
158+
console.log('Wrote video with new audio to "' + output + '".');
159+
} catch (e) {
160+
console.error(e);
161+
}
147162
},
148163
)
149164
.showHelpOnFail(true)

0 commit comments

Comments
 (0)