Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use clio to check base directory #139

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 129 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions butane_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ anyhow = "1.0"
butane = { features = ["default", "pg", "sqlite"], workspace = true }
cargo_metadata = "0.17"
chrono = { workspace = true }
clap = { version = "4.1" }
lazy_static = "1.4"
clap = { version = "4.1", features = ["string"] }
clio = { version = "0.3.2", features = ["clap-parse"] }
quote = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
10 changes: 4 additions & 6 deletions butane_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use std::path::PathBuf;

use clap::{value_parser, Arg, ArgMatches};
use clio::ClioPath;

use butane_cli::{
base_dir, clean, clear_data, collapse_migrations, delete_table, embed, handle_error,
list_migrations, migrate, Result,
};

fn main() {
lazy_static::lazy_static! {
static ref WORKING_DIR_PATH: PathBuf = base_dir();
}
let app = clap::Command::new("butane")
.version(env!("CARGO_PKG_VERSION"))
.author("James Oakley <james@electronstudio.org>")
Expand All @@ -19,8 +17,8 @@ fn main() {
.max_term_width(80)
.arg(
Arg::new("path").short('p').long("path")
.default_value(WORKING_DIR_PATH.as_os_str())
.value_parser(value_parser!(PathBuf))
.default_value(base_dir().into_os_string())
.value_parser(value_parser!(ClioPath).exists().is_dir())
.help("Select directory to locate butane state")
)
.subcommand(
Expand Down Expand Up @@ -96,7 +94,7 @@ fn main() {
.about("Clean current migration state. Deletes the current migration working state which is generated on each build. This can be used as a workaround to remove stale tables from the schema, as Butane does not currently auto-detect model removals. The next build will recreate with only tables for the extant models."))
.arg_required_else_help(true);
let args = app.get_matches();
let mut base_dir = args.get_one::<PathBuf>("path").unwrap().clone();
let mut base_dir: PathBuf = args.get_one::<ClioPath>("path").unwrap().to_path_buf();
base_dir.push(".butane");
match args.subcommand() {
Some(("init", sub_args)) => handle_error(init(&base_dir, Some(sub_args))),
Expand Down