-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
7 changed files
with
73 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,10 @@ jobs: | |
run: git clone https://github.com/coredump-ch/gitcash-demo-repo/ | ||
- name: Build | ||
run: cargo build | ||
- name: Create config | ||
run: echo -e "repo_path = 'gitcash-demo-repo'\naccount = 'pos:fridge'\ngit_name = 'CI'\ngit_email = '[email protected]'" > config.toml | ||
- name: Calculate balances | ||
run: target/debug/gitcash --repo-path gitcash-demo-repo balances | ||
run: target/debug/gitcash balances | ||
|
||
rustfmt: | ||
name: Check code formatting | ||
|
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,2 +1,3 @@ | ||
/target | ||
/Cargo.lock | ||
/config.toml |
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,38 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use anyhow::{bail, Context}; | ||
use libgitcash::{Account, AccountType}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// GitCash configuration | ||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct Config { | ||
/// Path to the GitCash repository to use | ||
pub repo_path: PathBuf, | ||
|
||
/// Account corresponding to this PoS | ||
pub account: Account, | ||
|
||
/// Name to use for git commits | ||
pub git_name: String, | ||
/// E-mail to use for git commits | ||
pub git_email: String, | ||
} | ||
|
||
impl Config { | ||
/// Load config from the specified config path | ||
pub fn load(config_path: &Path) -> anyhow::Result<Self> { | ||
let config_string: String = std::fs::read_to_string(config_path) | ||
.context(format!("Could not read config from {:?}", config_path))?; | ||
let config: Self = toml::from_str(&config_string) | ||
.context(format!("Could not parse config at {:?}", config_path))?; | ||
if config.account.account_type != AccountType::PointOfSale { | ||
bail!( | ||
"Account type must be {:?}, not {:?}", | ||
AccountType::PointOfSale, | ||
config.account.account_type | ||
); | ||
} | ||
Ok(config) | ||
} | ||
} |
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