aboutsummaryrefslogtreecommitdiff
path: root/crates/cli/src/main.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/main.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/main.rs')
-rw-r--r--crates/cli/src/main.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs
new file mode 100644
index 0000000..78d094d
--- /dev/null
+++ b/crates/cli/src/main.rs
@@ -0,0 +1,81 @@
+mod init;
+mod nuke;
+mod run;
+mod words;
+
+/// Version for this program.
+const VERSION: &str = "0.1.0";
+
+fn help() {
+ println!("Self-assessment tool for language learning.\n");
+ println!("usage: mihi [OPTIONS] [COMMAND] [COMMAND OPTIONS]\n");
+
+ println!("Options:");
+ println!(" -h, --help\t\tPrint this message.");
+ println!(" -v, --version\tPrint the version of this program.\n");
+
+ println!("Commands:");
+ println!(" init\t\t\tInitialize the configuration for this application.");
+ println!(" nuke\t\t\tRemove all files from this application and its database.");
+ println!(" run\t\t\tRun exercises. Default command if none was given.");
+ println!(" words\t\tManage the words for this application.");
+}
+
+fn main() {
+ let mut args = std::env::args();
+ let nargs = std::env::args().count();
+ let mut count = 1;
+
+ // Skip command name.
+ args.next();
+
+ // And iterate over the arguments.
+ while let Some(arg) = args.next() {
+ count += 1;
+
+ match arg.as_str() {
+ "-h" | "--help" => {
+ if nargs > count {
+ println!(
+ "warning: arguments passed the '{}' flag will be ignored.",
+ arg.as_str()
+ );
+ }
+ help();
+ std::process::exit(0);
+ }
+ "-v" | "--version" => {
+ if nargs > count {
+ println!(
+ "warning: arguments passed the '{}' flag will be ignored.",
+ arg.as_str()
+ );
+ }
+ println!("mihi {}", VERSION);
+ std::process::exit(0);
+ }
+ "init" => {
+ let rest: Vec<String> = args.collect();
+ return init::run(rest);
+ }
+ "nuke" => {
+ let rest: Vec<String> = args.collect();
+ return nuke::run(rest);
+ }
+ "words" => {
+ let rest: Vec<String> = args.collect();
+ return words::run(rest);
+ }
+ "run" => {
+ let rest: Vec<String> = args.collect();
+ return run::run(rest);
+ }
+ _ => {
+ println!("error: unknown flag or command: '{}'", arg.as_str());
+ std::process::exit(1);
+ }
+ }
+ }
+
+ run::run(Vec::new());
+}