Skip to content

Commit

Permalink
feat: adding initial CLI interfacing
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed May 23, 2024
1 parent ba32aeb commit 503142d
Show file tree
Hide file tree
Showing 31 changed files with 541 additions and 250 deletions.
100 changes: 98 additions & 2 deletions 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,12 +1,13 @@
[workspace]
members = ["config", "reqtui", "tui", "colors"]
members = ["config", "reqtui", "tui", "colors", "cli"]
default-members = ["tui"]
resolver = "2"

[workspace.dependencies]
config = { path = "config" }
reqtui = { path = "reqtui" }
colors = { path = "colors" }
cli = { path = "cli" }

anyhow = "1.0.81"
crossterm = { version = "0.27.0", features = ["event-stream"] }
Expand Down
7 changes: 7 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "cli"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.5.4", features = ["derive"] }
75 changes: 75 additions & 0 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::path::Path;

use clap::Parser;

pub enum RuntimeBehavior {
PrintConfigPath,
PrintDataPath,
DumpDefaultConfig,
Run,
}

#[derive(Parser)]
pub struct Cli {
/// prints the directory in which the config file is being loaded from
#[arg(long)]
config_dir: bool,
/// dumps the default configuration to stdout.
#[arg(long)]
config_dump: bool,
/// prints the directory in which the collections are being stored
#[arg(long)]
data_dir: bool,
}

impl Cli {
pub fn parse_args() -> RuntimeBehavior {
let args = Cli::parse();

if args.config_dir {
return RuntimeBehavior::PrintConfigPath;
}
if args.data_dir {
return RuntimeBehavior::PrintDataPath;
}
if args.config_dump {
return RuntimeBehavior::DumpDefaultConfig;
}

RuntimeBehavior::Run
}

pub fn print_data_path<P>(data_path: P)
where
P: AsRef<Path>,
{
println!(
"collections are being stored at: {}",
data_path.as_ref().to_string_lossy()
);
println!("you can change this on the configuration file by specifying `collections_dir`");
}

pub fn print_config_path<P>(maybe_path: Option<P>, usual_path: P)
where
P: AsRef<Path>,
{
match maybe_path {
Some(config_dir) => {
println!(
"config is being loaded from: {}",
config_dir.as_ref().to_string_lossy()
);
}
None => {
println!("no config file was found, the default one is being used");
println!("the usual path for the configuration file is at:\n");
println!("{}", usual_path.as_ref().to_string_lossy());
}
}
}

pub fn print_default_config(config_as_str: &str) {
println!("{}", config_as_str)
}
}
Loading

0 comments on commit 503142d

Please sign in to comment.