use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
use std::path::PathBuf;
use std::str::FromStr;
use chrono::Local;
use chrono::NaiveDate;
use structopt::StructOpt;
const DEFAULT_INVESTMENT_ACCOUNT: &str = "Assets:Investments:Alpaca:Stock";
const DEFAULT_BROKERAGE_ACCOUNT: &str = "Assets:Alpaca Brokerage";
const DEFAULT_BROKERAGE_FEE_ACCOUNT: &str = "Expenses:Broker:Fee";
const DEFAULT_DIVIDEND_ACCOUNT: &str = "Income:Dividend";
const DEFAULT_SEC_FEE_ACCOUNT: &str = "Expenses:Broker:SEC Fee";
const DEFAULT_FINRA_TAF_ACCOUNT: &str = "Expenses:Broker:FINRA TAF";
#[derive(Debug, StructOpt)]
#[structopt(about)]
pub struct Args {
#[structopt(subcommand)]
pub command: Command,
#[structopt(short = "v", long = "verbose", global = true, parse(from_occurrences))]
pub verbosity: usize,
}
#[derive(Debug, StructOpt)]
pub enum Command {
Activity(Activity),
Prices(Prices),
}
#[derive(Debug, StructOpt)]
pub struct Activity {
pub registry: PathBuf,
#[structopt(short, long)]
pub begin: Option<NaiveDate>,
#[structopt(long)]
pub force_separate_fees: bool,
#[structopt(long, default_value = DEFAULT_INVESTMENT_ACCOUNT)]
pub investment_account: String,
#[structopt(long, default_value = DEFAULT_BROKERAGE_ACCOUNT)]
pub brokerage_account: String,
#[structopt(long, default_value = DEFAULT_BROKERAGE_FEE_ACCOUNT)]
pub brokerage_fee_account: String,
#[structopt(long, default_value = DEFAULT_DIVIDEND_ACCOUNT)]
pub dividend_account: String,
#[structopt(long, default_value = DEFAULT_SEC_FEE_ACCOUNT)]
pub sec_fee_account: String,
#[structopt(long, default_value = DEFAULT_FINRA_TAF_ACCOUNT)]
pub finra_taf_account: String,
}
#[derive(Debug)]
pub struct Date(pub NaiveDate);
impl Default for Date {
fn default() -> Self {
Self(Local::today().naive_local())
}
}
impl Display for Date {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
Display::fmt(&self.0, f)
}
}
impl FromStr for Date {
type Err = <NaiveDate as FromStr>::Err;
fn from_str(string: &str) -> Result<Self, Self::Err> {
NaiveDate::from_str(string).map(Self)
}
}
#[derive(Debug, StructOpt)]
pub struct Prices {
pub symbols: Vec<String>,
#[structopt(short, long, default_value)]
pub date: Date,
}