Add an example usage in the check command
Feel free to do this differently, I just implemented it because i'm actually using it heh
This commit is contained in:
parent
4bb424ba78
commit
d04094560b
|
@ -1,5 +1,10 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use aiken_project::watch;
|
||||||
|
use owo_colors::{OwoColorize, Stream::Stderr};
|
||||||
|
|
||||||
|
use crate::Terminal;
|
||||||
|
|
||||||
#[derive(clap::Args)]
|
#[derive(clap::Args)]
|
||||||
/// Type-check an Aiken project
|
/// Type-check an Aiken project
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
|
@ -18,10 +23,14 @@ pub struct Args {
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
debug: bool,
|
debug: bool,
|
||||||
|
|
||||||
// When enabled, re-run the command on file changes instead of exiting
|
/// When enabled, re-run the command on file changes instead of exiting
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
watch: bool,
|
watch: bool,
|
||||||
|
|
||||||
|
/// When enabled, clear the screen before running
|
||||||
|
#[clap(long)]
|
||||||
|
clear: bool,
|
||||||
|
|
||||||
/// Only run tests if they match any of these strings.
|
/// Only run tests if they match any of these strings.
|
||||||
/// You can match a module with `-m aiken/list` or `-m list`.
|
/// You can match a module with `-m aiken/list` or `-m list`.
|
||||||
/// You can match a test with `-m "aiken/list.{map}"` or `-m "aiken/option.{flatten_1}"`
|
/// You can match a test with `-m "aiken/list.{map}"` or `-m "aiken/option.{flatten_1}"`
|
||||||
|
@ -47,9 +56,77 @@ pub fn exec(
|
||||||
match_tests,
|
match_tests,
|
||||||
exact_match,
|
exact_match,
|
||||||
no_traces,
|
no_traces,
|
||||||
|
watch,
|
||||||
|
clear,
|
||||||
..
|
..
|
||||||
}: Args,
|
}: Args,
|
||||||
) -> miette::Result<()> {
|
) -> miette::Result<()> {
|
||||||
|
if watch {
|
||||||
|
watch::watch_project(directory, Terminal, watch::default_filter, 500, |p| {
|
||||||
|
if clear {
|
||||||
|
println!("{esc}c", esc = 27 as char);
|
||||||
|
}
|
||||||
|
let build_result = p.check(
|
||||||
|
skip_tests,
|
||||||
|
match_tests.clone(),
|
||||||
|
debug,
|
||||||
|
exact_match,
|
||||||
|
(!no_traces).into(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let warnings = p.warnings();
|
||||||
|
|
||||||
|
let warning_count = warnings.len();
|
||||||
|
|
||||||
|
for warning in &warnings {
|
||||||
|
warning.report()
|
||||||
|
}
|
||||||
|
|
||||||
|
let plural = if warning_count == 1 { "" } else { "s" };
|
||||||
|
|
||||||
|
if let Err(errs) = build_result {
|
||||||
|
for err in &errs {
|
||||||
|
err.report()
|
||||||
|
}
|
||||||
|
|
||||||
|
eprintln!(
|
||||||
|
"\n{}",
|
||||||
|
"Summary"
|
||||||
|
.if_supports_color(Stderr, |s| s.purple())
|
||||||
|
.if_supports_color(Stderr, |s| s.bold())
|
||||||
|
);
|
||||||
|
|
||||||
|
let warning_text = format!("{warning_count} warning{plural}");
|
||||||
|
|
||||||
|
let plural = if errs.len() == 1 { "" } else { "s" };
|
||||||
|
|
||||||
|
let error_text = format!("{} error{}", errs.len(), plural);
|
||||||
|
|
||||||
|
let full_summary = format!(
|
||||||
|
" {}, {}",
|
||||||
|
error_text.if_supports_color(Stderr, |s| s.red()),
|
||||||
|
warning_text.if_supports_color(Stderr, |s| s.yellow())
|
||||||
|
);
|
||||||
|
|
||||||
|
eprintln!("{full_summary}");
|
||||||
|
} else {
|
||||||
|
eprintln!(
|
||||||
|
"\n{}",
|
||||||
|
"Summary"
|
||||||
|
.if_supports_color(Stderr, |s| s.purple())
|
||||||
|
.if_supports_color(Stderr, |s| s.bold())
|
||||||
|
);
|
||||||
|
|
||||||
|
let warning_text = format!("{warning_count} warning{plural}");
|
||||||
|
|
||||||
|
eprintln!(
|
||||||
|
" 0 errors, {}",
|
||||||
|
warning_text.if_supports_color(Stderr, |s| s.yellow()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
} else {
|
||||||
crate::with_project(directory, deny, |p| {
|
crate::with_project(directory, deny, |p| {
|
||||||
p.check(
|
p.check(
|
||||||
skip_tests,
|
skip_tests,
|
||||||
|
@ -59,4 +136,5 @@ pub fn exec(
|
||||||
(!no_traces).into(),
|
(!no_traces).into(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue