Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat: `just` `ls-config`, `grep-config`, and `grep-config-settings` (#3144)

Andrew Dunbar6a3add79d0af
diff --git a/justfile b/justfile
index a4e782997..2177e1cb9 100644
--- a/justfile
+++ b/justfile
@@ -746,3 +746,75 @@ run-snapshots:
cd harper-core
cargo test -- test_pos_tagger test_most_lints
+
+# list configuration groups by label and description, with settings if mode is verbose
+ls-config mode="brief":
+ #! /usr/bin/env node
+ const verbose = '{{mode}}' === 'verbose';
+ const config = JSON.parse(require('fs').readFileSync(require('path').join('{{justfile_directory()}}', 'harper-core/default_config.json'), 'utf8')).settings;
+
+ const formatLine = (items, maxLen = 120) => {
+ const lines = [];
+ let line = ' ';
+ items.forEach((item, i) => {
+ const comma = i < items.length - 1 ? ', ' : '';
+ const wouldExceed = line.length + item.length + comma.length > maxLen;
+ if (wouldExceed && line !== ' ') {
+ lines.push(line);
+ line = ' ';
+ }
+ line += item + comma;
+ });
+ lines.push(line);
+ return lines.join('\n');
+ };
+
+ config.forEach(g => {
+ console.log(`\x1b[1m${g.Group.label}\x1b[0m: \x1b[36m${g.Group.description}\x1b[0m`);
+ if (verbose) {
+ const names = g.Group.child.settings.map(s => s.Bool.name);
+ console.log(formatLine(names));
+ }
+ });
+
+# Search configuration groups for substring in label or description
+grep-config query:
+ #! /usr/bin/env node
+ const q = '{{query}}'.toLowerCase();
+ const config = JSON.parse(require('fs').readFileSync(require('path').join('{{justfile_directory()}}', 'harper-core/default_config.json'), 'utf8')).settings;
+
+ config.filter(g => g.Group.label.toLowerCase().includes(q) || g.Group.description.toLowerCase().includes(q))
+ .forEach(g => console.log(`\x1b[1m${g.Group.label}\x1b[0m: \x1b[36m${g.Group.description}\x1b[0m`));
+
+# search configuration group settings for substring in name
+grep-config-settings query:
+ #! /usr/bin/env node
+ const q = '{{query}}'.toLowerCase();
+ const config = JSON.parse(require('fs').readFileSync(require('path').join('{{justfile_directory()}}', 'harper-core/default_config.json'), 'utf8')).settings;
+
+ const formatLine = (items, maxLen = 120) => {
+ const lines = [];
+ let line = ' ';
+ items.forEach((item, i) => {
+ const comma = i < items.length - 1 ? ', ' : '';
+ const wouldExceed = line.length + item.length + comma.length > maxLen;
+ if (wouldExceed && line !== ' ') {
+ lines.push(line);
+ line = ' ';
+ }
+ line += item + comma;
+ });
+ lines.push(line);
+ return lines.join('\n');
+ };
+
+ config.forEach(g => {
+ const matches = g.Group.child.settings
+ .filter(s => s.Bool.name.toLowerCase().includes(q))
+ .map(s => s.Bool.name);
+
+ if (matches.length) {
+ console.log(`\x1b[1m${g.Group.label}\x1b[0m:`);
+ console.log(`\x1b[36m${formatLine(matches)}\x1b[0m`);
+ }
+ });