aboutsummaryrefslogtreecommitdiff
path: root/crates/cli/src/init.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-06-03 21:49:25 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-06-03 21:49:25 +0200
commit28c011c7b3ebd8f5aae111551222ed3748937b33 (patch)
treef6310107b9fbdabeda1cce46e2feb2cb85d1ce1a /crates/cli/src/init.rs
downloadmihi-28c011c7b3ebd8f5aae111551222ed3748937b33.tar.gz
mihi-28c011c7b3ebd8f5aae111551222ed3748937b33.zip
Initial commit
Basic commands have been added, but most of the features for this project are still work in progress. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'crates/cli/src/init.rs')
-rw-r--r--crates/cli/src/init.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/crates/cli/src/init.rs b/crates/cli/src/init.rs
new file mode 100644
index 0000000..7de2e8c
--- /dev/null
+++ b/crates/cli/src/init.rs
@@ -0,0 +1,55 @@
+fn help() {
+ println!("mihi init: Initialize 'mihi' for a given language.\n");
+ println!("usage: mihi init [OPTIONS]\n");
+
+ println!("Options:");
+ println!(" -h, --help\t\tPrint this message.");
+ println!(" -l, --language\tThe language to be used.");
+}
+
+pub fn run(args: Vec<String>) {
+ let mut given_language: Option<String> = None;
+ let mut it = args.into_iter();
+
+ while let Some(arg) = it.next() {
+ match arg.as_str() {
+ "-h" | "--help" => {
+ help();
+ std::process::exit(0);
+ }
+ "-l" | "--language" => match it.next() {
+ Some(lang) => given_language = Some(lang),
+ None => {
+ println!(
+ "error: init: you have to provide a value for the '-l/--language' flag"
+ );
+ std::process::exit(1);
+ }
+ },
+ _ => {
+ println!("error: init: unknown flag: '{}'", arg.as_str());
+ std::process::exit(1);
+ }
+ }
+ }
+
+ // Assume latin for now. If we support more languages in the future, there
+ // should be a prompt or something.
+ let language = match given_language {
+ Some(lang) => lang,
+ None => String::from("latin"),
+ };
+
+ match init(language) {
+ Ok(_) => {}
+ Err(e) => {
+ println!("error: init: {}", e);
+ std::process::exit(1);
+ }
+ }
+}
+
+fn init(language: String) -> Result<(), String> {
+ mihi::add_language(language)?;
+ mihi::init_database()
+}