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) {
249249 await runScript ( process . cwd ( ) , cmd , { pkgManagerName } ) ;
250250 } ) ;
251251 } else {
252- console . error ( kl . red ( `Unknown command: ${ cmd } ` ) ) ;
253- console . log ( ) ;
254- printHelp ( ) ;
255- process . exit ( 1 ) ;
252+ throwUnknownCommand ( cmd ) ;
256253 }
254+ } else {
255+ throwUnknownCommand ( cmd ) ;
257256 }
258257 }
259258 }
@@ -278,3 +277,10 @@ async function run(fn: () => Promise<void>) {
278277 throw err ;
279278 }
280279}
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 {
2121 writeTextFile ,
2222} from "../src/utils" ;
2323
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+
2457describe ( "install" , ( ) => {
2558 it ( "jsr i @std/encoding - resolve latest version" , async ( ) => {
2659 await withTempEnv ( [ "i" , "@std/encoding" ] , async ( dir ) => {
You can’t perform that action at this time.
0 commit comments