-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46bef10
commit b8cc3ab
Showing
18 changed files
with
345 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,43 @@ | ||
//TODO | ||
//TODO | ||
|
||
|
||
use clap::Args; | ||
use paradox_file::{Config, PdxFile, YmlFile}; | ||
use crate::common::Id; | ||
|
||
#[derive(Debug, Args)] | ||
pub struct CmdArgs { | ||
/// province ID | ||
#[arg(short, long)] | ||
id: u16, | ||
|
||
/// Rename province to | ||
#[arg(short, long)] | ||
to: String, | ||
|
||
// rename capital to | ||
#[arg(short, long)] | ||
capital: Option<String>, | ||
|
||
// priority(?) of province localisation | ||
#[arg(short, long)] | ||
priority: Option<u8> | ||
} | ||
|
||
pub fn run(args: CmdArgs) { | ||
let cfg = Config::current(); | ||
let mut yml = YmlFile::load_localisation(&cfg).unwrap(); | ||
yml.replace_or_add_key_name(args.id, args.to.clone(), args.priority); | ||
|
||
let mut file = PdxFile::pull(&cfg, "history/provinces/", &Id(args.id)).unwrap(); | ||
|
||
if let Some(capital) = args.capital { | ||
if !file.contents.mutate_kv("capital", | ||
|kv| kv.set_value(capital.clone())) { | ||
file.contents.insert_kv(0,"capital", capital.clone()) | ||
} | ||
} | ||
|
||
file.rename_prov_name(args.id, args.to).unwrap(); | ||
file.save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use std::fmt::{Debug, Display}; | ||
use std::io; | ||
use std::path::PathBuf; | ||
|
||
pub trait AsFilename: Debug { | ||
fn as_filename(&self, dir: &PathBuf) -> io::Result<String>; | ||
} | ||
|
||
impl AsFilename for &str { | ||
fn as_filename(&self, dir: &PathBuf) -> io::Result<String> { | ||
as_filename_inner(self, dir) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct Filename(pub(crate) String); | ||
|
||
impl AsFilename for Filename { | ||
fn as_filename(&self, dir: &PathBuf) -> io::Result<String> { | ||
as_filename_inner(&self.0, dir) | ||
} | ||
} | ||
|
||
fn as_filename_inner<T: Display>(from: &T, dir: &PathBuf) -> io::Result<String> { | ||
match dir.to_str() { | ||
None => Err(io::Error::new(io::ErrorKind::Unsupported, | ||
"Could not parse filename")), | ||
Some(dir) => Ok(format!("{dir}/{from}")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.