1
0
mirror of https://github.com/h7x4/nix-attr-search.git synced 2025-01-13 05:24:46 +01:00
nix-attr-search/templates/option-preview-template-color.nix
h7x4 f6217e4c54
Restructure project:
The project has grown quite a bit without me remembering
to make any commits...

Here's a summary of what has happened:

- Make the project friendly towards non-flake users
- Add searchers to be created: `nur-package-search`, `nix-lib-search`
- Add misc util scripts for formatting and testing code.
- Split templates into their own directory,
    as they get quite large after a while.

- Add colorized templates.
- Replace some of the xml tags with optionally colorized output.
- Add `--no-color` option
- Add json2nix script, which will convert the json-converted
    nix code back into nix.
2022-11-26 05:14:14 +01:00

72 lines
2.1 KiB
Nix

{ pkgs }:
let
inherit (pkgs.callPackage ../internals/lib.nix { })
flatten red bold blinkred green yellow magenta blue clear;
in pkgs.writeText "nix-attrs-search-internal-option-template" (flatten ''
{{ define "colorize" -}}
{{ strings.ShellQuote . | strings.Trim "'" }}
{{- end -}}
{{ with (ds "opt")}}
{{- $origTitle := join .loc "." }}
{{- $title := join .loc "." | regexp.Replace "(<name>)" "${red}$1${clear}${bold}" }}
{{- template "colorize" "${bold}" -}}
{{- template "colorize" $title }}
{{ strings.Repeat (strings.RuneCount $origTitle) "=" }}
{{- template "colorize" "${clear}" }}
{{ if .readOnly }}
{{ template "colorize" "${blinkred}READONLY${clear}" }}
{{ end }}
{{ template "colorize" "${green}" -}}
Type: {{ .type }}
{{- template "colorize" "${clear}" }}
{{ if has . "description" }}
{{ template "colorize" "${yellow}" -}}
DESCRIPTION
{{ strings.Repeat 20 "=" }}
{{- template "colorize" "${clear}" }}
{{ getenv "DESCRIPTION" "Gomplate error: could not fetch description" }}
{{ end }}
{{- if has . "example" }}
{{ template "colorize" "${magenta}" -}}
EXAMPLE
{{ strings.Repeat 20 "=" }}
{{- template "colorize" "${clear}" }}
{{ getenv "EXAMPLE" "Gomplate error: could not fetch example" }}
{{ end }}
{{- if has . "default" }}
{{ template "colorize" "${blue}" -}}
DEFAULT
{{ strings.Repeat 20 "=" }}
{{- template "colorize" "${clear}" }}
{{ getenv "DEFAULT" "Gomplate error: could not fetch default value" }}
{{ end }}
{{- if has . "declarations" }}
{{ template "colorize" "${red}" -}}
CONFIGURED IN
{{ strings.Repeat 20 "=" }}
{{- template "colorize" "${clear}" }}
{{ range .declarations }}
{{- .path }}
{{ end }}
{{ end }}
{{- if has . "relatedPackages" }}
RELATED PACKAGES:
{{ strings.Repeat 20 "=" }}
{{ range .relatedPackages }}
{{- .attrName }}
{{- .description }}
{{ end }}
{{ end }}
{{ else }}
ERROR: Could not find datasource
{{ end }}
'')