Skip to content

Commit 6c4750f

Browse files
added help
1 parent de17c78 commit 6c4750f

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "css-linter"
3-
version = "1.9.0"
3+
version = "1.9.1"
44
edition = "2021"
55

66
[dependencies]

src/main.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::{env, process};
1+
use std::env;
22

33
use anyhow::Result;
44
use modules::{
5-
css_class::get_class_body, defined_classes::get_defined_classes, linter,
6-
styles_imports::get_styles_imports,
5+
css_class::get_class_body, defined_classes::get_defined_classes, help::print_help, linter,
6+
styles_imports::get_styles_imports, version::get_version,
77
};
88

99
mod config;
@@ -12,31 +12,19 @@ mod parsers;
1212
mod utils;
1313

1414
fn main() -> Result<()> {
15-
const COLOR_RED: &str = "\x1b[31m";
16-
const COLOR_RESET: &str = "\u{001B}[0m";
17-
18-
let args: Vec<String> = env::args().collect();
1915
if let Ok(cwd) = std::env::var("cwd") {
2016
env::set_current_dir(cwd)?;
2117
}
2218

19+
let args: Vec<String> = env::args().collect();
2320
match args.get(1) {
24-
Some(arg) if arg == "-v" => {
25-
print!("v{}", env!("CARGO_PKG_VERSION"));
26-
process::exit(0);
27-
}
21+
Some(arg) if arg == "-v" => get_version()?,
2822
Some(arg) if arg == "--lint" => linter::lint()?,
2923
Some(arg) if arg == "--imports" => get_styles_imports()?,
3024
Some(arg) if arg == "--classes" => get_defined_classes()?,
3125
Some(arg) if arg == "--class" => get_class_body()?,
32-
Some(arg) => {
33-
eprintln!(
34-
"{}Error{}: Invalid argument: {}",
35-
COLOR_RED, COLOR_RESET, arg
36-
);
37-
process::exit(1);
38-
}
39-
None => todo!(),
26+
Some(_) => print_help(),
27+
None => print_help(),
4028
};
4129

4230
Ok(())

src/modules/help.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub fn print_help() {
2+
println!(
3+
"Usage: css-linter [OPTION]\
4+
\n\nOptions:\
5+
\n -v\t\t\t\t\t Print version information\
6+
\n --lint <project path>\t\t\t Lint CSS and TSX files\
7+
\n --imports <file path>\t\t\t Get all CSS imports in file\
8+
\n --classes <file path>\t\t\t Get all defined CSS classes\
9+
\n --class <file path> <class name>\t Get CSS class body\
10+
"
11+
);
12+
}

src/modules/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ pub mod css_class;
22
pub mod defined_classes;
33
pub mod linter;
44
pub mod styles_imports;
5+
pub mod version;
6+
pub mod help;

src/modules/version.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use anyhow::Result;
2+
use std::process;
3+
4+
pub fn get_version() -> Result<()> {
5+
print!("v{}", env!("CARGO_PKG_VERSION"));
6+
process::exit(0);
7+
}

0 commit comments

Comments
 (0)