-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
40 lines (35 loc) · 1.24 KB
/
cli.ts
File metadata and controls
40 lines (35 loc) · 1.24 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
import { Args, parseArgs, ParseOptions } from 'jsr:@std/cli/parse-args';
export default async function parse(): Promise<Args> {
const validFlags = ['bitratelimit', 'loglevel', 'path', 'help'];
const validAliases = ['p', 'b', 'l'];
const cliOptions: ParseOptions = {
alias: {
path: 'p',
bitratelimit: 'b',
loglevel: 'l',
},
string: validFlags,
boolean: ['help'],
default: { path: '.', bitratelimit: 320, loglevel: 'INFO' },
};
const args = parseArgs(Deno.args, cliOptions);
if (args.help) {
await printHelp();
Deno.exit(0);
}
const validArgsObjectKeys = [...validAliases, ...validFlags, '_'];
const unrecognizedFlags = Object.keys(args).filter((flag: string) => !validArgsObjectKeys.includes(flag));
if (unrecognizedFlags.length > 0) {
await printHelp();
Deno.exit(1);
}
return args;
}
async function printHelp(): Promise<void> {
console.log('Usage: audio-scanner [options]');
console.log('Options:');
console.log(' --help Show help information');
console.log(' --path | -p Specify path to search at');
console.log(' --bitratelimit | -b Specify bitrate limit in kbps');
console.log(' --loglevel | -l Specify log level: ERROR, INFO, DEBUG');
}