-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add check option to confirm the file is clean
- Loading branch information
Showing
2 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { | |
import { runner } from "./lib/common.ts"; | ||
import { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
|
||
const { _, binsize, b, filter, f } = parse(Deno.args); | ||
const { _, binsize, b, filter, f, check, c } = parse(Deno.args); | ||
const [column, filename] = _; | ||
if (typeof column !== "number" || typeof filename !== "string") { | ||
console.log("Usage:\n colc [column] [file.csv|tsv|txt]"); | ||
|
@@ -23,13 +23,46 @@ const filterRank: number = (() => { | |
if (typeof f === "number" && f > 0) return f; | ||
return 0; | ||
})(); | ||
const hasCheck: boolean = (() => { | ||
if (typeof check === "boolean") return check; | ||
if (typeof c === "boolean") return c; | ||
return false; | ||
})(); | ||
|
||
const isCsv = filename.endsWith(".csv"); | ||
const headerName = await runner.run( | ||
`head -n 1 ${filename}| cut -f${column} ${isCsv ? "-d, " : ""}| tr -d 0-9.-`, | ||
); | ||
const hasHeader = headerName !== ""; | ||
|
||
if (hasCheck) { | ||
const checkCommand = (() => { | ||
const bash = []; | ||
if (hasHeader) { | ||
bash.push( | ||
`tail -n +2 ${filename} | cut -f${column} ${isCsv ? "-d, " : ""}`, | ||
); | ||
} else { | ||
bash.push( | ||
`cut -f${column} ${isCsv ? "-d, " : ""}${filename} `, | ||
); | ||
} | ||
bash.push( | ||
"| awk '{clean=($1 ~/^[0-9.-]+$/);if(!clean)exit}END{print clean}'", | ||
); | ||
return bash.join(" "); | ||
})(); | ||
const result = await runner | ||
.run(checkCommand); | ||
const hasError = result === "0"; | ||
if (hasError) { | ||
console.log("dirty:<"); | ||
Deno.exit(1); | ||
} | ||
console.log("clean:D"); | ||
Deno.exit(0); | ||
} | ||
|
||
if (binSize === null) { | ||
const statsCommand = (() => { | ||
const bash = []; | ||
|