mirror of
https://github.com/adriankumpf/tesla_auth.git
synced 2026-02-27 09:54:03 +08:00
Parse command line arguments
This commit is contained in:
Generated
+30
-12
@@ -8,6 +8,35 @@ version = "1.0.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1"
|
||||
|
||||
[[package]]
|
||||
name = "argh"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f023c76cd7975f9969f8e29f0e461decbdc7f51048ce43427107a3d192f1c9bf"
|
||||
dependencies = [
|
||||
"argh_derive",
|
||||
"argh_shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "argh_derive"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48ad219abc0c06ca788aface2e3a1970587e3413ab70acd20e54b6ec524c1f8f"
|
||||
dependencies = [
|
||||
"argh_shared",
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "argh_shared"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38de00daab4eac7d753e97697066238d67ce9d7e2d823ab4f72fe14af29f3f33"
|
||||
|
||||
[[package]]
|
||||
name = "atk"
|
||||
version = "0.14.0"
|
||||
@@ -183,17 +212,6 @@ dependencies = [
|
||||
"objc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "colored"
|
||||
version = "1.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"lazy_static",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "com"
|
||||
version = "0.2.0"
|
||||
@@ -1647,7 +1665,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7de33c687404ec3045d4a0d437580455257c0436f858d702f244e7d652f9f07"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"colored",
|
||||
"log",
|
||||
"winapi",
|
||||
]
|
||||
@@ -1831,6 +1848,7 @@ name = "tesla_auth"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"argh",
|
||||
"log",
|
||||
"oauth2",
|
||||
"reqwest",
|
||||
|
||||
+3
-19
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "tesla_auth"
|
||||
version = "0.1.0"
|
||||
description = "TBA"
|
||||
description = "Tesla token generator"
|
||||
homepage = "https://github.com/adriankumpf/tesla_auth"
|
||||
repository = "https://github.com/adriankumpf/tesla_auth"
|
||||
keywords = ["tesla", "oauth", "cli", "terminal"]
|
||||
@@ -10,33 +10,17 @@ authors = ["Adrian Kumpf"]
|
||||
edition = "2018"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[package.metadata.bundle]
|
||||
name = "TeslaAuth"
|
||||
identifier = "io.github.adriankumpf.tesla_auth"
|
||||
# icon = ["32x32.png", "128x128.png", "128x128@2x.png"]
|
||||
# icon = ["examples/hello/icon*.png"]
|
||||
resources = []
|
||||
copyright = "Copyright (c) Adrian Kumpf 2021. All rights reserved."
|
||||
category = "Utility"
|
||||
long_description = """
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
||||
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
|
||||
enim ad minim veniam, quis nostrud exercitation ullamco laboris
|
||||
nisi ut aliquip ex ea commodo consequat.
|
||||
"""
|
||||
deb_depends = []
|
||||
osx_frameworks = []
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.44"
|
||||
argh = "0.1.6"
|
||||
log = "0.4.14"
|
||||
oauth2 = "4.1.0"
|
||||
reqwest = { version = "0.11.4" , default-features = false, features = ["json", "rustls-tls"]}
|
||||
serde = "1.0.130"
|
||||
serde_json = "1.0.67"
|
||||
simple_logger = { version = "1.13.0", default-features = false, features = ["colors", "stderr"] }
|
||||
simple_logger = { version = "1.13.0", default-features = false, features = ["stderr"] }
|
||||
static_vcruntime = "1.5.1"
|
||||
wry = { version = "0.12", default-features = false, features = [] }
|
||||
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
# tesla_auth
|
||||
|
||||
## Overview
|
||||
|
||||
## TODO
|
||||
|
||||
- [x] Error handling
|
||||
- [x] Debug logs
|
||||
- [x] Display simple HTML page with access and refresh token
|
||||
- [x] Add GitHub Action
|
||||
- [x] Lint code
|
||||
- [x] Build binaries for different operating systems and attach them to a release
|
||||
- [ ] Create macOS app, Windows .exe etc.
|
||||
- [ ] Add icons
|
||||
- [ ] Show app in doc
|
||||
- [ ] Update CD action
|
||||
|
||||
## Platform-specific notes
|
||||
|
||||
### Linux
|
||||
|
||||
@@ -105,6 +105,7 @@ fn exchange_sso_access_token(access_token: &AccessToken) -> anyhow::Result<Strin
|
||||
.header(AUTHORIZATION, format!("Bearer {}", access_token.secret()))
|
||||
.json(&body)
|
||||
.send()?
|
||||
.error_for_status()?
|
||||
.json()?;
|
||||
|
||||
Ok(tokens.access_token)
|
||||
|
||||
+21
-8
@@ -5,6 +5,7 @@ use std::sync::mpsc::channel;
|
||||
use std::thread;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use argh::FromArgs;
|
||||
use log::{debug, error, LevelFilter};
|
||||
use oauth2::url::Url;
|
||||
use simple_logger::SimpleLogger;
|
||||
@@ -22,9 +23,9 @@ use wry::Value;
|
||||
mod auth;
|
||||
|
||||
const INITIALIZATION_SCRIPT: &str = r#"
|
||||
window.addEventListener('DOMContentLoaded', function(event) {
|
||||
rpc.call('url', window.location.toString());
|
||||
});
|
||||
window.addEventListener('DOMContentLoaded', function() {
|
||||
rpc.call('url', window.location.toString());
|
||||
});
|
||||
"#;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -32,12 +33,24 @@ enum CustomEvent {
|
||||
Tokens(auth::Tokens),
|
||||
}
|
||||
|
||||
#[derive(FromArgs, Debug)]
|
||||
/// Tesla tokens generator
|
||||
struct Args {
|
||||
/// print debug output
|
||||
#[argh(switch, short = 'd')]
|
||||
debug: bool,
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
SimpleLogger::new()
|
||||
.with_level(LevelFilter::Off)
|
||||
.with_module_level("reqwest", LevelFilter::Debug)
|
||||
.with_module_level("tesla_auth", LevelFilter::Debug)
|
||||
.init()?;
|
||||
let args: Args = argh::from_env();
|
||||
|
||||
if args.debug {
|
||||
SimpleLogger::new()
|
||||
.with_level(LevelFilter::Off)
|
||||
.with_module_level("reqwest", LevelFilter::Debug)
|
||||
.with_module_level("tesla_auth", LevelFilter::Debug)
|
||||
.init()?;
|
||||
}
|
||||
|
||||
let event_loop = EventLoop::<CustomEvent>::with_user_event();
|
||||
let event_proxy = event_loop.create_proxy();
|
||||
|
||||
Reference in New Issue
Block a user