@@ -4,19 +4,21 @@ use anyhow::{Context, Result, bail};
44use serde_json:: Value ;
55use vespertide_core:: TableDef ;
66
7- use crate :: { ModelFormat , utils:: load_config} ;
7+ use crate :: utils:: load_config;
8+ use vespertide_config:: FileFormat ;
89
9- pub fn cmd_new ( name : String , format : ModelFormat ) -> Result < ( ) > {
10+ pub fn cmd_new ( name : String , format : Option < FileFormat > ) -> Result < ( ) > {
1011 let config = load_config ( ) ?;
12+ let format = format. unwrap_or_else ( || config. model_format ( ) ) ;
1113 let dir = config. models_dir ( ) ;
1214 if !dir. exists ( ) {
1315 fs:: create_dir_all ( dir) . context ( "create models directory" ) ?;
1416 }
1517
1618 let ext = match format {
17- ModelFormat :: Json => "json" ,
18- ModelFormat :: Yaml => "yaml" ,
19- ModelFormat :: Yml => "yml" ,
19+ FileFormat :: Json => "json" ,
20+ FileFormat :: Yaml => "yaml" ,
21+ FileFormat :: Yml => "yml" ,
2022 } ;
2123
2224 let schema_url = schema_url_for ( format) ;
@@ -33,15 +35,15 @@ pub fn cmd_new(name: String, format: ModelFormat) -> Result<()> {
3335 } ;
3436
3537 match format {
36- ModelFormat :: Json => write_json_with_schema ( & path, & table, & schema_url) ?,
37- ModelFormat :: Yaml | ModelFormat :: Yml => write_yaml ( & path, & table, & schema_url) ?,
38+ FileFormat :: Json => write_json_with_schema ( & path, & table, & schema_url) ?,
39+ FileFormat :: Yaml | FileFormat :: Yml => write_yaml ( & path, & table, & schema_url) ?,
3840 }
3941
4042 println ! ( "Created model template: {}" , path. display( ) ) ;
4143 Ok ( ( ) )
4244}
4345
44- fn schema_url_for ( format : ModelFormat ) -> String {
46+ fn schema_url_for ( format : FileFormat ) -> String {
4547 // If not set, default to public raw GitHub schema location.
4648 // Users can override via VESP_SCHEMA_BASE_URL.
4749 let base = std:: env:: var ( "VESP_SCHEMA_BASE_URL" ) . ok ( ) ;
@@ -50,8 +52,8 @@ fn schema_url_for(format: ModelFormat) -> String {
5052 ) ;
5153 let base = base. trim_end_matches ( '/' ) ;
5254 match format {
53- ModelFormat :: Json => format ! ( "{}/model.schema.json" , base) ,
54- ModelFormat :: Yaml | ModelFormat :: Yml => format ! ( "{}/model.schema.json" , base) ,
55+ FileFormat :: Json => format ! ( "{}/model.schema.json" , base) ,
56+ FileFormat :: Yaml | FileFormat :: Yml => format ! ( "{}/model.schema.json" , base) ,
5557 }
5658}
5759
0 commit comments