Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Provide wrapper scripts for svls, in addition to svlint. #259

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions rulesets/svls-DaveMcEwan-design
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e

# If flag/options are given that don't use the ruleset config, simply run
# svls with the given arguments.
NONRULESET="-h|--help|-V|--version"
if printf "%b\n" " $*" | grep -Eq " (${NONRULESET})";
then
svls $*
exit $?
fi

SVLINT_CONFIG="$(dirname $(command -v svls-DaveMcEwan-design))/DaveMcEwan-design.toml"

env SVLINT_CONFIG="${SVLINT_CONFIG}" svls $*
7 changes: 7 additions & 0 deletions rulesets/svls-DaveMcEwan-design.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@echo off
for /f %%E in ('where.exe svls-DaveMcEwan-design') do (
set "SVLINT_CONFIG=%%~dpEDaveMcEwan-design.toml"
)
svls %*

15 changes: 15 additions & 0 deletions rulesets/svls-DaveMcEwan-designnaming
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e

# If flag/options are given that don't use the ruleset config, simply run
# svls with the given arguments.
NONRULESET="-h|--help|-V|--version"
if printf "%b\n" " $*" | grep -Eq " (${NONRULESET})";
then
svls $*
exit $?
fi

SVLINT_CONFIG="$(dirname $(command -v svls-DaveMcEwan-designnaming))/DaveMcEwan-designnaming.toml"

env SVLINT_CONFIG="${SVLINT_CONFIG}" svls $*
7 changes: 7 additions & 0 deletions rulesets/svls-DaveMcEwan-designnaming.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@echo off
for /f %%E in ('where.exe svls-DaveMcEwan-designnaming') do (
set "SVLINT_CONFIG=%%~dpEDaveMcEwan-designnaming.toml"
)
svls %*

15 changes: 15 additions & 0 deletions rulesets/svls-designintent
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e

# If flag/options are given that don't use the ruleset config, simply run
# svls with the given arguments.
NONRULESET="-h|--help|-V|--version"
if printf "%b\n" " $*" | grep -Eq " (${NONRULESET})";
then
svls $*
exit $?
fi

SVLINT_CONFIG="$(dirname $(command -v svls-designintent))/designintent.toml"

env SVLINT_CONFIG="${SVLINT_CONFIG}" svls $*
7 changes: 7 additions & 0 deletions rulesets/svls-designintent.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@echo off
for /f %%E in ('where.exe svls-designintent') do (
set "SVLINT_CONFIG=%%~dpEdesignintent.toml"
)
svls %*

15 changes: 15 additions & 0 deletions rulesets/svls-parseonly
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e

# If flag/options are given that don't use the ruleset config, simply run
# svls with the given arguments.
NONRULESET="-h|--help|-V|--version"
if printf "%b\n" " $*" | grep -Eq " (${NONRULESET})";
then
svls $*
exit $?
fi

SVLINT_CONFIG="$(dirname $(command -v svls-parseonly))/parseonly.toml"

env SVLINT_CONFIG="${SVLINT_CONFIG}" svls $*
7 changes: 7 additions & 0 deletions rulesets/svls-parseonly.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@echo off
for /f %%E in ('where.exe svls-parseonly') do (
set "SVLINT_CONFIG=%%~dpEparseonly.toml"
)
svls %*

15 changes: 15 additions & 0 deletions rulesets/svls-simsynth
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e

# If flag/options are given that don't use the ruleset config, simply run
# svls with the given arguments.
NONRULESET="-h|--help|-V|--version"
if printf "%b\n" " $*" | grep -Eq " (${NONRULESET})";
then
svls $*
exit $?
fi

SVLINT_CONFIG="$(dirname $(command -v svls-simsynth))/simsynth.toml"

env SVLINT_CONFIG="${SVLINT_CONFIG}" svls $*
7 changes: 7 additions & 0 deletions rulesets/svls-simsynth.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@echo off
for /f %%E in ('where.exe svls-simsynth') do (
set "SVLINT_CONFIG=%%~dpEsimsynth.toml"
)
svls %*

15 changes: 15 additions & 0 deletions rulesets/svls-style
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e

# If flag/options are given that don't use the ruleset config, simply run
# svls with the given arguments.
NONRULESET="-h|--help|-V|--version"
if printf "%b\n" " $*" | grep -Eq " (${NONRULESET})";
then
svls $*
exit $?
fi

SVLINT_CONFIG="$(dirname $(command -v svls-style))/style.toml"

env SVLINT_CONFIG="${SVLINT_CONFIG}" svls $*
7 changes: 7 additions & 0 deletions rulesets/svls-style.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@echo off
for /f %%E in ('where.exe svls-style') do (
set "SVLINT_CONFIG=%%~dpEstyle.toml"
)
svls %*

