From 051048a67c1549b24997eba58234eca2941d7d62 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 10 Dec 2025 10:16:09 +0000 Subject: [PATCH 1/2] - Add template grep command --- repli | 121 ++++++++++++++++++ src/bashly.yml | 8 ++ src/commands/template/grep.sh | 10 ++ test/approvals/cat_tmp_repli_yaml | 3 + test/approvals/echo_1_repli_template_show_mod | 2 + test/approvals/repli_template | 1 + test/approvals/repli_template_grep | 2 + test/approvals/repli_template_grep_21_9 | 4 + test/approvals/repli_template_grep_2_3 | 7 + test/approvals/repli_template_grep_help | 13 ++ test/approvals/repli_template_help | 1 + test/approvals/repli_template_show_model1 | 2 + test/fixtures/templates/basic-grep.yaml | 7 + test/fixtures/templates/basic.yaml | 3 + test/spec/template/grep.sh | 9 ++ 15 files changed, 193 insertions(+) create mode 100644 src/commands/template/grep.sh create mode 100644 test/approvals/repli_template_grep create mode 100644 test/approvals/repli_template_grep_21_9 create mode 100644 test/approvals/repli_template_grep_2_3 create mode 100644 test/approvals/repli_template_grep_help create mode 100644 test/fixtures/templates/basic-grep.yaml create mode 100644 test/spec/template/grep.sh diff --git a/repli b/repli index 2d20568..0ca3780 100755 --- a/repli +++ b/repli @@ -344,6 +344,7 @@ repli_template_usage() { printf "%s\n" "$(bold "Commands:")" printf " %s Add a new template from a remote Replicate model example\n" "$(green "new") " printf " %s Show list of templates\n" "$(green "list") " + printf " %s Find templates that contain a string in their YAML\n" "$(green "grep") " printf " %s Show template\n" "$(green "show") " printf " %s Open template in editor\n" "$(green "edit") " printf " %s Delete template file\n" "$(green "delete")" @@ -443,6 +444,36 @@ repli_template_list_usage() { fi } +# :command.usage +repli_template_grep_usage() { + printf "repli template grep - Find templates that contain a string in their YAML\n\n" + + printf "%s\n" "$(bold "Usage:")" + printf " repli template grep SEARCH\n" + printf " repli template grep --help | -h\n" + echo + + # :command.long_usage + if [[ -n "$long_usage" ]]; then + # :command.usage_options + printf "%s\n" "$(bold "Options:")" + + # :command.usage_fixed_flags + printf " %s\n" "$(green "--help, -h")" + printf " Show this help\n" + echo + + # :command.usage_args + printf "%s\n" "$(bold "Arguments:")" + + # :argument.usage + printf " %s\n" "$(green "SEARCH")" + printf " Search string\n" + echo + + fi +} + # :command.usage repli_template_show_usage() { printf "repli template show - Show template\n\n" @@ -1424,6 +1455,21 @@ repli_template_list_command() { } +# :command.function +repli_template_grep_command() { + + # src/commands/template/grep.sh + local search="${args[search]}" + + echo "Templates: $(blue "$templates_dir")" + echo "Search: $(green "$search")" + echo + + grep -Ril --include="*.yaml" "$search" "$templates_dir" | + sed -e "s|^$templates_dir/||" -e 's/\.yaml$//' + +} + # :command.function repli_template_show_command() { @@ -2211,6 +2257,13 @@ repli_template_parse_requirements() { shift $# ;; + grep) + action="grep" + shift + repli_template_grep_parse_requirements "$@" + shift $# + ;; + show | s) action="show" shift @@ -2425,6 +2478,73 @@ repli_template_list_parse_requirements() { } +# :command.parse_requirements +repli_template_grep_parse_requirements() { + local key + + # :command.fixed_flags_filter + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + --help | -h) + long_usage=yes + repli_template_grep_usage + exit + ;; + + *) + break + ;; + + esac + done + + # :command.command_filter + action="template grep" + + # :command.parse_requirements_while + while [[ $# -gt 0 ]]; do + key="$1" + case "$key" in + + -?*) + printf "invalid option: %s\n" "$key" >&2 + exit 1 + ;; + + *) + # :command.parse_requirements_case + # :command.parse_requirements_case_simple + # :argument.case + if [[ -z ${args['search']+x} ]]; then + args['search']=$1 + shift + else + printf "invalid argument: %s\n" "$key" >&2 + exit 1 + fi + + ;; + + esac + done + + # :command.required_args_filter + if [[ -z ${args['search']+x} ]]; then + printf "missing required argument: SEARCH\nusage: repli template grep SEARCH\n" >&2 + + exit 1 + fi + + # :command.user_filter + filter_error=$(filter_templates_dir_exists) + if [[ -n $filter_error ]]; then + echo "$filter_error" >&2 + exit 1 + fi + +} + # :command.parse_requirements repli_template_show_parse_requirements() { local key @@ -2869,6 +2989,7 @@ run() { "template") repli_template_command ;; "template new") repli_template_new_command ;; "template list") repli_template_list_command ;; + "template grep") repli_template_grep_command ;; "template show") repli_template_show_command ;; "template edit") repli_template_edit_command ;; "template delete") repli_template_delete_command ;; diff --git a/src/bashly.yml b/src/bashly.yml index 8c648ba..0fc6cf7 100644 --- a/src/bashly.yml +++ b/src/bashly.yml @@ -174,6 +174,14 @@ commands: - name: search help: Template search string + - name: grep + help: Find templates that contain a string in their YAML + filters: [templates_dir_exists] + args: + - name: search + help: Search string + required: true + - name: show alias: s help: Show template diff --git a/src/commands/template/grep.sh b/src/commands/template/grep.sh new file mode 100644 index 0000000..1bd92bb --- /dev/null +++ b/src/commands/template/grep.sh @@ -0,0 +1,10 @@ +local search="${args[search]}" + +echo "Templates: $(blue "$templates_dir")" +echo "Search: $(green "$search")" +echo + +grep -Ril --include="*.yaml" "$search" "$templates_dir" | + sed -e "s|^$templates_dir/||" -e 's/\.yaml$//' + + diff --git a/test/approvals/cat_tmp_repli_yaml b/test/approvals/cat_tmp_repli_yaml index f0296bf..f58dcef 100644 --- a/test/approvals/cat_tmp_repli_yaml +++ b/test/approvals/cat_tmp_repli_yaml @@ -2,3 +2,6 @@ model: google/nano-banana input: prompt: an image of a JSON file output_format: jpg + aspect: 2:3 + +# aspects: 2:3 16:9 diff --git a/test/approvals/echo_1_repli_template_show_mod b/test/approvals/echo_1_repli_template_show_mod index eb7dd5b..3796776 100644 --- a/test/approvals/echo_1_repli_template_show_mod +++ b/test/approvals/echo_1_repli_template_show_mod @@ -7,3 +7,5 @@ model: google/nano-banana input: prompt: an image of a JSON file output_format: jpg + aspect: 2:3 +# aspects: 2:3 16:9 diff --git a/test/approvals/repli_template b/test/approvals/repli_template index 5ee0a37..399053c 100644 --- a/test/approvals/repli_template +++ b/test/approvals/repli_template @@ -9,6 +9,7 @@ Alias: t Commands: new Add a new template from a remote Replicate model example list Show list of templates + grep Find templates that contain a string in their YAML show Show template edit Open template in editor delete Delete template file diff --git a/test/approvals/repli_template_grep b/test/approvals/repli_template_grep new file mode 100644 index 0000000..bae1a21 --- /dev/null +++ b/test/approvals/repli_template_grep @@ -0,0 +1,2 @@ +missing required argument: SEARCH +usage: repli template grep SEARCH diff --git a/test/approvals/repli_template_grep_21_9 b/test/approvals/repli_template_grep_21_9 new file mode 100644 index 0000000..f14cefc --- /dev/null +++ b/test/approvals/repli_template_grep_21_9 @@ -0,0 +1,4 @@ +Templates: tmp/templates +Search: 21:9 + +template-with-21x9 diff --git a/test/approvals/repli_template_grep_2_3 b/test/approvals/repli_template_grep_2_3 new file mode 100644 index 0000000..4164a38 --- /dev/null +++ b/test/approvals/repli_template_grep_2_3 @@ -0,0 +1,7 @@ +Templates: tmp/templates +Search: 2:3 + +another +model1 +model2 +nested/upscaler diff --git a/test/approvals/repli_template_grep_help b/test/approvals/repli_template_grep_help new file mode 100644 index 0000000..a34294a --- /dev/null +++ b/test/approvals/repli_template_grep_help @@ -0,0 +1,13 @@ +repli template grep - Find templates that contain a string in their YAML + +Usage: + repli template grep SEARCH + repli template grep --help | -h + +Options: + --help, -h + Show this help + +Arguments: + SEARCH + Search string diff --git a/test/approvals/repli_template_help b/test/approvals/repli_template_help index 860be85..b275ebb 100644 --- a/test/approvals/repli_template_help +++ b/test/approvals/repli_template_help @@ -9,6 +9,7 @@ Alias: t Commands: new Add a new template from a remote Replicate model example list Show list of templates + grep Find templates that contain a string in their YAML show Show template edit Open template in editor delete Delete template file diff --git a/test/approvals/repli_template_show_model1 b/test/approvals/repli_template_show_model1 index f0296bf..e8d7621 100644 --- a/test/approvals/repli_template_show_model1 +++ b/test/approvals/repli_template_show_model1 @@ -2,3 +2,5 @@ model: google/nano-banana input: prompt: an image of a JSON file output_format: jpg + aspect: 2:3 +# aspects: 2:3 16:9 diff --git a/test/fixtures/templates/basic-grep.yaml b/test/fixtures/templates/basic-grep.yaml new file mode 100644 index 0000000..f4bb34a --- /dev/null +++ b/test/fixtures/templates/basic-grep.yaml @@ -0,0 +1,7 @@ +model: google/nano-banana +input: + prompt: an image of a JSON file + output_format: jpg + aspect: 2:3 + +# aspects: 2:3 16:9 21:9 diff --git a/test/fixtures/templates/basic.yaml b/test/fixtures/templates/basic.yaml index f0296bf..f58dcef 100644 --- a/test/fixtures/templates/basic.yaml +++ b/test/fixtures/templates/basic.yaml @@ -2,3 +2,6 @@ model: google/nano-banana input: prompt: an image of a JSON file output_format: jpg + aspect: 2:3 + +# aspects: 2:3 16:9 diff --git a/test/spec/template/grep.sh b/test/spec/template/grep.sh new file mode 100644 index 0000000..3ac5b73 --- /dev/null +++ b/test/spec/template/grep.sh @@ -0,0 +1,9 @@ +describe "templates list" + reset_state + approve "repli template grep --help" + approve "repli template grep" + add_templates + approve "repli template grep 2:3" + cp fixtures/templates/basic-grep.yaml "$REPLI_TEMPLATES_DIR/template-with-21x9.yaml" + approve "repli template grep 21:9" + From 3248c24757b36609200f80e0312dc2fb3fad4fea Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Wed, 10 Dec 2025 10:23:36 +0000 Subject: [PATCH 2/2] ci: fix grep order --- repli | 13 +++++++++++-- src/commands/template/grep.sh | 13 ++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/repli b/repli index 0ca3780..469cc71 100755 --- a/repli +++ b/repli @@ -1465,8 +1465,17 @@ repli_template_grep_command() { echo "Search: $(green "$search")" echo - grep -Ril --include="*.yaml" "$search" "$templates_dir" | - sed -e "s|^$templates_dir/||" -e 's/\.yaml$//' + ( + cd "$templates_dir" >/dev/null || return 1 + + find . \ + -type f -name '*.yaml' \ + -printf '%P\0' | + xargs -0 grep -ilZ "$search" | + sed -z 's/\.yaml$//' | + sort -zV | + tr '\0' '\n' + ) } diff --git a/src/commands/template/grep.sh b/src/commands/template/grep.sh index 1bd92bb..c5e5b1d 100644 --- a/src/commands/template/grep.sh +++ b/src/commands/template/grep.sh @@ -4,7 +4,14 @@ echo "Templates: $(blue "$templates_dir")" echo "Search: $(green "$search")" echo -grep -Ril --include="*.yaml" "$search" "$templates_dir" | - sed -e "s|^$templates_dir/||" -e 's/\.yaml$//' - +( + cd "$templates_dir" >/dev/null || return 1 + find . \ + -type f -name '*.yaml' \ + -printf '%P\0' | + xargs -0 grep -ilZ "$search" | + sed -z 's/\.yaml$//' | + sort -zV | + tr '\0' '\n' +)