diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-03 18:08:22 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-03 18:08:22 +0200 |
commit | d4c8bfd6f9fc4617b8abf7296cf65bcf5f7cc395 (patch) | |
tree | 8ae948332bcd44edc7c48e2d0698326dde6a66f2 /build/rust/scripts | |
parent | chore(templates): Use new common files (diff) | |
download | flake-templates-d4c8bfd6f9fc4617b8abf7296cf65bcf5f7cc395.tar.gz flake-templates-d4c8bfd6f9fc4617b8abf7296cf65bcf5f7cc395.zip |
chore(build): Regenerate
Diffstat (limited to 'build/rust/scripts')
-rwxr-xr-x | build/rust/scripts/cprh.sh | 57 | ||||
-rwxr-xr-x | build/rust/scripts/renew_copyright_header.sh | 92 |
2 files changed, 57 insertions, 92 deletions
diff --git a/build/rust/scripts/cprh.sh b/build/rust/scripts/cprh.sh new file mode 100755 index 0000000..9582575 --- /dev/null +++ b/build/rust/scripts/cprh.sh @@ -0,0 +1,57 @@ +#! /usr/bin/env sh + +die() { + echo "$@" 1>&2 + exit 1 +} + +help() { + cat <<EOF +A copyright header managment tool. + +USAGE: + cprh.sh [OPTIONS] contribute NAME EMAIL FILE.. + +OPTIONS: + --help | -h + Display this help and exit. + +ARGUMENTS: + NAME := [[git config user.name]] + Your name. + + NAME := [[git config user.email]] + Your email address. + + FILE := [[git diff --name-only --cached]] + The file you want to change. This can be given multiple times. +EOF +} + +for arg in "$@"; do + case "$arg" in + "--help" | "-h") + help + exit 0 + ;; + *) + echo "'$1' is not a recognized option. See --help for more!" 1>&2 + exit 1 + ;; + esac +done + +user_name="$1" +[ -z "$user_name" ] && die "No NAME set! See --help for more" + +user_email="$2" +[ -z "$user_email" ] && die "No EMAIL set! See --help for more" +shift 2 + +styleOne="" +styleTwo="" +[ "$COMMENT_STYLE" ] && styleOne="--style" && styleTwo="$COMMENT_STYLE" + +# The styleTwo must be unquoted to avoid adding empty args to reuse +# shellcheck disable=2086 +reuse annotate --copyright "$user_name <$user_email>" --copyright-prefix string-c --template default --multi-line $styleOne $styleTwo diff --git a/build/rust/scripts/renew_copyright_header.sh b/build/rust/scripts/renew_copyright_header.sh deleted file mode 100755 index 423547f..0000000 --- a/build/rust/scripts/renew_copyright_header.sh +++ /dev/null @@ -1,92 +0,0 @@ -#! /usr/bin/env sh - -# NOTE: This is the line length of the .licensure.yml header template **plus** the extra -# line after the template comment. -TEMPLATE_LINE_LENGTH=20 -LATEX_TEMPLATE_LINE_LENGTH=9 - -PROJECT_ROOT="$(git rev-parse --show-toplevel)" - -remove() { - extension="$1" - file="$2" - - # We need to differentiate, when removing the old copyright header, as some - # formatters do weird things to the file - case "$extension" in - # normal '#' comments (these are $TEMPLATE_LINE_LENGTH lines long) - "Makefile" | "makefile" | "toml" | "envrc" | "yml" | "gitignore" | "awk" | "pest" | "lua") - sed --in-place "1,${TEMPLATE_LINE_LENGTH}d" "$file" - ;; - # LaTeX files (or TeX files in general) have a different license, use the - # $LATEX_TEMPLATE_LINE_LENGTH variable. - "tex") - sed --in-place "1,${LATEX_TEMPLATE_LINE_LENGTH}d" "$file" - ;; - # normal '/* ... */' like comments (these are $TEMPLATE_LINE_LENGTH + 2 lines long) - "c" | "h" | "md" | "rs" | "html" | "svg" | "drawio" | "tri") - length="$((TEMPLATE_LINE_LENGTH + 2))" - sed --in-place "1,${length}d;" "$file" - ;; - # alejandra (the nix formatter) removes the blank line after the comment, - # thus only $TEMPLATE_LINE_LENGTH - 1 lines - "nix") - length="$((TEMPLATE_LINE_LENGTH - 1))" - sed --in-place "1,${length}d;" "$file" - ;; - # Shell needs a shebang on the first line, only after the first line can we - # remove the $TEMPLATE_LINE_LENGTH lines - "sh") - sed --in-place "2,${TEMPLATE_LINE_LENGTH}d;" "$file" - licensure --in-place "$file" - - TEMPLATE_LINE_LENGTH_NEW="$(($(yq --raw-output '.licenses | map(.template) | join("")' "$PROJECT_ROOT/.licensure.yml" | wc -l) + $(yq '.comments | last | .commenter.trailing_lines' "$PROJECT_ROOT/.licensure.yml")))" - - # delete the current shebang - to="$((TEMPLATE_LINE_LENGTH_NEW + 1))" - sed --in-place "${TEMPLATE_LINE_LENGTH_NEW},${to}d;" "$file" - - # add a new one - sed --in-place "1i#! /usr/bin/env sh" "$file" - ;; - *) - echo "File '$file' with extension '$extension' is not know yet, please add it!" - ;; - esac -} - -list() { - echo "$extension -> $file" -} - -if [ -f "$1" ]; then - file="$(realpath "$1")" - filename="$(basename -- "$file")" - extension="${filename##*.}" - filename="${filename%.*}" - - if [ -n "$DRY_RUN" ]; then - list "$extension" "$file" - else - remove "$extension" "$file" - fi -else - fd --type file --hidden . | while read -r file; do - if grep --quiet 'SPDX-License-Identifier' "$file"; then - filename="$(basename -- "$file")" - extension="${filename##*.}" - filename="${filename%.*}" - - if [ -n "$DRY_RUN" ]; then - list "$extension" "$file" - else - remove "$extension" "$file" - fi - fi - done - - if [ -z "$DRY_RUN" ]; then - licensure --in-place --project - nix fmt - fi -fi |