Skip to content

Commit a346ea4

Browse files
authored
Merge pull request #589 from mrcjkb/mj/push-xssluzkussnn
feat(emmylua_check): library
2 parents f107dea + 5e41e4b commit a346ea4

File tree

5 files changed

+37
-109
lines changed

5 files changed

+37
-109
lines changed

crates/emmylua_check/Cargo.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ fern.workspace = true
2424
rowan.workspace = true
2525
walkdir.workspace = true
2626
tokio-util.workspace = true
27-
clap.workspace = true
2827
ansi_term.workspace = true
2928
tokio.workspace = true
29+
30+
[dependencies.clap]
31+
workspace = true
32+
optional = true
33+
34+
[[bin]]
35+
name = "emmylua_check"
36+
required-features = ["cli"]
37+
38+
[features]
39+
default = ["cli"]
40+
cli = ["dep:clap"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use clap::Parser;
2+
use emmylua_check::{cmd_args::CmdArgs, run_check};
3+
use std::error::Error;
4+
5+
#[tokio::main]
6+
async fn main() -> Result<(), Box<dyn Error + Sync + Send>> {
7+
let cmd_args = CmdArgs::parse();
8+
run_check(cmd_args).await
9+
}

crates/emmylua_check/src/cmd_args.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
1+
#[cfg(feature = "cli")]
12
use clap::{Parser, ValueEnum};
3+
24
use std::path::PathBuf;
35

46
#[allow(unused)]
5-
#[derive(Debug, Parser, Clone)]
7+
#[derive(Debug, Clone)]
8+
#[cfg_attr(feature = "cli", derive(Parser))]
69
pub struct CmdArgs {
710
/// Configuration file paths.
811
/// If not provided, both ".emmyrc.json" and ".luarc.json" will be searched in the workspace
912
/// directory
10-
#[arg(short, long, value_delimiter = ',')]
13+
#[cfg_attr(feature = "cli", arg(short, long, value_delimiter = ','))]
1114
pub config: Option<Vec<PathBuf>>,
1215

1316
/// Path to the workspace directory
1417
pub workspace: PathBuf,
1518

1619
/// Comma separated list of ignore patterns.
1720
/// Patterns must follow glob syntax
18-
#[arg(short, long, value_delimiter = ',')]
21+
#[cfg_attr(feature = "cli", arg(short, long, value_delimiter = ','))]
1922
pub ignore: Option<Vec<String>>,
2023

2124
/// Specify output format
22-
#[arg(long, default_value = "text", value_enum, ignore_case = true)]
25+
#[cfg_attr(
26+
feature = "cli",
27+
arg(long, default_value = "text", value_enum, ignore_case = true)
28+
)]
2329
pub output_format: OutputFormat,
2430

2531
/// Specify output destination (stdout or a file path, only used when output_format is json).
26-
#[arg(long, default_value = "stdout")]
32+
#[cfg_attr(feature = "cli", arg(long, default_value = "stdout"))]
2733
pub output: OutputDestination,
2834

2935
/// Treat warnings as errors
30-
#[arg(long)]
36+
#[cfg_attr(feature = "cli", arg(long))]
3137
pub warnings_as_errors: bool,
3238

3339
/// Verbose output
34-
#[arg(long)]
40+
#[cfg_attr(feature = "cli", arg(long))]
3541
pub verbose: bool,
3642
}
3743

38-
#[derive(Debug, Clone, PartialEq, ValueEnum)]
44+
#[derive(Debug, Clone, PartialEq)]
45+
#[cfg_attr(feature = "cli", derive(ValueEnum))]
3946
pub enum OutputFormat {
4047
Json,
4148
Text,

crates/emmylua_check/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
mod cmd_args;
1+
pub mod cmd_args;
22
mod init;
33
mod output;
44
mod terminal_display;
55

6-
pub use clap::Parser;
76
pub use cmd_args::*;
87
use fern::Dispatch;
98
use log::LevelFilter;
@@ -13,7 +12,6 @@ use tokio_util::sync::CancellationToken;
1312

1413
use crate::init::get_need_check_ids;
1514

16-
#[allow(unused)]
1715
pub async fn run_check(cmd_args: CmdArgs) -> Result<(), Box<dyn Error + Sync + Send>> {
1816
let mut workspace = cmd_args.workspace;
1917
if !workspace.is_absolute() {

crates/emmylua_check/src/main.rs

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)