Skip to content

Commit 05a6a02

Browse files
authoredJan 15, 2021
Improved CLI (#244)
* Added in version flag and name flag * Improved CLI
1 parent f5a0ea5 commit 05a6a02

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed
 

‎cli.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,46 @@
22

33
'use strict';
44

5+
process.title = 'mime';
56
var mime = require('.');
6-
var file = process.argv[2];
7+
var pkg = require('./package.json');
8+
var args = process.argv.splice(2);
9+
10+
if (args.includes('--version') || args.includes('-v') || args.includes('--v')) {
11+
console.log(pkg.version);
12+
process.exit(0);
13+
}
14+
else if (args.includes('--name') || args.includes('-n') || args.includes('--n')) {
15+
console.log(pkg.name);
16+
process.exit(0);
17+
}
18+
else if (args.includes('--help') || args.includes('-h') || args.includes('--h')) {
19+
console.log(pkg.name + ' - ' + pkg.description + '\n');
20+
console.log(`Usage:
21+
22+
mime [flags] [path_or_extension]
23+
24+
Flags:
25+
--help, -h Show this message
26+
--version, -v Display the version
27+
--name, -n Print the name of the program
28+
29+
Note: the command will exit after it executes if a command is specified
30+
The path_or_extension is the path to the file or the extension of the file.
31+
32+
Examples:
33+
mime --help
34+
mime --version
35+
mime --name
36+
mime -v
37+
mime src/log.js
38+
mime new.py
39+
mime foo.sh
40+
`);
41+
process.exit(0);
42+
}
43+
44+
var file = args[0];
745
var type = mime.getType(file);
846

947
process.stdout.write(type + '\n');

0 commit comments

Comments
 (0)
Please sign in to comment.