1use std::error::Error;
2pub mod config;
3pub mod create_app;
4
5#[derive(Debug)]
6pub enum Command {
8 Create,
10 Start,
12 Build,
14 Test,
16 Help,
18}
19pub enum AppType {
21 Mobile,
23 Site,
25 BackStage,
27 SingleSpa,
29 Library,
31}
32pub use config::Config;
33
34pub use self::create_app::CreateApp;
35
36pub fn run(app: Config) -> Result<(), Box<dyn Error>> {
37 println!("{:?}", app);
38 match app.command {
39 Command::Create => {
40 CreateApp::new(app)?;
41 }
42 Command::Start => todo!(),
43 Command::Build => todo!(),
44 Command::Test => todo!(),
45 Command::Help => todo!(),
46 };
47 Ok(())
48}
49
50pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
52 contents
53 .lines()
54 .filter(|line| line.contains(query))
55 .collect()
56}
57pub fn search_case_insensitive<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
59 let query = query.to_lowercase();
60
61 contents
62 .lines()
63 .filter(|line| line.to_lowercase().contains(&query))
64 .collect()
65}
66#[cfg(test)]
67mod tests {
68 use super::*;
69 #[test]
70 fn case_sensitive() {
71 let query = "duct";
72 let contents = "\
73Rust:
74safe, fast, productive.
75Pick three.
76Duct tape.";
77 assert_eq!(vec!["safe, fast, productive."], search(query, contents))
78 }
79 #[test]
80 fn case_insensitive() {
81 let query = "rUsT";
82 let contents = "\
83Rust:
84safe, fast, productive.
85Pick three.
86Trust me.";
87 assert_eq!(
88 vec!["Rust:", "Trust me."],
89 search_case_insensitive(query, contents)
90 )
91 }
92}