File tree 1 file changed +39
-1
lines changed
1 file changed +39
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
'use strict' ;
4
4
5
+ process . title = 'mime' ;
5
6
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 ] ;
7
45
var type = mime . getType ( file ) ;
8
46
9
47
process . stdout . write ( type + '\n' ) ;
You can’t perform that action at this time.
0 commit comments