22#![ feature( iter_advance_by) ]
33#![ feature( iter_intersperse) ]
44
5- use crate :: { analyze:: create_docs, url :: UrlPath , normalize :: Normalize } ;
5+ use crate :: { analyze:: create_docs, normalize :: Normalize , url :: UrlPath } ;
66use clap:: Parser ;
77use config:: Config ;
8- use std:: { fs, path:: { PathBuf , Path } , process:: exit, io, time:: Instant } ;
8+ use std:: {
9+ error:: Error ,
10+ fs, io,
11+ path:: { Path , PathBuf } ,
12+ process:: exit,
13+ time:: Instant ,
14+ } ;
915
1016mod analyze;
17+ mod annotation;
1118mod builder;
1219mod cmake;
1320mod config;
1421mod html;
15- mod url;
16- mod normalize;
17- mod annotation;
1822mod lookahead;
23+ mod normalize;
24+ mod url;
1925
2026#[ derive( Parser , Debug ) ]
2127#[ command( name( "Flash" ) , version, about) ]
@@ -31,6 +37,10 @@ struct Args {
3137 /// Whether to overwrite output directory if it already exists
3238 #[ arg( long, default_value_t = false ) ]
3339 overwrite : bool ,
40+
41+ /// Whether to skip invoking CMake entirely, relies on existing build dir.
42+ #[ arg( long, default_value_t = false , hide = true ) ]
43+ skip_build : bool ,
3444}
3545
3646fn remove_dir_contents < P : AsRef < Path > > ( path : P ) -> io:: Result < ( ) > {
@@ -49,7 +59,7 @@ fn remove_dir_contents<P: AsRef<Path>>(path: P) -> io::Result<()> {
4959}
5060
5161#[ tokio:: main]
52- async fn main ( ) -> Result < ( ) , String > {
62+ async fn main ( ) -> Result < ( ) , Box < dyn Error > > {
5363 let args = Args :: parse ( ) ;
5464
5565 // Check if output dir exists
@@ -59,19 +69,15 @@ async fn main() -> Result<(), String> {
5969 // Then overwrite must be specified
6070 && !args. overwrite
6171 {
62- println ! (
72+ eprintln ! (
6373 "Output directory {} already exists and no --overwrite option was specified, aborting" ,
64- args. output. to_str ( ) . unwrap ( )
74+ args. output. to_string_lossy ( )
6575 ) ;
6676 exit ( 1 ) ;
6777 }
6878
69- // Clear output dir if it exists
70- if args. output . exists ( ) {
71- remove_dir_contents ( & args. output ) . unwrap ( ) ;
72- }
73- else {
74- fs:: create_dir_all ( & args. output ) . unwrap ( ) ;
79+ if !args. output . exists ( ) {
80+ fs:: create_dir_all ( & args. output ) ?;
7581 }
7682
7783 let relative_output = if args. output . is_relative ( ) {
@@ -86,12 +92,12 @@ async fn main() -> Result<(), String> {
8692 let full_output = if args. output . is_absolute ( ) {
8793 args. output
8894 } else {
89- std:: env:: current_dir ( ) . unwrap ( ) . join ( args. output ) . normalize ( )
95+ std:: env:: current_dir ( ) ? . join ( args. output ) . normalize ( )
9096 } ;
9197 let full_input = if args. input . is_absolute ( ) {
9298 args. input
9399 } else {
94- std:: env:: current_dir ( ) . unwrap ( ) . join ( args. input ) . normalize ( )
100+ std:: env:: current_dir ( ) ? . join ( args. input ) . normalize ( )
95101 } ;
96102 std:: env:: set_current_dir ( & full_input) . expect (
97103 "Unable to set input dir as working directory \
@@ -107,8 +113,12 @@ async fn main() -> Result<(), String> {
107113 conf. project. name, conf. project. version
108114 ) ;
109115 let now = Instant :: now ( ) ;
110- create_docs ( conf. clone ( ) ) . await ?;
111- println ! ( "Docs built for {} in {}s" , conf. project. name, now. elapsed( ) . as_secs( ) ) ;
116+ create_docs ( conf. clone ( ) , args. skip_build ) . await ?;
117+ println ! (
118+ "Docs built for {} in {}s" ,
119+ conf. project. name,
120+ now. elapsed( ) . as_secs( )
121+ ) ;
112122
113123 Ok ( ( ) )
114124}
0 commit comments