Skip to content

Commit

Permalink
feature: make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
shenek committed Jan 19, 2024
1 parent ae41ca7 commit a219ea8
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 160 deletions.
113 changes: 8 additions & 105 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 ucelofka-data/src/invoice/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Invoice {
.iter()
.map(|i| i.id + 1)
.max()
.unwrap_or_else(|| Utc::today().naive_utc().year() as u64 * 100_000 + 1)
.unwrap_or_else(|| Utc::now().date_naive().year() as u64 * 100_000 + 1)
}

pub fn new(
Expand All @@ -86,7 +86,7 @@ impl Invoice {
Self {
_version: VERSION,
id: new_id,
issue_day: Utc::today().format("%Y-%m-%d").to_string(),
issue_day: Utc::now().format("%Y-%m-%d").to_string(),
due_day: (Utc::now() + Duration::days(DEFAULT_DUE))
.format("%Y-%m-%d")
.to_string(),
Expand Down
4 changes: 2 additions & 2 deletions ucelofka-data/src/invoice/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl Invoice {
.iter()
.map(|i| i.id + 1)
.max()
.unwrap_or_else(|| Utc::today().naive_utc().year() as u64 * 100_000 + 1)
.unwrap_or_else(|| Utc::now().date_naive().year() as u64 * 100_000 + 1)
}

pub fn new(
Expand All @@ -110,7 +110,7 @@ impl Invoice {
Self {
_version: VERSION,
id: new_id,
issue_date: Utc::today().format("%Y-%m-%d").to_string(),
issue_date: Utc::now().format("%Y-%m-%d").to_string(),
due_date: (Utc::now()
+ Duration::days(
due.map(|v| i64::try_from(v).unwrap())
Expand Down
2 changes: 1 addition & 1 deletion ucelofka/src/actions/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn ids(data_path: &Path) -> Result<String> {

pub fn list(data_path: &Path) -> Result<Accounts> {
let account_path = data_path.join(Path::new("accounts"));
Ok(Accounts::load(account_path.as_path())?)
Accounts::load(account_path.as_path())
}

pub fn get(data_path: &Path, id: &str) -> Result<Account> {
Expand Down
6 changes: 3 additions & 3 deletions ucelofka/src/actions/customer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ pub fn ids(data_path: &Path) -> Result<String> {

pub fn list(data_path: &Path) -> Result<Customers> {
let customer_path = data_path.join(Path::new("customers"));
Ok(Customers::load(customer_path.as_path())?)
Customers::load(customer_path.as_path())
}

pub fn get(data_path: &Path, id: &str) -> Result<Customer> {
Ok(list(data_path)?
list(data_path)?
.get(id)
.ok_or_else(|| anyhow!("Customer {} not found.", id))?)
.ok_or_else(|| anyhow!("Customer {} not found.", id))
}
6 changes: 3 additions & 3 deletions ucelofka/src/actions/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ pub fn ids(data_path: &Path) -> Result<String> {

pub fn list(data_path: &Path) -> Result<Entries> {
let entry_path = data_path.join(Path::new("entries"));
Ok(Entries::load(entry_path.as_path())?)
Entries::load(entry_path.as_path())
}

pub fn get(data_path: &Path, id: &str) -> Result<Entry> {
Ok(list(data_path)?
list(data_path)?
.get(id)
.ok_or_else(|| anyhow!("Entry {} not found.", id))?)
.ok_or_else(|| anyhow!("Entry {} not found.", id))
}

pub fn create(
Expand Down
6 changes: 3 additions & 3 deletions ucelofka/src/actions/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ pub fn ids(data_path: &Path) -> Result<String> {

pub fn list(data_path: &Path) -> Result<Identities> {
let identity_path = data_path.join(Path::new("identities"));
Ok(Identities::load(identity_path.as_path())?)
Identities::load(identity_path.as_path())
}

pub fn get(data_path: &Path, id: &str) -> Result<Identity> {
Ok(list(data_path)?
list(data_path)?
.get(id)
.ok_or_else(|| anyhow!("Identity {} not found.", id))?)
.ok_or_else(|| anyhow!("Identity {} not found.", id))
}
2 changes: 1 addition & 1 deletion ucelofka/src/actions/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn ids(data_path: &Path) -> Result<String> {
result += &template::list(data_path)?
.templates
.iter()
.map(|template| format!("{}\n", template.name))
.map(|template| template.name.clone() + "\n")
.collect::<String>();

Ok(result)
Expand Down
17 changes: 8 additions & 9 deletions ucelofka/src/actions/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ struct WrappedInvoice(Invoice);
impl TryFrom<WrappedInvoice> for Context {
type Error = anyhow::Error;
fn try_from(wrapped_invoice: WrappedInvoice) -> Result<Self> {
Ok(Self::from_serialize(wrapped_invoice.0).map_err(anyhow::Error::from)?)
Self::from_serialize(wrapped_invoice.0).map_err(anyhow::Error::from)
}
}

impl Into<WrappedInvoice> for Invoice {
fn into(self) -> WrappedInvoice {
WrappedInvoice(self)
impl From<Invoice> for WrappedInvoice {
fn from(val: Invoice) -> Self {
WrappedInvoice(val)
}
}

Expand Down Expand Up @@ -75,8 +75,7 @@ pub fn create(
.map_err(|err| anyhow!("{}", err))?;

if git {
let git_path =
Path::new("invoices").join(Path::new(&format!("{}.yml", new_invoice.id.to_string())));
let git_path = Path::new("invoices").join(Path::new(&format!("{}.yml", new_invoice.id)));
let repo = Repository::open(data_path)
.map_err(|err| anyhow!("Faield to open git repository {}", err))?;

Expand Down Expand Up @@ -106,13 +105,13 @@ pub fn ids(data_path: &Path) -> Result<String> {

pub fn list(data_path: &Path) -> Result<Invoices> {
let invoice_path = data_path.join(Path::new("invoices"));
Ok(Invoices::load(invoice_path.as_path())?)
Invoices::load(invoice_path.as_path())
}

pub fn get(data_path: &Path, id: &str) -> Result<Invoice> {
Ok(list(data_path)?
list(data_path)?
.get(id)
.ok_or_else(|| anyhow!("Invoice {} not found.", id))?)
.ok_or_else(|| anyhow!("Invoice {} not found.", id))
}

pub fn render(data_path: &Path, invoice: &str, template: &str, git: bool) -> Result<String> {
Expand Down
2 changes: 1 addition & 1 deletion ucelofka/src/actions/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::data::template::{Template, Templates};

pub fn list(data_path: &Path) -> Result<Templates> {
let templates_path = data_path.join(Path::new("templates"));
Ok(Templates::load(templates_path.as_path())?)
Templates::load(templates_path.as_path())
}

pub fn get(data_path: &Path, id: &str) -> Result<Template> {
Expand Down
Loading

0 comments on commit a219ea8

Please sign in to comment.