helix/xtask/src/main.rs

124 lines
3.3 KiB
Rust
Raw Normal View History

mod codegen;
feat: xtask themelint (#3234) * feat: cargo xtask themelint <theme> * fix: add docs and print json error status * fix: refactor paths -> path * fix: remove unused function * fix: only report one err per scope (ui.statusline is reported if none of ui.statusline.* is recognized) * fix: save work for later * fix: finally decided on a design * fix: ready for discussion * fix: better rules * fix: lint precision * fix: String -> &'static str * fix: allowlist not denylist for file type * fix: add missing and indication of what's needed * fix: copy pasteable errors * fix: use Loader:read_names * Update xtask/src/helpers.rs Co-authored-by: Ivan Tham <pickfire@riseup.net> * fix: remove into and clone for str * Update book/src/themes.md Co-authored-by: Ivan Tham <pickfire@riseup.net> * fix: better lint output * fix: cleaner logic for lint reporting * style: use explicit imports * Pascal support (#3542) * fix: add difference check for statusline normal,insert,select * fix: fg for whitespace and early exit if and one is ok * chore: cleaning up, no idea how these got here or how this will look * chore: revert from older commit? * refactor: use static fn to equalize api between difference and existance * refactor: querycheck and clippy * refactor: clippy fixes * fix: query-check behaves as before * fix: error with x of y message, not total count * fix: consistent reporting and less mutable state * fix: selection difference ref #3942 ref #1833 Co-authored-by: Ivan Tham <pickfire@riseup.net> Co-authored-by: ath3 <45574139+ath3@users.noreply.github.com>
2022-09-19 21:38:20 +08:00
mod docgen;
mod helpers;
mod path;
mod querycheck;
use std::{env, error::Error};
type DynError = Box<dyn Error>;
2021-11-17 21:30:11 +08:00
pub mod tasks {
use crate::codegen::code_gen;
feat: xtask themelint (#3234) * feat: cargo xtask themelint <theme> * fix: add docs and print json error status * fix: refactor paths -> path * fix: remove unused function * fix: only report one err per scope (ui.statusline is reported if none of ui.statusline.* is recognized) * fix: save work for later * fix: finally decided on a design * fix: ready for discussion * fix: better rules * fix: lint precision * fix: String -> &'static str * fix: allowlist not denylist for file type * fix: add missing and indication of what's needed * fix: copy pasteable errors * fix: use Loader:read_names * Update xtask/src/helpers.rs Co-authored-by: Ivan Tham <pickfire@riseup.net> * fix: remove into and clone for str * Update book/src/themes.md Co-authored-by: Ivan Tham <pickfire@riseup.net> * fix: better lint output * fix: cleaner logic for lint reporting * style: use explicit imports * Pascal support (#3542) * fix: add difference check for statusline normal,insert,select * fix: fg for whitespace and early exit if and one is ok * chore: cleaning up, no idea how these got here or how this will look * chore: revert from older commit? * refactor: use static fn to equalize api between difference and existance * refactor: querycheck and clippy * refactor: clippy fixes * fix: query-check behaves as before * fix: error with x of y message, not total count * fix: consistent reporting and less mutable state * fix: selection difference ref #3942 ref #1833 Co-authored-by: Ivan Tham <pickfire@riseup.net> Co-authored-by: ath3 <45574139+ath3@users.noreply.github.com>
2022-09-19 21:38:20 +08:00
use crate::docgen::{lang_features, typable_commands, write};
use crate::docgen::{LANG_SUPPORT_MD_OUTPUT, TYPABLE_COMMANDS_MD_OUTPUT};
use crate::querycheck::query_check;
use crate::DynError;
2021-11-17 21:30:11 +08:00
use std::path::{Path, PathBuf};
pub fn docgen() -> Result<(), DynError> {
write(TYPABLE_COMMANDS_MD_OUTPUT, &typable_commands()?);
write(LANG_SUPPORT_MD_OUTPUT, &lang_features()?);
Ok(())
2021-11-17 21:30:11 +08:00
}
feat: xtask themelint (#3234) * feat: cargo xtask themelint <theme> * fix: add docs and print json error status * fix: refactor paths -> path * fix: remove unused function * fix: only report one err per scope (ui.statusline is reported if none of ui.statusline.* is recognized) * fix: save work for later * fix: finally decided on a design * fix: ready for discussion * fix: better rules * fix: lint precision * fix: String -> &'static str * fix: allowlist not denylist for file type * fix: add missing and indication of what's needed * fix: copy pasteable errors * fix: use Loader:read_names * Update xtask/src/helpers.rs Co-authored-by: Ivan Tham <pickfire@riseup.net> * fix: remove into and clone for str * Update book/src/themes.md Co-authored-by: Ivan Tham <pickfire@riseup.net> * fix: better lint output * fix: cleaner logic for lint reporting * style: use explicit imports * Pascal support (#3542) * fix: add difference check for statusline normal,insert,select * fix: fg for whitespace and early exit if and one is ok * chore: cleaning up, no idea how these got here or how this will look * chore: revert from older commit? * refactor: use static fn to equalize api between difference and existance * refactor: querycheck and clippy * refactor: clippy fixes * fix: query-check behaves as before * fix: error with x of y message, not total count * fix: consistent reporting and less mutable state * fix: selection difference ref #3942 ref #1833 Co-authored-by: Ivan Tham <pickfire@riseup.net> Co-authored-by: ath3 <45574139+ath3@users.noreply.github.com>
2022-09-19 21:38:20 +08:00
pub fn querycheck() -> Result<(), DynError> {
query_check()
2022-08-26 06:24:09 +08:00
}
pub fn codegen() {
code_gen()
}
pub fn install_steel() {
fn workspace_dir() -> PathBuf {
let output = std::process::Command::new(env!("CARGO"))
.arg("locate-project")
.arg("--workspace")
.arg("--message-format=plain")
.output()
.unwrap()
.stdout;
let cargo_path = Path::new(std::str::from_utf8(&output).unwrap().trim());
cargo_path.parent().unwrap().to_path_buf()
}
// Update the steel submodule
std::process::Command::new("git")
.args(["submodule", "init"])
.spawn()
.unwrap()
.wait()
.unwrap();
std::process::Command::new("git")
.args(["submodule", "foreach", "git", "pull", "origin", "master"])
.spawn()
.unwrap()
.wait()
.unwrap();
let mut workspace_dir = workspace_dir();
workspace_dir.push("steel");
std::process::Command::new("cargo")
.args(["xtask", "install"])
.current_dir(workspace_dir)
.spawn()
.unwrap()
.wait()
.unwrap();
println!("=> Finished installing steel");
code_gen();
let helix_scm_path = helix_term::commands::helix_module_file();
let steel_init_path = helix_term::commands::steel_init_file();
if !helix_scm_path.exists() {
std::fs::File::create(helix_scm_path).expect("Unable to create new helix.scm file!");
}
if !steel_init_path.exists() {
std::fs::File::create(steel_init_path).expect("Unable to create new init.scm file!");
}
std::process::Command::new("cargo")
.args(["install", "--path", "helix-term", "--locked", "--force"])
.spawn()
.unwrap()
.wait()
.unwrap();
}
2021-11-17 21:30:11 +08:00
pub fn print_help() {
println!(
"
Usage: Run with `cargo xtask <task>`, eg. `cargo xtask docgen`.
2021-11-17 21:30:11 +08:00
Tasks:
docgen: Generate files to be included in the mdbook output.
2022-08-26 06:24:09 +08:00
query-check: Check that tree-sitter queries are valid.
2021-11-17 21:30:11 +08:00
"
);
}
}
fn main() -> Result<(), DynError> {
2021-11-17 21:30:11 +08:00
let task = env::args().nth(1);
match task {
None => tasks::print_help(),
Some(t) => match t.as_str() {
"docgen" => tasks::docgen()?,
feat: xtask themelint (#3234) * feat: cargo xtask themelint <theme> * fix: add docs and print json error status * fix: refactor paths -> path * fix: remove unused function * fix: only report one err per scope (ui.statusline is reported if none of ui.statusline.* is recognized) * fix: save work for later * fix: finally decided on a design * fix: ready for discussion * fix: better rules * fix: lint precision * fix: String -> &'static str * fix: allowlist not denylist for file type * fix: add missing and indication of what's needed * fix: copy pasteable errors * fix: use Loader:read_names * Update xtask/src/helpers.rs Co-authored-by: Ivan Tham <pickfire@riseup.net> * fix: remove into and clone for str * Update book/src/themes.md Co-authored-by: Ivan Tham <pickfire@riseup.net> * fix: better lint output * fix: cleaner logic for lint reporting * style: use explicit imports * Pascal support (#3542) * fix: add difference check for statusline normal,insert,select * fix: fg for whitespace and early exit if and one is ok * chore: cleaning up, no idea how these got here or how this will look * chore: revert from older commit? * refactor: use static fn to equalize api between difference and existance * refactor: querycheck and clippy * refactor: clippy fixes * fix: query-check behaves as before * fix: error with x of y message, not total count * fix: consistent reporting and less mutable state * fix: selection difference ref #3942 ref #1833 Co-authored-by: Ivan Tham <pickfire@riseup.net> Co-authored-by: ath3 <45574139+ath3@users.noreply.github.com>
2022-09-19 21:38:20 +08:00
"query-check" => tasks::querycheck()?,
"code-gen" => tasks::codegen(),
"steel" => tasks::install_steel(),
invalid => return Err(format!("Invalid task name: {}", invalid).into()),
2021-11-17 21:30:11 +08:00
},
};
Ok(())
}