Skip to content

Commit

Permalink
Add Annual cost estimation format
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-mdr committed Feb 9, 2023
1 parent 7b17281 commit bdd00a1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub enum InputSource {
pub enum OutputFormat {
Hour,
Month,
Year,
Json,
Csv,
Ods,
Expand Down Expand Up @@ -83,6 +84,10 @@ impl Args {
error!("cannot aggregate with month format");
1
}
(true, OutputFormat::Year) => {
error!("cannot aggregate with annual format");
1
}
};
err_count += match (&self.output, &self.format) {
(Some(_), _) => 0,
Expand Down
4 changes: 4 additions & 0 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl Resources {
Ok(self.cost_per_hour()? * HOURS_PER_MONTH)
}

pub fn cost_per_year(&self) -> Result<f32, ResourceError> {
Ok(self.cost_per_hour()? * HOURS_PER_MONTH * 12.0)
}

pub fn json(&self) -> serde_json::Result<String> {
let mut out = String::new();
for resource in &self.resources {
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let output: Vec<u8> = match args.format {
OutputFormat::Hour => format!("{}", resources.cost_per_hour()?).into_bytes(),
OutputFormat::Month => format!("{}", resources.cost_per_month()?).into_bytes(),
OutputFormat::Year => format!("{}", resources.cost_per_year()?).into_bytes(),
OutputFormat::Json => resources.json()?.into_bytes(),
OutputFormat::Csv => resources.csv()?.into_bytes(),
OutputFormat::Ods => resources.ods()?,
Expand Down

0 comments on commit bdd00a1

Please sign in to comment.