main.rs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. use qif_generator::account::{Account, AccountType};
  2. use std::path::PathBuf;
  3. use structopt::StructOpt;
  4. mod categories;
  5. mod convert;
  6. mod import;
  7. mod receipt;
  8. #[cfg(feature = "telegram")]
  9. mod telegram;
  10. mod ui;
  11. mod user;
  12. /// Search for a pattern in a file and display the lines that contain it.
  13. #[derive(StructOpt)]
  14. struct Cli {
  15. #[structopt(parse(from_os_str), long, help = "Accounts csv file")]
  16. accounts: Option<PathBuf>,
  17. #[structopt(short, long)]
  18. database: Option<String>,
  19. #[structopt(short, long, default_value = "New")]
  20. memo: String,
  21. /// Run telegram bot
  22. #[cfg(feature = "telegram")]
  23. #[structopt(short, long)]
  24. telegram: bool,
  25. /// Run Turbo Vision UI
  26. #[cfg(feature = "tv")]
  27. #[structopt(long)]
  28. ui: bool,
  29. /// The path to the file to read
  30. #[structopt(required_unless_one = &["telegram", "ui"])]
  31. filename: Option<String>,
  32. }
  33. #[cfg(not(tarpaulin_include))]
  34. fn main() {
  35. let args = Cli::from_args();
  36. #[cfg(feature = "telegram")]
  37. if args.telegram {
  38. telegram::bot();
  39. return;
  40. }
  41. let mut user = user::User::new(0, &args.database);
  42. match args.accounts {
  43. None => (),
  44. Some(path) => user.accounts(import::read_accounts(&path).unwrap()),
  45. }
  46. #[cfg(feature = "tv")]
  47. {
  48. ui::run_tv();
  49. return;
  50. }
  51. // If program is used as command-line tool
  52. let acc = Account::new()
  53. .name("Wallet")
  54. .account_type(AccountType::Cash)
  55. .build();
  56. if let Some(filename) = &args.filename {
  57. let cat = &|item: &str, stats: &mut categories::CatStats| -> String {
  58. categories::get_category(&item, stats)
  59. };
  60. let t = convert::convert(filename, &args.memo, &mut user, &acc, &cat).unwrap();
  61. print!("{}", acc.to_string());
  62. println!("{}", t.to_string());
  63. }
  64. }