Skip to content

Commit c73059c

Browse files
committed
Implement cli
1 parent 42e56e1 commit c73059c

File tree

8 files changed

+278
-0
lines changed

8 files changed

+278
-0
lines changed

Cargo.lock

Lines changed: 182 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "vespertide-cli"
3+
version = "0.1.0"
4+
edition = "2024"
5+
publish = false
6+
7+
[dependencies]
8+
anyhow = "1"
9+
clap = { version = "4", features = ["derive"] }
10+
serde_json = "1"
11+
vespertide-config = { path = "../vespertide-config" }
12+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use anyhow::Result;
2+
3+
pub fn cmd_diff() -> Result<()> {
4+
println!("(todo) diff: compare applied migrations and current models");
5+
Ok(())
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::{fs, path::PathBuf};
2+
3+
use anyhow::{bail, Context, Result};
4+
use vespertide_config::VespertideConfig;
5+
6+
pub fn cmd_init() -> Result<()> {
7+
let path = PathBuf::from("vespertide.json");
8+
if path.exists() {
9+
bail!("vespertide.json already exists");
10+
}
11+
12+
let config = VespertideConfig::default();
13+
let json = serde_json::to_string_pretty(&config).context("serialize default config")?;
14+
fs::write(&path, json).context("write vespertide.json")?;
15+
println!("created {:?}", path);
16+
Ok(())
17+
}
18+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub mod diff;
2+
pub mod init;
3+
pub mod revision;
4+
pub mod status;
5+
6+
pub use diff::cmd_diff;
7+
pub use init::cmd_init;
8+
pub use revision::cmd_revision;
9+
pub use status::cmd_status;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use anyhow::Result;
2+
3+
pub fn cmd_revision(message: String) -> Result<()> {
4+
println!("(todo) revision: create new revision with message: {message}");
5+
Ok(())
6+
}
7+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use anyhow::Result;
2+
3+
pub fn cmd_status() -> Result<()> {
4+
println!("(todo) status: show current migration/application state");
5+
Ok(())
6+
}

crates/vespertide-cli/src/main.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use anyhow::Result;
2+
use clap::{Parser, Subcommand};
3+
4+
mod commands;
5+
use commands::{cmd_diff, cmd_init, cmd_revision, cmd_status};
6+
7+
/// vespertide command-line interface.
8+
#[derive(Parser, Debug)]
9+
#[command(name = "vespertide", author, version, about)]
10+
struct Cli {
11+
#[command(subcommand)]
12+
command: Commands,
13+
}
14+
15+
#[derive(Subcommand, Debug)]
16+
enum Commands {
17+
/// Show diff between applied migrations and current models.
18+
Diff,
19+
/// Show current status.
20+
Status,
21+
/// Create a new revision with a message.
22+
Revision {
23+
#[arg(short = 'm', long = "message")]
24+
message: String,
25+
},
26+
/// Initialize vespertide.json with defaults.
27+
Init,
28+
}
29+
30+
fn main() -> Result<()> {
31+
let cli = Cli::parse();
32+
match cli.command {
33+
Commands::Diff => cmd_diff(),
34+
Commands::Status => cmd_status(),
35+
Commands::Revision { message } => cmd_revision(message),
36+
Commands::Init => cmd_init(),
37+
}
38+
}

0 commit comments

Comments
 (0)