~jheckt/Basket

b8b9c8977d4b34f8ef3928dddc0b960b16ed5883 — turnipsoup 1 year, 3 months ago 28ef007 main
rust re-write of client complete
M rust-version/client/Cargo.lock => rust-version/client/Cargo.lock +10 -0
@@ 18,6 18,7 @@ checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
name = "basket-rewrite"
version = "0.1.0"
dependencies = [
 "home",
 "reqwest",
 "serde",
 "serde_json",


@@ 192,6 193,15 @@ dependencies = [
]

[[package]]
name = "home"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408"
dependencies = [
 "winapi",
]

[[package]]
name = "http"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"

M rust-version/client/Cargo.toml => rust-version/client/Cargo.toml +2 -1
@@ 9,4 9,5 @@ edition = "2021"
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }
serde = "1.0.104"
serde_json = "1.0.44"
\ No newline at end of file
serde_json = "1.0.44"
home = "0.5.4"

M rust-version/client/src/main.rs => rust-version/client/src/main.rs +33 -1
@@ 1,4 1,6 @@
use std::env;
use std::process::exit;
use std::fs;

/*#[derive(Debug, Deserialize)]
struct RequestData {


@@ 16,6 18,24 @@ struct RequestObject {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {


    // Help string
    let helpstr = "
    Usage: basket set <key> <value> -- Set value in store
           basket get <key> -- Get value in store
    ";

    // Config location
    let homepath = str::replace(&home::home_dir().as_ref().unwrap().to_str().unwrap(), '"', "");
    let configloc = format!("{}/.local/basket/basket-conf.json", homepath);

    // Load config into JSON
    let jdata = fs::read_to_string(configloc).expect("Unable to read file");
    

    let jsonconfig: serde_json::Value = serde_json::from_str(&jdata).expect("JSON was not well-formatted");


    // Get arguments and assign them to mode, key, value
    let args: Vec<String> = env::args().collect(); // Get args
    let argslen = args.len();


@@ 28,6 48,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
        mode = &args[1];
    }

    // If this is not an accepted mode then print the help str
    if mode != "set" && mode != "get" {
        println!("    Unknown mode: {}", mode);
        println!("{}", helpstr);
        exit(0);
    }

    if argslen > 2 {
        key = &args[2];
    }


@@ 41,7 68,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

    // Make POST request with data
    let client = reqwest::Client::new();
    let target_uri = "http://192.168.0.202:5000";

    let protocol = str::replace(&jsonconfig["protocol"].to_string(), '"', "");
    let host = str::replace(&jsonconfig["host"].to_string(), '"', "");
    let port = str::replace(&jsonconfig["port"].to_string(), '"', "");

    let target_uri = format!("{}://{}:{}", protocol, host, port);

    // Make the actual request object itself, awaiting async
    let res = client