File tree Expand file tree Collapse file tree 2 files changed +43
-4
lines changed Expand file tree Collapse file tree 2 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -249,11 +249,10 @@ if (args.length === 0) {
249
249
await runScript ( process . cwd ( ) , cmd , { pkgManagerName } ) ;
250
250
} ) ;
251
251
} else {
252
- console . error ( kl . red ( `Unknown command: ${ cmd } ` ) ) ;
253
- console . log ( ) ;
254
- printHelp ( ) ;
255
- process . exit ( 1 ) ;
252
+ throwUnknownCommand ( cmd ) ;
256
253
}
254
+ } else {
255
+ throwUnknownCommand ( cmd ) ;
257
256
}
258
257
}
259
258
}
@@ -278,3 +277,10 @@ async function run(fn: () => Promise<void>) {
278
277
throw err ;
279
278
}
280
279
}
280
+
281
+ function throwUnknownCommand ( cmd : string ) {
282
+ console . error ( kl . red ( `Unknown command: ${ cmd } ` ) ) ;
283
+ console . log ( ) ;
284
+ printHelp ( ) ;
285
+ process . exit ( 1 ) ;
286
+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,39 @@ import {
21
21
writeTextFile ,
22
22
} from "../src/utils" ;
23
23
24
+ describe ( "general" , ( ) => {
25
+ it ( "exit 1 on unknown command" , async ( ) => {
26
+ try {
27
+ await withTempEnv ( [ "foo" ] , async ( ) => { } ) ;
28
+ assert . fail ( "no" ) ;
29
+ } catch ( err ) {
30
+ if ( err instanceof Error ) {
31
+ assert . match ( err . message , / C h i l d p r o c e s s / ) ;
32
+ assert . equal ( ( err as any ) . code , 1 ) ;
33
+ } else {
34
+ throw err ;
35
+ }
36
+ }
37
+ } ) ;
38
+
39
+ // See https://github.com/jsr-io/jsr-npm/issues/79
40
+ it ( "exit 1 on unknown command in empty folder" , async ( ) => {
41
+ await runInTempDir ( async ( dir ) => {
42
+ try {
43
+ await runJsr ( [ "asdf" ] , dir ) ;
44
+ assert . fail ( "no" ) ;
45
+ } catch ( err ) {
46
+ if ( err instanceof Error ) {
47
+ assert . match ( err . message , / C h i l d p r o c e s s / ) ;
48
+ assert . equal ( ( err as any ) . code , 1 ) ;
49
+ } else {
50
+ throw err ;
51
+ }
52
+ }
53
+ } ) ;
54
+ } ) ;
55
+ } ) ;
56
+
24
57
describe ( "install" , ( ) => {
25
58
it ( "jsr i @std/encoding - resolve latest version" , async ( ) => {
26
59
await withTempEnv ( [ "i" , "@std/encoding" ] , async ( dir ) => {
You can’t perform that action at this time.
0 commit comments