Skip to content

Commit

Permalink
✨ some subcommands can be run from outside the game directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mleduque committed Jun 14, 2024
1 parent 938eed3 commit 6fcf9c3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
10 changes: 6 additions & 4 deletions modda-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ fn main() -> Result<()> {
let current_dir = std::env::current_dir()?;
let current_dir = CanonPath::new(current_dir)?;

if ensure_chitin_key().is_err() {
bail!("Must be run from the game directory (where chitin.key is)");
} else {
debug!("chitin.key found");
if cli.command.wants_chitin_key() {
if ensure_chitin_key().is_err() {
bail!("Must be run from the game directory (where chitin.key is)");
} else {
debug!("chitin.key found");
}
}
let settings = Settings::read_settings(&current_dir)?;
let config = &settings.combined;
Expand Down
1 change: 1 addition & 0 deletions modda-cli/src/subcommands/introspect.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use std::path::PathBuf;

use anyhow::Result;
Expand Down
20 changes: 20 additions & 0 deletions modda-lib/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ pub enum Commands {
GlobalConfig(ConfigArgs)
}

impl Commands {
pub fn wants_chitin_key(&self) -> bool {
match self {
Commands::Install(..) => true,
Commands:: Search(..) => false,
Commands::ListComponents(..) => true,
Commands::Invalidate(..) => false,
Commands::Reverse(..) => true,
Commands::AppendMod(..) => true,
Commands::Reset(..) => true,
Commands::Discover(..) => true,
Commands::Introspect(..) => true,
Commands::GlobalConfig(variant) => match variant {
ConfigArgs::Edit(..) => false,
ConfigArgs::Show(..) => false,
}
}
}
}

#[derive(Args, Debug, Default)]
pub struct Install {

Expand Down

0 comments on commit 6fcf9c3

Please sign in to comment.