Skip to content

Commit

Permalink
Added a proper CLI handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Divy1211 committed Sep 19, 2024
1 parent 2f5ce9e commit c31d076
Show file tree
Hide file tree
Showing 13 changed files with 389 additions and 110 deletions.
160 changes: 156 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "xs-check"
version = "0.1.0"
authors = ["Alian713"]
edition = "2021"
description = "A linter for AoE2:DE's flavour of XS"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -13,6 +14,7 @@ chrono = "0.4.38"
ariadne = "0.4.1"
chumsky = "1.0.0-alpha.7"
log = "0.4.21"
structopt = "0.3.26"

[[bin]]
name = "xs-check"
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# XS Check

This tool is a linter for AoE2:DE's flavour of XS.
A linter for AoE2:DE's flavour of XS.

## Installation

You may download and use the prebuilt binaries from [here](https://github.com/Divy1211/xs-check/releases/latest)

Or instead, if you have rust installed and prefer to build it from source, you can simply run:

```sh
cargo install --git https://github.com/Divy1211/xs-check
```

This is recommended, as it will automatically add the binary to your system's path variable.

## Cool Maths

Expand Down
61 changes: 61 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use std::collections::HashSet;
use std::path::PathBuf;
use structopt::StructOpt;
use crate::r#static::xs_error::WarningKind;

fn from_str(ignores: &str) -> Result<HashSet<u32>, &str> {
ignores
.split(",")
.map(str::trim)
.map(|str| {
match WarningKind::from_str(str) {
None => { Err(str) }
Some(kind) => { Ok(kind.as_u32()) }
}
}).collect()
}

#[derive(Debug, StructOpt)]
#[structopt(name = "xs-check", about = env!("CARGO_PKG_DESCRIPTION"))]
struct Opt {
#[structopt(parse(from_os_str))]
filepath: Option<PathBuf>,

#[structopt(short, long, help = "Show binary version & info")]
version: bool,

#[structopt(short, long, help = "Comma separated list of names of warnings to ignore", parse(try_from_str = from_str))]
ignores: Option<HashSet<u32>>,
}

include!(concat!(env!("OUT_DIR"), "/build_date.rs"));

fn print_info() {
let name = env!("CARGO_PKG_NAME");
let version = env!("CARGO_PKG_VERSION");
let authors = env!("CARGO_PKG_AUTHORS");
let description = env!("CARGO_PKG_DESCRIPTION");

println!("{name} v{version}: {description}");
println!("Author: {authors}");
println!("Compiled: {BUILD_DATE}");
}

pub fn parse_args() -> Option<(PathBuf, HashSet<u32>)> {
let opt = Opt::from_args();
if opt.version {
print_info();
return None;
}

match opt.filepath {
None => {
Opt::clap().print_help().unwrap();
println!();
None
}
Some(filepath) => {
Some((filepath, opt.ignores.unwrap_or_else(HashSet::new)))
}
}
}
Loading

0 comments on commit c31d076

Please sign in to comment.