cdp_cli/
lib.rs

1mod handlers;
2mod types;
3mod utils;
4
5use clap::CommandFactory;
6use crossterm::style::Stylize;
7use types::*;
8use handlers::{
9    general::*, aliases::*, create_project::*,
10};
11
12use crate::{handlers::errors::CliErr, utils::parse_path};
13
14pub fn cli_run() -> Result<(), CliErr> {
15    let args = Cli::parse();
16
17    match args.command {
18        Some(Commands::General(cmd)) => {
19            let path = match parse_path::parse_path(cmd.path.clone()) {
20                Ok(s) => s,
21                Err(e) => {
22                    eprintln!("{e}");
23                    cmd.path
24                }
25            };
26
27            if cmd.current_user {
28                let home_path = if cfg!(windows) {
29                    "%USER/"
30                } else {
31                    "~/"
32                };
33                println!(
34                    "{}: the {} (or {}) flag is no longer necessary.\nYou can specify whether the directory is in user/home using: {}your_dir", 
35                    "Deprecated".yellow(), 
36                    "--current-user".red(), 
37                    "-C".red(), 
38                    home_path.green()
39                );
40            }
41            if cmd.alias {
42                println!(
43                    "{}: the {} (or {}) flag is no longer necessary.\nYou can specify whether is an alias using {}. (e.g. {})", 
44                    "Deprecated".yellow(), 
45                    "--alias".red(), 
46                    "--al".red(),
47                    ":".green(),
48                    ":cdpproject/src/parse_path.rs".green()
49                );
50            }
51            if cmd.ls {
52                if let Err(e) = ls::ls(path.clone()) {
53                    eprintln!("{e}");
54                }
55            }
56            if cmd.vsc {
57                println!(
58                    "{}: the {} flag is no longer necessary. Use {} (or {}) instead. (e.g. {})", 
59                    "Deprecated".yellow(), 
60                    "--vsc".red(),
61                    "--editor".green(),
62                    "-E".green(),
63                    r#"cdp general ":cdptests/assets" -E vsc"#.green()
64                );
65            }
66            if cmd.editor.is_some() {
67                if let Err(e) = editors::open_editor(Editors::Vsc, path.clone()) {
68                    eprintln!("{e}");
69                }
70            }
71        },
72        Some(Commands::Aliases(cmd)) => {
73            if let Err(e) = aliases::aliases(cmd.path, cmd.alias) {
74                eprintln!("{e}");
75            }
76        },
77        Some(Commands::CreateProject(cmd)) => {
78            if let Err(e) = create_project::create_project(
79                cmd.lang,
80                cmd.name,
81                cmd.alias,
82            ) {
83                eprintln!("{e}");
84            }
85        },
86        None => { Cli::command().print_help().unwrap(); std::process::exit(1); }
87    }
88
89    Ok(())
90}