Skip to content
This repository was archived by the owner on Jul 25, 2023. It is now read-only.

Commit c0df4ba

Browse files
committed
feat: add help command #11
- add OPUS_HELP - if opus is invoked without arguments, default feedback is now the 'opus ls' command - if opus is invoked with not enough arguments for the given command, help will be displayed and opus exists
1 parent 9bebb00 commit c0df4ba

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/cli.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::db::Database;
22
use crate::types::{ArgumentType, Cli, CliInput, ExportType, Task};
33
use chrono::Utc;
4+
use crate::util::OPUS_HELP;
45

56
pub fn parse_args(args: Vec<String>) -> Cli {
67
let mut r: Cli = Cli {
@@ -11,7 +12,17 @@ pub fn parse_args(args: Vec<String>) -> Cli {
1112
},
1213
};
1314

15+
if args.len() == 1 {
16+
r.top_level_arg = ArgumentType::List;
17+
r.input.query = Some("list".to_string());
18+
return r;
19+
}
20+
1421
r.top_level_arg = match args[1].as_str() {
22+
"help" | "h" => {
23+
println!("{}", OPUS_HELP);
24+
std::process::exit(1);
25+
},
1526
"add" | "a" => ArgumentType::Add,
1627
"finish" | "f" => ArgumentType::Finish,
1728
"delete" | "d" => ArgumentType::Delete,
@@ -71,7 +82,10 @@ pub fn parse_args(args: Vec<String>) -> Cli {
7182
"Unknown Argument '{}', run 'opus help' for more info on command syntax.",
7283
args[1]
7384
),
74-
ArgumentType::Notenough => panic!("Not enough Arguments."),
85+
ArgumentType::Notenough => {
86+
println!("{}", OPUS_HELP);
87+
panic!("Not enough Arguments.");
88+
}
7589
_ => task = args[2].trim().split(' ').collect(),
7690
}
7791

src/util.rs

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ use std::fs::create_dir;
44
use std::path::Path;
55

66
const CONFIG_PATH: &str = "/opus/opus.db";
7+
pub const OPUS_HELP: &str = "Usage: opus [command] [params]
8+
Commands:
9+
list \t<query>
10+
add \t<task> <tag> <priority> <date>
11+
finish\t<id>
12+
delete\t<id>
13+
export\t<format> <filename>
14+
clear
15+
";
716

817
/// Get system dependent path to config files
918
///
@@ -56,3 +65,4 @@ pub fn create_dir_if_not_exist(path: &String) -> bool {
5665
}
5766
false
5867
}
68+

0 commit comments

Comments
 (0)