switched from dotenv to confy
This commit is contained in:
parent
0ed9d66b6a
commit
afa0cd2218
4 changed files with 243 additions and 21 deletions
|
@ -6,7 +6,8 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dotenv = "0.15.0"
|
||||
clap = { version = "4.4.0", features = ["derive"] }
|
||||
confy = "0.5.1"
|
||||
reqwest = { version = "0.11.18", features = ["blocking", "json"] }
|
||||
serde = { version = "1.0.184", features = ["serde_derive"] }
|
||||
serde_json = "1.0.105"
|
||||
|
|
|
@ -1,25 +1,44 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use reqwest::blocking::Client;
|
||||
|
||||
use dotenv::dotenv;
|
||||
use clap::Parser;
|
||||
use confy;
|
||||
|
||||
use std::env;
|
||||
use std::process::Command;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Config {
|
||||
user: String,
|
||||
pswd: String,
|
||||
note_id: String,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
user: "".to_string(),
|
||||
pswd: "".to_string(),
|
||||
note_id: "".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about=None)]
|
||||
struct CliArgs {
|
||||
/// Path to config .toml file
|
||||
#[arg(short, long)]
|
||||
config_file: String,
|
||||
}
|
||||
|
||||
// TODO: logging
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
dotenv().ok();
|
||||
|
||||
let user = env::var("NEXTCLOUD_USER").unwrap();
|
||||
let pswd = env::var("NEXTCLOUD_PWD").unwrap();
|
||||
let note_id = env::var("NOTE_ID").unwrap();
|
||||
let args = CliArgs::parse();
|
||||
|
||||
// let client = Client::new();
|
||||
// let res = client
|
||||
// .get(format!("https://files.nickiel.net/index.php/apps/notes/api/v1/notes/{}", note_id))
|
||||
// .header("Accept", "application/json")
|
||||
// .basic_auth(user.clone(), Some(pswd.clone()))
|
||||
// .send()?
|
||||
// .json::<Note>()?;
|
||||
// println!("{:#?}", res);
|
||||
let cfg: Config = confy::load_path(args.config_file)?;
|
||||
|
||||
let mut drives: Vec<String> = vec![];
|
||||
|
||||
|
@ -64,10 +83,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
|
||||
|
||||
let update = Client::new()
|
||||
.put(format!("https://files.nickiel.net/index.php/apps/notes/api/v1/notes/{}", note_id))
|
||||
.put(format!("https://files.nickiel.net/index.php/apps/notes/api/v1/notes/{}", cfg.note_id.clone()))
|
||||
.header("Accept", "application/json")
|
||||
.header("Content-Type", "application/json")
|
||||
.basic_auth(user, Some(pswd))
|
||||
.basic_auth(cfg.user.clone(), Some(cfg.pswd.clone()))
|
||||
.body(serde_json::to_string(&NoteUpdate {content: body_content}).unwrap());
|
||||
|
||||
println!("{:#?}", update.send()?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue