17 lines
528 B
Plaintext
17 lines
528 B
Plaintext
|
|
#!/usr/bin/env nu
|
||
|
|
# fmt.nu — run cargo fmt --check on the crate.
|
||
|
|
# Reads JSON inputs from stdin. Emits JSON result to stdout.
|
||
|
|
|
||
|
|
def main []: nothing -> nothing {
|
||
|
|
let inputs = ($in | from json)
|
||
|
|
let _ = $inputs # inputs acknowledged but fmt needs none
|
||
|
|
|
||
|
|
let result = (do { ^cargo fmt -- --check } | complete)
|
||
|
|
let changed = if ($result.exit_code == 0) { 0 } else { 1 }
|
||
|
|
|
||
|
|
let fix = (do { ^cargo fmt } | complete)
|
||
|
|
let ok = ($fix.exit_code == 0)
|
||
|
|
|
||
|
|
{ "formatted-code": { ok: $ok, changed: $changed } } | to json | print
|
||
|
|
}
|