-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from gak/7-refactor-api
- Loading branch information
Showing
12 changed files
with
303 additions
and
195 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
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 |
---|---|---|
@@ -1,37 +1,3 @@ | ||
pub mod energy; | ||
pub mod powerwall; | ||
pub mod vehicle; | ||
|
||
use crate::error::TeslatteError; | ||
use crate::ResponseData; | ||
use std::process::exit; | ||
|
||
pub fn print_json<T>(result: Result<ResponseData<T>, TeslatteError>) { | ||
match result { | ||
Ok(data) => print_json_data(data), | ||
Err(TeslatteError::ServerError { ref body, .. }) if body.is_some() => { | ||
print_json_str(&body.clone().unwrap()) | ||
} | ||
Err(e) => { | ||
eprintln!("{}", e); | ||
exit(1); | ||
} | ||
} | ||
} | ||
pub fn print_json_data<T>(data: ResponseData<T>) { | ||
// TODO: pretty print cli option | ||
print_json_str(data.body()); | ||
} | ||
|
||
pub fn print_json_str(body: &str) { | ||
#[cfg(feature = "cli-pretty-json")] | ||
{ | ||
use colored_json::prelude::*; | ||
println!("{}", body.to_colored_json_auto().unwrap()); | ||
} | ||
|
||
#[cfg(not(feature = "cli-pretty-json"))] | ||
{ | ||
println!("{}", body); | ||
} | ||
} |
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
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
Oops, something went wrong.