refactor: cli to be a binary with cli feature

This commit is contained in:
gak 2023-08-29 10:49:04 +10:00
parent 009ae67734
commit 635bd84384
No known key found for this signature in database
5 changed files with 16 additions and 15 deletions

View file

@ -5,9 +5,11 @@ description = "A Rust crate for querying the Tesla API."
edition = "2021" edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
[lib] [features]
name = "teslatte" default = ["cli", "fancy"]
path = "src/lib.rs"
fancy = ["miette/fancy"]
cli = ["dep:clap", "dep:tracing-subscriber"]
[dependencies] [dependencies]
miette = { version = "5.1", features = ["fancy"] } miette = { version = "5.1", features = ["fancy"] }
@ -26,7 +28,8 @@ urlencoding = "2.1.0"
derive_more = "0.99" derive_more = "0.99"
pkce = "0.2.0" pkce = "0.2.0"
clap = { version = "3.2", features = ["derive", "env"], optional = true }
tracing-subscriber = { version = "0.3.17", optional = true }
[dev-dependencies] [dev-dependencies]
test-log = { version = "0.2", default-features = false, features = ["trace"] } test-log = { version = "0.2.12", default-features = false, features = ["trace"] }
tracing-subscriber = "0.3"
clap = { version = "3.2", features = ["derive", "env"]}

1
src/cli.rs Normal file
View file

@ -0,0 +1 @@
pub mod vehicle;

View file

@ -1,10 +1,6 @@
use crate::vehicles::{SetChargeLimit, SetChargingAmps};
use crate::{Api, VehicleId};
use clap::{Args, Subcommand}; use clap::{Args, Subcommand};
use teslatte::vehicles::{SetChargeLimit, SetChargingAmps};
use teslatte::{Api, VehicleId};
pub fn main() {
todo!()
}
#[derive(Debug, Args)] #[derive(Debug, Args)]
pub struct VehicleArgs { pub struct VehicleArgs {

View file

@ -14,6 +14,9 @@ pub mod error;
pub mod powerwall; pub mod powerwall;
pub mod vehicles; pub mod vehicles;
#[cfg(feature = "cli")]
pub mod cli;
const API_URL: &str = "https://owner-api.teslamotors.com/api/1"; const API_URL: &str = "https://owner-api.teslamotors.com/api/1";
trait Values { trait Values {

View file

@ -1,12 +1,10 @@
mod cli_vehicle;
use chrono::DateTime; use chrono::DateTime;
use clap::{Args, Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
use cli_vehicle::VehicleArgs;
use miette::{IntoDiagnostic, WrapErr}; use miette::{IntoDiagnostic, WrapErr};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use teslatte::auth::{AccessToken, RefreshToken}; use teslatte::auth::{AccessToken, RefreshToken};
use teslatte::calendar_history::{CalendarHistoryValues, HistoryKind, HistoryPeriod}; use teslatte::calendar_history::{CalendarHistoryValues, HistoryKind, HistoryPeriod};
use teslatte::cli::vehicle::VehicleArgs;
use teslatte::energy::EnergySiteId; use teslatte::energy::EnergySiteId;
use teslatte::powerwall::{PowerwallEnergyHistoryValues, PowerwallId}; use teslatte::powerwall::{PowerwallEnergyHistoryValues, PowerwallId};
use teslatte::Api; use teslatte::Api;