1
1
use std:: fmt:: Write ;
2
2
3
+ #[ cfg( feature = "cli" ) ]
4
+ use clap:: ValueEnum ;
5
+
3
6
use crate :: parsing:: {
4
7
ast:: types:: {
5
8
Annotation , ArrayExpression , ArrayRangeExpression , BinaryExpression , BinaryOperator , BinaryPart , BodyItem ,
@@ -864,10 +867,33 @@ impl Parameter {
864
867
}
865
868
}
866
869
867
- /// Collect all the kcl files in a directory, recursively.
870
+ lazy_static:: lazy_static! {
871
+
872
+ pub static ref IMPORT_FILE_EXTENSIONS : Vec <String > = {
873
+ let mut import_file_extensions = vec![ "stp" . to_string( ) , "glb" . to_string( ) , "fbxb" . to_string( ) ] ;
874
+ #[ cfg( feature = "cli" ) ]
875
+ let named_extensions = kittycad:: types:: FileImportFormat :: value_variants( )
876
+ . iter( )
877
+ . map( |x| format!( "{}" , x) )
878
+ . collect:: <Vec <String >>( ) ;
879
+ #[ cfg( not( feature = "cli" ) ) ]
880
+ let named_extensions = vec![ ] ; // We don't really need this outside of the CLI.
881
+ // Add all the default import formats.
882
+ import_file_extensions. extend_from_slice( & named_extensions) ;
883
+ import_file_extensions
884
+ } ;
885
+
886
+ pub static ref RELEVANT_EXTENSIONS : Vec <String > = {
887
+ let mut relevant_extensions = IMPORT_FILE_EXTENSIONS . clone( ) ;
888
+ relevant_extensions. push( "kcl" . to_string( ) ) ;
889
+ relevant_extensions
890
+ } ;
891
+ }
892
+
893
+ /// Collect all the kcl (and other relevant) files in a directory, recursively.
868
894
#[ cfg( not( target_arch = "wasm32" ) ) ]
869
895
#[ async_recursion:: async_recursion]
870
- pub ( crate ) async fn walk_dir ( dir : & std:: path:: PathBuf ) -> Result < Vec < std:: path:: PathBuf > , anyhow:: Error > {
896
+ pub async fn walk_dir ( dir : & std:: path:: PathBuf ) -> Result < Vec < std:: path:: PathBuf > , anyhow:: Error > {
871
897
// Make sure we actually have a directory.
872
898
if !dir. is_dir ( ) {
873
899
anyhow:: bail!( "`{}` is not a directory" , dir. display( ) ) ;
@@ -881,7 +907,10 @@ pub(crate) async fn walk_dir(dir: &std::path::PathBuf) -> Result<Vec<std::path::
881
907
882
908
if path. is_dir ( ) {
883
909
files. extend ( walk_dir ( & path) . await ?) ;
884
- } else if path. extension ( ) . is_some_and ( |ext| ext == "kcl" ) {
910
+ } else if path
911
+ . extension ( )
912
+ . is_some_and ( |ext| RELEVANT_EXTENSIONS . contains ( & ext. to_string_lossy ( ) . to_string ( ) ) )
913
+ {
885
914
files. push ( path) ;
886
915
}
887
916
}
@@ -901,6 +930,8 @@ pub async fn recast_dir(dir: &std::path::Path, options: &crate::FormatOptions) -
901
930
902
931
let futures = files
903
932
. into_iter ( )
933
+ . filter ( |file| file. extension ( ) . is_some_and ( |ext| ext == "kcl" ) ) // We only care about kcl
934
+ // files here.
904
935
. map ( |file| {
905
936
let options = options. clone ( ) ;
906
937
tokio:: spawn ( async move {
0 commit comments