Skip to content

Commit

Permalink
Move Backend enum into cli module
Browse files Browse the repository at this point in the history
  • Loading branch information
bikeshedder committed Jan 18, 2024
1 parent af5b597 commit a4dedcc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/cli/schema/check.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use anyhow::Result;
use clap::Parser;

use crate::{config::Config, Backend};
use crate::config::Config;

use super::Backend;

#[derive(Debug, Parser)]
pub struct CheckArgs {
Expand Down
6 changes: 5 additions & 1 deletion src/cli/schema/diff.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use anyhow::Result;
use clap::Parser;

use crate::{config::Config, Backend};
use crate::config::Config;

use super::Backend;

#[derive(Debug, Parser)]
pub struct DiffArgs {
Expand Down Expand Up @@ -30,6 +32,8 @@ pub struct DiffArgs {
pub async fn cmd(cfg: &Config, args: &DiffArgs) -> Result<()> {
let client = cfg.database.connect().await?;
let res = tusker_schema::inspect(&client).await?;
// Prepare from backend

// FIXME this is work in progress
for schema in res.values() {
for table in schema.tables.values() {
Expand Down
18 changes: 17 additions & 1 deletion src/cli/schema/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use clap::{Parser, Subcommand, ValueEnum};

use crate::config::Config;

Expand Down Expand Up @@ -39,3 +39,19 @@ pub async fn cmd(cfg: &Config, args: &SchemaCommand) -> Result<()> {
}
Ok(())
}

#[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq)]
enum Backend {
Migrations,
Schema,
Database,
}

impl std::fmt::Display for Backend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.to_possible_value()
.expect("no values are skipped")
.get_name()
.fmt(f)
}
}
16 changes: 0 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,6 @@ use config::Config;
pub mod cli;
pub mod config;

#[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq)]
enum Backend {
Migrations,
Schema,
Database,
}

impl std::fmt::Display for Backend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.to_possible_value()
.expect("no values are skipped")
.get_name()
.fmt(f)
}
}

#[tokio::main]
async fn main() -> Result<()> {
let cfg = Config::new()?;
Expand Down

0 comments on commit a4dedcc

Please sign in to comment.