@@ -87,6 +87,10 @@ impl Subcommand {
8787 return Self :: edit ( & search) ;
8888 }
8989
90+ if matches ! ( self , Format ) {
91+ return Self :: format ( config, loader, & search) ;
92+ }
93+
9094 let compilation = Self :: compile ( config, loader, & search) ?;
9195 let justfile = & compilation. justfile ;
9296
@@ -98,15 +102,16 @@ impl Subcommand {
98102 justfile. run ( config, & search, & [ ] ) ?;
99103 }
100104 Dump => Self :: dump ( config, compilation) ?,
101- Format => Self :: format ( config, & search, compilation) ?,
102105 Groups => Self :: groups ( config, justfile) ,
103106 List { path } => Self :: list ( config, justfile, path) ?,
104107 Run { arguments } => Self :: run ( config, loader, search, compilation, arguments) ?,
105108 Show { path } => Self :: show ( config, justfile, path) ?,
106109 Summary => Self :: summary ( config, justfile) ,
107110 Usage { path } => Self :: usage ( config, justfile, path) ?,
108111 Variables => Self :: variables ( justfile) ,
109- Changelog | Completions { .. } | Edit | Init | Man | Request { .. } => unreachable ! ( ) ,
112+ Changelog | Completions { .. } | Edit | Format | Init | Man | Request { .. } => {
113+ unreachable ! ( )
114+ }
110115 }
111116
112117 Ok ( ( ) )
@@ -324,12 +329,29 @@ impl Subcommand {
324329 Ok ( ( ) )
325330 }
326331
327- fn format ( config : & Config , search : & Search , compilation : Compilation ) -> RunResult < ' static > {
328- let justfile = & compilation. justfile ;
329- let src = compilation. root_src ( ) ;
330- let ast = compilation. root_ast ( ) ;
332+ fn format < ' src > ( config : & Config , loader : & ' src Loader , search : & Search ) -> RunResult < ' src > {
333+ let root = search. justfile . parent ( ) . unwrap ( ) ;
334+
335+ let ( path, src) = loader. load ( root, & search. justfile ) ?;
336+
337+ let ast = Parser :: parse_source ( path, src, & Source :: root ( & search. justfile ) ) ?;
331338
332- config. require_unstable ( justfile, UnstableFeature :: FormatSubcommand ) ?;
339+ let unstable = config. unstable
340+ || ast. items . iter ( ) . any ( |item| {
341+ matches ! (
342+ item,
343+ Item :: Set ( Set {
344+ value: Setting :: Unstable ( true ) ,
345+ ..
346+ } )
347+ )
348+ } ) ;
349+
350+ if !unstable {
351+ return Err ( Error :: UnstableFeature {
352+ unstable_feature : UnstableFeature :: FormatSubcommand ,
353+ } ) ;
354+ }
333355
334356 let formatted = ast. to_string ( ) ;
335357
0 commit comments