Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions repli
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -1424,6 +1455,30 @@ 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

(
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'
)

}

# :command.function
repli_template_show_command() {

Expand Down Expand Up @@ -2211,6 +2266,13 @@ repli_template_parse_requirements() {
shift $#
;;

grep)
action="grep"
shift
repli_template_grep_parse_requirements "$@"
shift $#
;;

show | s)
action="show"
shift
Expand Down Expand Up @@ -2425,6 +2487,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
Expand Down Expand Up @@ -2869,6 +2998,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 ;;
Expand Down
8 changes: 8 additions & 0 deletions src/bashly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/commands/template/grep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local search="${args[search]}"

echo "Templates: $(blue "$templates_dir")"
echo "Search: $(green "$search")"
echo

(
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'
)
3 changes: 3 additions & 0 deletions test/approvals/cat_tmp_repli_yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions test/approvals/echo_1_repli_template_show_mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions test/approvals/repli_template
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions test/approvals/repli_template_grep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
missing required argument: SEARCH
usage: repli template grep SEARCH
4 changes: 4 additions & 0 deletions test/approvals/repli_template_grep_21_9
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Templates: tmp/templates
Search: 21:9

template-with-21x9
7 changes: 7 additions & 0 deletions test/approvals/repli_template_grep_2_3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Templates: tmp/templates
Search: 2:3

another
model1
model2
nested/upscaler
13 changes: 13 additions & 0 deletions test/approvals/repli_template_grep_help
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/approvals/repli_template_help
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/approvals/repli_template_show_model1
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions test/fixtures/templates/basic-grep.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions test/fixtures/templates/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions test/spec/template/grep.sh
Original file line number Diff line number Diff line change
@@ -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"