2021-12-09 19:15:21 +03:00
#!/usr/bin/env fq -rnf
def code: "`\(.)`";
def nbsp: gsub(" "; " ");
2022-09-10 19:28:54 +03:00
def has_section($f; $fhelp): $fhelp.notes or $fhelp.examples or $f.decode_in_arg or ((_registry.files[][] | select(.name=="\($f.name).md").data) // false);
2021-12-09 19:15:21 +03:00
def formats_list:
2022-09-10 19:28:54 +03:00
[ formats[] as $f
| ({} | _help_format_enrich("fq"; $f; false)) as $fhelp
| if has_section($f; $fhelp) then "[\($f.name)](doc/formats.md#\($f.name))"
else $f.name
2021-12-09 19:15:21 +03:00
end
] | join(",\n");
def formats_table:
2023-07-27 14:21:04 +03:00
( [ { name: "Name"
, desc: "Description"
, uses: "Dependencies"
}
, { name: "-"
, desc: "-"
, uses: "-"
}
, ( formats
2021-12-09 19:15:21 +03:00
| to_entries[]
| (_format_func(.key; "_help")? // {}) as $fhelp
2023-07-27 14:21:04 +03:00
| { name:
2021-12-09 19:15:21 +03:00
( ( .key as $format
| if has_section(.value; $fhelp) then "[\($format | code)](#\($format))"
else $format | code
end
)
+ " "
2023-07-27 14:21:04 +03:00
)
, desc: (.value.description | nbsp)
, uses: "<sub>\((((.value.dependencies | flatten | map(code)) | join(" "))? // ""))</sub>"
2021-12-09 19:15:21 +03:00
}
),
( [ formats
| to_entries[]
| . as $e
| select(.value.groups)
| .value.groups[] | {key: ., value: $e.key}
]
| reduce .[] as $e ({}; .[$e.key] += [$e.value])
| to_entries[]
2023-07-27 14:21:04 +03:00
| { name: ((.key | code) + " ")
, desc: "Group"
, uses: "<sub>\(((.value | map(code)) | join(" ")))</sub>"
2021-12-09 19:15:21 +03:00
}
)
]
| table(
[ .name
, .desc
, .uses
];
[ ""
2022-12-05 14:24:51 +03:00
, (.[0] | . as $rc | $rc.string | rpad(" "; $rc.maxwidth | [., .+20] | max))
, (.[1] | . as $rc | $rc.string | rpad(" "; $rc.maxwidth | [., .+20] | max))
2021-12-09 19:15:21 +03:00
, .[2].string
, ""
] | join("|")
)
);
def formats_sections:
( formats[] as $f
2022-09-10 19:28:54 +03:00
| ((_registry.files[][] | select(.name=="\($f.name).md").data) // false) as $doc
| ({} | _help_format_enrich("fq"; $f; false)) as $fhelp
2021-12-09 19:15:21 +03:00
| select(has_section($f; $fhelp))
2022-09-11 10:55:30 +03:00
| "## \($f.name)"
2024-05-24 13:08:07 +03:00
, $f.description + "."
2021-12-09 19:15:21 +03:00
, ""
, ($fhelp.notes | if . then ., "" else empty end)
, if $f.decode_in_arg then
2022-09-11 10:55:30 +03:00
( "### Options"
2021-12-09 19:15:21 +03:00
, ""
, ( [ { name: "Name"
, default: "Default"
, desc: "Description"
}
, { name: "-"
, default: "-"
, desc: "-"
}
, ( $f.decode_in_arg
| to_entries[] as {$key,$value}
| { name: ($key | code)
, default: ($value | tostring)
, desc: $f.decode_in_arg_doc[$key]
}
)
]
| table(
[ .name
, .default
, .desc
];
[ ""
, (.[0] | . as $rc | $rc.string | rpad(" "; $rc.maxwidth))
, (.[1] | . as $rc | $rc.string | rpad(" "; $rc.maxwidth))
, .[2].string
, ""
] | join("|")
)
)
, ""
)
else empty
end
, if $fhelp.examples then
2022-09-11 10:55:30 +03:00
( "### Examples"
2021-12-09 19:15:21 +03:00
, ""
, ( $fhelp.examples[]
| "\(.comment)"
, if .shell then
( "```"
, "$ \(.shell)"
, "```"
)
elif .expr then
( "```"
, "... | \(.expr)"
, "```"
)
else empty
end
, ""
)
)
else empty
end
2022-09-10 19:28:54 +03:00
, ($doc // empty)
2021-12-09 19:15:21 +03:00
);