Skip to content

Commit 24f32b3

Browse files
committed
Implement format and file pattern
1 parent 562e138 commit 24f32b3

File tree

14 files changed

+465
-48
lines changed

14 files changed

+465
-48
lines changed

Cargo.lock

Lines changed: 228 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vespertide-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ publish = false
77
[dependencies]
88
anyhow = "1"
99
clap = { version = "4", features = ["derive"] }
10+
chrono = { version = "0.4", default-features = false, features = ["clock", "serde"] }
1011
serde_json = "1"
1112
serde_yaml = "0.9"
1213
schemars = "1.1"

crates/vespertide-cli/src/commands/log.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pub fn cmd_log() -> Result<()> {
1616

1717
for plan in &plans {
1818
println!("Version: {}", plan.version);
19+
if let Some(created) = &plan.created_at {
20+
println!("Created at: {}", created);
21+
}
1922
if let Some(comment) = &plan.comment {
2023
println!("Comment: {}", comment);
2124
}

crates/vespertide-cli/src/commands/new.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ use anyhow::{Context, Result, bail};
44
use serde_json::Value;
55
use 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

Comments
 (0)