cli: fix global -y flag conflicts in add-prj` and sync commands
`AddPrjArgs` had a local `-y` flag that conflicted with the global flag, causing runtime panics. Removed the local field and updated callers to use `global_yes` consistently. The sync command now respects the global `-y` flag by accepting, you guessed it, the `global_yes` parameter. Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I7b7c42fabbca0e363bd18a1d8b6b3bb76a6a6964
This commit is contained in:
parent
d4938c4ae8
commit
b0a594e892
3 changed files with 81 additions and 50 deletions
73
src/main.rs
73
src/main.rs
|
|
@ -18,12 +18,31 @@ mod resolver;
|
|||
mod ui_utils;
|
||||
mod utils;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use clap::Parser;
|
||||
use cli::{Cli, Commands};
|
||||
use error::PakkerError;
|
||||
|
||||
/// Search for pakker-lock.json in current directory and parent directories
|
||||
/// Returns the directory containing pakker-lock.json, or None if not found
|
||||
fn find_working_directory() -> Option<PathBuf> {
|
||||
let mut current_dir = env::current_dir().ok()?;
|
||||
|
||||
loop {
|
||||
let lockfile = current_dir.join("pakker-lock.json");
|
||||
if lockfile.exists() {
|
||||
return Some(current_dir);
|
||||
}
|
||||
|
||||
// Try parent directory
|
||||
if !current_dir.pop() {
|
||||
// Reached filesystem root
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), PakkerError> {
|
||||
let cli = Cli::parse();
|
||||
|
|
@ -43,19 +62,41 @@ async fn main() -> Result<(), PakkerError> {
|
|||
.format_module_path(false)
|
||||
.init();
|
||||
|
||||
let working_dir = PathBuf::from(".");
|
||||
// Search for pakker-lock.json in current directory and parent directories
|
||||
let working_dir =
|
||||
find_working_directory().unwrap_or_else(|| PathBuf::from("."));
|
||||
let lockfile_path = working_dir.join("pakker-lock.json");
|
||||
let config_path = working_dir.join("pakker.json");
|
||||
|
||||
let global_yes = cli.yes;
|
||||
|
||||
match cli.command {
|
||||
Commands::Init(args) => {
|
||||
cli::commands::init::execute(args, &lockfile_path, &config_path).await
|
||||
cli::commands::init::execute(
|
||||
args,
|
||||
global_yes,
|
||||
&lockfile_path,
|
||||
&config_path,
|
||||
)
|
||||
.await
|
||||
},
|
||||
Commands::Import(args) => {
|
||||
cli::commands::import::execute(args, &lockfile_path, &config_path).await
|
||||
cli::commands::import::execute(
|
||||
args,
|
||||
global_yes,
|
||||
&lockfile_path,
|
||||
&config_path,
|
||||
)
|
||||
.await
|
||||
},
|
||||
Commands::Add(args) => {
|
||||
cli::commands::add::execute(args, &lockfile_path, &config_path).await
|
||||
cli::commands::add::execute(
|
||||
args,
|
||||
global_yes,
|
||||
&lockfile_path,
|
||||
&config_path,
|
||||
)
|
||||
.await
|
||||
},
|
||||
Commands::AddPrj(args) => {
|
||||
cli::commands::add_prj::execute(
|
||||
|
|
@ -70,17 +111,24 @@ async fn main() -> Result<(), PakkerError> {
|
|||
args.aliases,
|
||||
args.export,
|
||||
args.no_deps,
|
||||
args.yes,
|
||||
global_yes,
|
||||
&lockfile_path,
|
||||
&config_path,
|
||||
)
|
||||
.await
|
||||
},
|
||||
Commands::Rm(args) => {
|
||||
cli::commands::rm::execute(args, &lockfile_path, &config_path).await
|
||||
cli::commands::rm::execute(args, global_yes, &lockfile_path, &config_path)
|
||||
.await
|
||||
},
|
||||
Commands::Update(args) => {
|
||||
cli::commands::update::execute(args, &lockfile_path, &config_path).await
|
||||
cli::commands::update::execute(
|
||||
args,
|
||||
global_yes,
|
||||
&lockfile_path,
|
||||
&config_path,
|
||||
)
|
||||
.await
|
||||
},
|
||||
Commands::Ls(args) => cli::commands::ls::execute(args, &lockfile_path),
|
||||
Commands::Set(args) => {
|
||||
|
|
@ -95,7 +143,13 @@ async fn main() -> Result<(), PakkerError> {
|
|||
cli::commands::fetch::execute(args, &lockfile_path, &config_path).await
|
||||
},
|
||||
Commands::Sync(args) => {
|
||||
cli::commands::sync::execute(args, &lockfile_path, &config_path).await
|
||||
cli::commands::sync::execute(
|
||||
args,
|
||||
global_yes,
|
||||
&lockfile_path,
|
||||
&config_path,
|
||||
)
|
||||
.await
|
||||
},
|
||||
Commands::Export(args) => {
|
||||
cli::commands::export::execute(args, &lockfile_path, &config_path).await
|
||||
|
|
@ -107,6 +161,7 @@ async fn main() -> Result<(), PakkerError> {
|
|||
Commands::Status(args) => {
|
||||
cli::commands::status::execute(
|
||||
args.parallel,
|
||||
global_yes,
|
||||
&lockfile_path,
|
||||
&config_path,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue