diff --git a/Cargo.toml b/Cargo.toml index 8e31d21..7aec22e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,9 +5,11 @@ description = "A Rust crate for querying the Tesla API." edition = "2021" license = "MIT OR Apache-2.0" -[lib] -name = "teslatte" -path = "src/lib.rs" +[features] +default = ["cli", "fancy"] + +fancy = ["miette/fancy"] +cli = ["dep:clap", "dep:tracing-subscriber"] [dependencies] miette = { version = "5.1", features = ["fancy"] } @@ -26,7 +28,8 @@ urlencoding = "2.1.0" derive_more = "0.99" pkce = "0.2.0" +clap = { version = "3.2", features = ["derive", "env"], optional = true } +tracing-subscriber = { version = "0.3.17", optional = true } + [dev-dependencies] -test-log = { version = "0.2", default-features = false, features = ["trace"] } -tracing-subscriber = "0.3" -clap = { version = "3.2", features = ["derive", "env"]} +test-log = { version = "0.2.12", default-features = false, features = ["trace"] } diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..1843cfc --- /dev/null +++ b/src/cli.rs @@ -0,0 +1 @@ +pub mod vehicle; diff --git a/examples/cli_vehicle.rs b/src/cli/vehicle.rs similarity index 92% rename from examples/cli_vehicle.rs rename to src/cli/vehicle.rs index 845b0c9..2892f7d 100644 --- a/examples/cli_vehicle.rs +++ b/src/cli/vehicle.rs @@ -1,10 +1,6 @@ +use crate::vehicles::{SetChargeLimit, SetChargingAmps}; +use crate::{Api, VehicleId}; use clap::{Args, Subcommand}; -use teslatte::vehicles::{SetChargeLimit, SetChargingAmps}; -use teslatte::{Api, VehicleId}; - -pub fn main() { - todo!() -} #[derive(Debug, Args)] pub struct VehicleArgs { diff --git a/src/lib.rs b/src/lib.rs index 96e705b..0dcd3e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,9 @@ pub mod error; pub mod powerwall; pub mod vehicles; +#[cfg(feature = "cli")] +pub mod cli; + const API_URL: &str = "https://owner-api.teslamotors.com/api/1"; trait Values { diff --git a/examples/cli.rs b/src/main.rs similarity index 99% rename from examples/cli.rs rename to src/main.rs index d5a888c..e121613 100644 --- a/examples/cli.rs +++ b/src/main.rs @@ -1,12 +1,10 @@ -mod cli_vehicle; - use chrono::DateTime; use clap::{Args, Parser, Subcommand}; -use cli_vehicle::VehicleArgs; use miette::{IntoDiagnostic, WrapErr}; use serde::{Deserialize, Serialize}; use teslatte::auth::{AccessToken, RefreshToken}; use teslatte::calendar_history::{CalendarHistoryValues, HistoryKind, HistoryPeriod}; +use teslatte::cli::vehicle::VehicleArgs; use teslatte::energy::EnergySiteId; use teslatte::powerwall::{PowerwallEnergyHistoryValues, PowerwallId}; use teslatte::Api;