Skip to content

Commit

Permalink
Add argument helper method for files & paths
Browse files Browse the repository at this point in the history
Fixes a downcast issue with the upload command.
  • Loading branch information
nickelc committed Jan 10, 2024
1 parent 8a8a54a commit 545eeb0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/bin/modiom/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub trait ArgMatchesExt {
}

fn root_manifest(&self, config: &Config) -> io::Result<Cow<Path>> {
if let Some(path) = self._get_one::<PathBuf>("manifest-path") {
if let Some(path) = self.get_path("manifest-path") {
if !path.ends_with("Modio.toml") {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
Expand All @@ -79,6 +79,10 @@ pub trait ArgMatchesExt {
fn get_string(&self, id: &str) -> Option<&String> {
self._get_one::<String>(id)
}

fn get_path(&self, id: &str) -> Option<&PathBuf> {
self._get_one::<PathBuf>(id)
}
}

impl ArgMatchesExt for ArgMatches {
Expand Down
6 changes: 1 addition & 5 deletions src/bin/modiom/commands/download.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::borrow::Cow;
use std::collections::HashSet;
use std::path::PathBuf;

use tokio::runtime::Runtime;

Expand Down Expand Up @@ -41,10 +40,7 @@ pub fn exec(config: &Config, args: &ArgMatches) -> CliResult {
let game_id = *args.get_one("game-id").expect("required arg");
let mod_ids = args.get_many("mod-id").expect("required arg");
let _with_deps = args.get_flag("with-dependencies");
let dest = args
.get_one::<PathBuf>("dest")
.map(Cow::from)
.unwrap_or_default();
let dest = args.get_path("dest").map(Cow::from).unwrap_or_default();

let rt = Runtime::new()?;
let modio_ = client(config)?;
Expand Down
6 changes: 1 addition & 5 deletions src/bin/modiom/commands/upload.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::borrow::Cow;
use std::path::PathBuf;

use futures::{future::try_join3, StreamExt};
use prettytable::format;
Expand Down Expand Up @@ -65,10 +64,7 @@ pub fn cli() -> Command {
pub fn exec(config: &Config, args: &ArgMatches) -> CliResult {
let game_id = *args.get_one("game").expect("required arg");
let mod_id = *args.get_one("mod").expect("required arg");
let src = args
.get_string("src")
.map(PathBuf::from)
.expect("required arg");
let src = args.get_path("src").expect("required arg");

let rt = Runtime::new()?;
let modio = client(config)?;
Expand Down

0 comments on commit 545eeb0

Please sign in to comment.