15 changes: 15 additions & 0 deletions rulesets/svls-verifintent
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e

# If flag/options are given that don't use the ruleset config, simply run
# svls with the given arguments.
NONRULESET="-h|--help|-V|--version"
if printf "%b\n" " $*" | grep -Eq " (${NONRULESET})";
then
svls $*
exit $?
fi

SVLINT_CONFIG="$(dirname $(command -v svls-verifintent))/verifintent.toml"

env SVLINT_CONFIG="${SVLINT_CONFIG}" svls $*
7 changes: 7 additions & 0 deletions rulesets/svls-verifintent.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

@echo off
for /f %%E in ('where.exe svls-verifintent') do (
set "SVLINT_CONFIG=%%~dpEverifintent.toml"
)
svls %*

60 changes: 56 additions & 4 deletions src/mdgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fn write_manual_md(
}
}

fn write_ruleset_sh(ruleset: &Ruleset) -> () {
fn write_ruleset_sh_svlint(ruleset: &Ruleset) -> () {
let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let p = Path::new(&cargo_manifest_dir)
.join("rulesets")
Expand Down Expand Up @@ -317,7 +317,41 @@ fn write_ruleset_sh(ruleset: &Ruleset) -> () {
}
}

fn write_ruleset_cmd(ruleset: &Ruleset) -> () {
fn write_ruleset_sh_svls(ruleset: &Ruleset) -> () {
let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let p = Path::new(&cargo_manifest_dir)
.join("rulesets")
.join(format!("svls-{}", ruleset.name));

{
let mut o = File::create(&p).unwrap();

let _ = writeln!(o, "#!/usr/bin/env sh");
let _ = writeln!(o, "set -e");
let _ = writeln!(o, "");
let _ = writeln!(o, "# If flag/options are given that don't use the ruleset config, simply run");
let _ = writeln!(o, "# svls with the given arguments.");
let _ = writeln!(o, "NONRULESET=\"-h|--help|-V|--version\"");
let _ = writeln!(o, "if printf \"%b\\n\" \" $*\" | grep -Eq \" (${{NONRULESET}})\";");
let _ = writeln!(o, "then");
let _ = writeln!(o, " svls $*");
let _ = writeln!(o, " exit $?");
let _ = writeln!(o, "fi");
let _ = writeln!(o, "");
let _ = writeln!(o, "SVLINT_CONFIG=\"$(dirname $(command -v svls-{0}))/{0}.toml\"", ruleset.name);
let _ = writeln!(o, "");
let _ = writeln!(o, "env SVLINT_CONFIG=\"${{SVLINT_CONFIG}}\" svls $*");
}

#[cfg(unix)]
{
use std::fs::{set_permissions, Permissions};
use std::os::unix::fs::PermissionsExt;
set_permissions(&p, Permissions::from_mode(0o755)).unwrap();
}
}

fn write_ruleset_cmd_svlint(ruleset: &Ruleset) -> () {
let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let p = Path::new(&cargo_manifest_dir)
.join("rulesets")
Expand All @@ -336,6 +370,22 @@ fn write_ruleset_cmd(ruleset: &Ruleset) -> () {
let _ = write!(o, "\r\n");
}

fn write_ruleset_cmd_svls(ruleset: &Ruleset) -> () {
let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let p = Path::new(&cargo_manifest_dir)
.join("rulesets")
.join(format!("svls-{}.cmd", ruleset.name));
let mut o = File::create(&p).unwrap();

let _ = write!(o, "\r\n");
let _ = write!(o, "@echo off\r\n");
let _ = write!(o, "for /f %%E in ('where.exe svls-{0}') do (\r\n", ruleset.name);
let _ = write!(o, " set \"SVLINT_CONFIG=%%~dpE{0}.toml\"\r\n", ruleset.name);
let _ = write!(o, ")\r\n");
let _ = write!(o, "svls %*\r\n");
let _ = write!(o, "\r\n");
}

fn write_ruleset_toml(ruleset: &Ruleset) -> () {
let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let p = Path::new(&cargo_manifest_dir)
Expand All @@ -353,8 +403,10 @@ fn write_ruleset_toml(ruleset: &Ruleset) -> () {
pub fn main() {
let rulesets = get_rulesets();
for ruleset in &rulesets {
write_ruleset_sh(ruleset);
write_ruleset_cmd(ruleset);
write_ruleset_sh_svlint(ruleset);
write_ruleset_sh_svls(ruleset);
write_ruleset_cmd_svlint(ruleset);
write_ruleset_cmd_svls(ruleset);
write_ruleset_toml(ruleset);
}

Expand Down