-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecotaxa-occurrences.js
69 lines (60 loc) · 1.66 KB
/
ecotaxa-occurrences.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import {
commonOptions,
csvgenerator,
jsongenerator,
ndmapcommand,
parseArgs,
} from "./deps.js";
import { occurrenceMapFactory } from "./occurrence-map.js";
import { alias } from "./alias.js";
const { stdin, args, exit } = Deno;
const helptext = () => {
console.log(`Convert EcoTaxa data to Darwin Core Occurrences
Use:
ecotaxa-occurrences --project {number} [OPTIONS] < INPUT
Options
--project EcoTaxa project number (integer)
--dataset-id
--country Set country code
--not-living Also include records classified as not-living
--dynamic-properties Store all unknown variables in dynamicProperties
--from Set input format [ tsv | ndjson ]
`);
exit(0);
};
const ignoreFactory = (args) =>
(line, i) =>
args["not-living"]
? line.length === 0
: line.length === 0 || /not-living/.test(line);
const ecotaxaOccurrencesCommand = async (args) => {
const mapfx = occurrenceMapFactory(args);
args.ignore = ignoreFactory(args);
const generator = /(nd)?json/i.test(args.from)
? jsongenerator(stdin, args)
: csvgenerator(stdin, args);
await ndmapcommand({
mapfx,
generator,
args,
});
};
if (import.meta.main) {
try {
const options = { ...commonOptions };
options.alias = { ...options.alias, ...alias };
options.default = { ...options.default, numeric: true, std: true };
const args = parseArgs(Deno.args, options);
if (args.temporary) {
args.temporaryMap = new Map(JSON.parse(args.temporary));
}
if (args.help) {
helptext();
} else {
ecotaxaOccurrencesCommand(args);
}
} catch (e) {
console.error(e);
exit(1);
}
}