-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.rs
67 lines (60 loc) · 1.84 KB
/
cli.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::{
config::Config,
init::handle_init,
migrate::{handle_migrate, handle_remigrate},
poop::handle_poop,
};
use anyhow::Result;
use std::path::PathBuf;
use structopt::StructOpt;
#[derive(StructOpt)]
/// PostgreSQL migration tool
#[structopt(name = "seagull")]
pub enum Seagull {
#[structopt(name = "poop")]
Poop { description: String },
Migrate {
#[structopt(long)]
url: Option<String>,
#[structopt(long)]
dir: Option<String>,
},
Remigrate {
#[structopt(long)]
database: Option<String>,
#[structopt(long)]
dir: Option<String>,
},
/// Sets up the "seagull.toml" config file
Init {},
}
pub fn run(args: Seagull) -> Result<()> {
match args {
Seagull::Poop { description } => {
let config = Config::from_file(PathBuf::from("seagull.toml"))?;
handle_poop(description, config.migrations.dir_path)?;
}
Seagull::Migrate { url, dir } => {
let dir_path = dir.unwrap_or_else(|| String::from("migrations"));
if let Some(c) = url {
handle_migrate(c, dir_path)?;
} else {
let config = Config::from_file(PathBuf::from("seagull.toml"))?;
handle_migrate(config.postgres.connection_string(), dir_path)?;
}
}
Seagull::Remigrate { database, dir } => {
let dir_path = dir.unwrap_or_else(|| String::from("migrations"));
if let Some(c) = database {
handle_remigrate(c, dir_path)?;
} else {
let config = Config::from_file(PathBuf::from("seagull.toml"))?;
handle_remigrate(config.postgres.connection_string(), dir_path)?;
}
}
Seagull::Init {} => {
handle_init()?;
}
}
Ok(())
}