Skip to content

Commit

Permalink
Added first time run prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
obvMellow committed Sep 6, 2024
1 parent eee5e0f commit 251c5d7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "distore"
version = "0.1.1"
version = "0.1.2"
description = "Utility to use Discord as cloud storage"
authors = ["Deniz Demir <[email protected]>"]
license = "GPL-3.0-or-later"
Expand All @@ -16,3 +16,4 @@ libdistore = { path = "./libdistore", version = "0.1.0" }
clap = { version = "4.5.16", features = ["derive"] }
tokio = { version = "1.39.3", features = ["rt-multi-thread"] }
anyhow = "1.0.86"
dirs = "5.0.1"
39 changes: 38 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{io::Write, path::PathBuf};

use clap::{Parser, Subcommand};

Expand Down Expand Up @@ -94,10 +94,47 @@ enum Commands {
},
}

// Convenience macro to read user input
macro_rules! inputln {
($message:expr) => {{
print!("{}: ", $message);
std::io::stdout().flush().unwrap();
inputln!()
}};
() => {{
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
input.trim().to_string()
}};
}

fn first_time_run(args: Args) {
println!("Looks like it's your first time running.");
println!(
"Follow the instructions at https://github.com/obvMellow/distore?tab=readme-ov-file#usage"
);
println!("Then Input your token and channel ID. They will be set automatically for you.");

let token = inputln!("Token");
let channel = inputln!("Channel");

commands::config(true, "token".into(), token, args.config_directory.clone()).unwrap();
commands::config(true, "channel".into(), channel, args.config_directory).unwrap();
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args = Args::parse();

let config_path = dirs::config_dir()
.expect("No config directory found.")
.join("distore/distore.ini");

if !config_path.exists() {
first_time_run(args);
return Ok(());
}

match args.command {
Commands::Config { global, key, value } => match key {
Some(key) => commands::config(global, key, value.unwrap(), args.config_directory)?,
Expand Down

0 comments on commit 251c5d7

Please sign in to comment.