Skip to content

Commit

Permalink
Merge pull request #1 from abbudao/config
Browse files Browse the repository at this point in the history
Adding config token to user home
  • Loading branch information
abbudao authored Oct 26, 2019
2 parents 1ff6da6 + 9f2ca3f commit 020a0db
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::env;
use flate2::read::GzDecoder;
use serde::Deserialize;
use structopt::StructOpt;
use tar;
use std::fs::File;
use std::io::prelude::*;
use std::path::PathBuf;

static API_URI: &str = "http://sharpener-cloud.appspot.com/api";
static BUCKET_URI: &str = "https://storage.googleapis.com/";
Expand Down Expand Up @@ -31,7 +35,9 @@ fn main() {
language: l,
name: n,
} => download_exercise(l, n).unwrap(),
_ => println!("Oh noes"),
Cli::Config {
token: t,
} => store_token_in_home(t).unwrap(),
}
}

Expand Down Expand Up @@ -75,3 +81,11 @@ fn download_tar(target: &str) -> Result<TarArchive, CliError> {
Ok(tar::Archive::new(decoded_response))
}


fn store_token_in_home(token: String) -> std::io::Result<()>{
let home = env::var("HOME").map(PathBuf::from).unwrap();
let config_path = home.join(".sharpener-config");
let mut file = File::create(config_path)?;
file.write_all(token.as_bytes())?;
Ok(())
}

0 comments on commit 020a0db

Please sign in to comment.