@@ -6,8 +6,8 @@ function commonJustfile(paths: string[]): string {
66 if ( paths . length === 0 ) return "" ;
77 const splitPaths = paths . map ( ( p ) => p . split ( path . sep ) ) ;
88 let justfile : string | undefined = undefined ;
9- for ( let i = 0 ; i < splitPaths [ 0 ] . length ; i ++ ) {
10- let candidate = path . resolve ( path . join ( splitPaths [ 0 ] . slice ( 0 , i ) . join ( path . sep ) , "justfile" ) ) ;
9+ for ( let i = 0 ; i <= splitPaths [ 0 ] . length ; i ++ ) {
10+ let candidate = path . join ( splitPaths [ 0 ] . slice ( 0 , i ) . join ( path . sep ) , "justfile" ) ;
1111 if ( fs . existsSync ( candidate ) ) {
1212 justfile = candidate ;
1313 }
@@ -42,25 +42,34 @@ function forwardCommand(args: string[]): number {
4242 ( arg ) => ! is_non_positional . test ( arg ) ,
4343 ) ;
4444
45- if ( positionalArgs . length === 0 ) {
46- console . error ( "No positional arguments provided" ) ;
47- return 1 ;
45+ const justfile = commonJustfile ( positionalArgs . length !== 0 ? positionalArgs : [ "." ] ) ;
46+ let cwd : string | undefined ;
47+ let invocation = [ process . env [ "JUST_EXECUTABLE" ] || "just" ] ;
48+ if ( positionalArgs . length === 1 && justfile == path . join ( positionalArgs [ 0 ] , "justfile" ) ) {
49+ // If there's only one positional argument and it matches the justfile path, suppress arguments
50+ // so for example `just build ql/rust` becomes `just build` in the `ql/rust` directory
51+ cwd = positionalArgs [ 0 ] ;
52+ invocation . push (
53+ cmd ,
54+ ...flags ,
55+ ) ;
56+ console . log ( `-> cd ${ cwd } ; just ${ invocation . slice ( 1 ) . join ( " " ) } ` ) ;
57+ } else {
58+ cwd = undefined ;
59+ invocation . push (
60+ "--justfile" ,
61+ justfile ,
62+ cmd ,
63+ ...flags ,
64+ ...positionalArgs ,
65+ ) ;
66+ console . log ( `-> just ${ invocation . slice ( 1 ) . join ( " " ) } ` ) ;
4867 }
4968
50- const justfile = commonJustfile ( positionalArgs ) ;
51-
52- const invocation = [
53- process . env [ "JUST_EXECUTABLE" ] || "just" ,
54- "--justfile" ,
55- justfile ,
56- cmd ,
57- ...flags ,
58- ...positionalArgs ,
59- ] ;
60- console . log ( `-> just ${ invocation . slice ( 1 ) . join ( " " ) } ` ) ;
6169 try {
6270 child_process . execFileSync ( invocation [ 0 ] , invocation . slice ( 1 ) , {
6371 stdio : "inherit" ,
72+ cwd,
6473 } ) ;
6574 } catch ( error ) {
6675 return 1 ;
0 commit comments