-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding initial CLI interfacing
- Loading branch information
Showing
31 changed files
with
541 additions
and
250 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.