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
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[codespell]
skip = CHANGELOG.md,sublime*
skip = CHANGELOG.md,sublime*,approvals
; ignore-words-list = bu
2 changes: 1 addition & 1 deletion examples/flux-schnell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ input:

# ADDITIONAL OPTIONS:
# output_quality: 95 # 0-100 (not relevant to PNG)
# num_output: 1 # 1-4
# num_outputs: 1 # 1-4
# num_inference_steps: 4 # 1-4
# go_fast: true
# seed: 123
7 changes: 7 additions & 0 deletions examples/upscale/google.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://replicate.com/google/upscaler

model: google/upscaler
input:
image: <source.jpg>
upscale_factor: x4 # x2 x4
compression_quality: 92
7 changes: 7 additions & 0 deletions examples/upscale/real-esrgan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://replicate.com/nightmareai/real-esrgan

model: nightmareai/real-esrgan
input:
image: <source.jpg>
scale: 2 # 0 - 10
face_enhance: false
101 changes: 61 additions & 40 deletions repli
Original file line number Diff line number Diff line change
Expand Up @@ -879,15 +879,27 @@ get_model_info() {

# src/lib/get_templates_list.sh
get_templates_list() {
local search="${1:-.}" # optional search term
local search="${1:-}"

while IFS= read -r -d '' rel; do
# Strip .yaml
local name="${rel%.yaml}"

# If not nested, show only the basename
if [[ "$rel" != */* ]]; then
printf '%s\0' "$name"
else
# Keep the relative directory path
printf '%s\0' "$name"
fi

while IFS= read -r -d '' file; do
basename -s .yaml "$file"
done < <(
find "$templates_dir" -maxdepth 1 -type f -name '*.yaml' -print0 |
find "$templates_dir" \
-type f -name '*.yaml' \
-printf '%P\0' | # <-- %P = path relative to $templates_dir
grep -iz "$search" |
sort -zV
) | tr '\n' '\0'
)
}

# src/lib/get_unique_filename.sh
Expand Down Expand Up @@ -1015,6 +1027,45 @@ replace_file_placeholders() {
echo "$json"
}

# src/lib/select_template.sh
select_template() {
local search="$1"
local exact="$2"

# Get templates list matching the search
mapfile -d '' templates < <(get_templates_list "$search")

# No matches
if [[ ${#templates[@]} -eq 0 ]]; then
log error "no matching templates"
return 1
fi

if [[ ${#templates[@]} -eq 1 ]]; then
# Exactly one match → auto-select
echo "${templates[0]}"
return
else
# Show interactive menu
show_templates_list "$search" >&2

if [[ "$exact" ]]; then
log error "no exact match"
return 1
fi

read -rp "Choose a template (1-${#templates[@]}): " choice

# Validate selection
if ! [[ "$choice" =~ ^[0-9]+$ ]] || ((choice < 1 || choice > ${#templates[@]})); then
log error "invalid selection"
return 1
fi

echo "${templates[choice - 1]}"
fi
}

# src/lib/show_templates_list.sh
show_templates_list() {
local search="${1:-.}" # optional search term
Expand Down Expand Up @@ -1155,10 +1206,10 @@ yurl() {
repli_new_command() {

# src/commands/new.sh
search="${args[search]}"
outfile="${args[--use]}"
force="${args[--force]}"
exact="${args[--exact]}"
local search="${args[search]}"
local outfile="${args[--use]}"
local force="${args[--force]}"
local exact="${args[--exact]}"

# Do not overwrite unless --force is used
if [[ -e "$outfile" && -z "$force" ]]; then
Expand All @@ -1167,37 +1218,7 @@ repli_new_command() {
return 1
fi

# Get templates list matching the search
mapfile -d '' templates < <(get_templates_list "$search")

# No matches
if [[ ${#templates[@]} -eq 0 ]]; then
log error "no matching templates"
return 1
fi

if [[ ${#templates[@]} -eq 1 ]]; then
# Exactly one match → auto-select
selected="${templates[0]}"
else
# Show interactive menu
show_templates_list "$search"

if [[ "$exact" ]]; then
log error "no exact match"
return 1
fi

read -rp "Choose a template (1-${#templates[@]}): " choice

# Validate selection
if ! [[ "$choice" =~ ^[0-9]+$ ]] || ((choice < 1 || choice > ${#templates[@]})); then
log error "invalid selection"
return 1
fi

selected="${templates[choice - 1]}"
fi
selected="$(select_template "$search" "$exact")"

# Copy file
infile="${templates_dir}/${selected}.yaml"
Expand Down
1 change: 1 addition & 0 deletions src/bashly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ variables:
value: $REPLICATE_HOST

commands:
# - { name: debug, help: Debug, private: true }
- name: new
alias: ['n', init]
help: Create a new configuration file from a tmeplate
Expand Down
40 changes: 5 additions & 35 deletions src/commands/new.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
search="${args[search]}"
outfile="${args[--use]}"
force="${args[--force]}"
exact="${args[--exact]}"
local search="${args[search]}"
local outfile="${args[--use]}"
local force="${args[--force]}"
local exact="${args[--exact]}"

# Do not overwrite unless --force is used
if [[ -e "$outfile" && -z "$force" ]]; then
Expand All @@ -10,37 +10,7 @@ if [[ -e "$outfile" && -z "$force" ]]; then
return 1
fi

# Get templates list matching the search
mapfile -d '' templates < <(get_templates_list "$search")

# No matches
if [[ ${#templates[@]} -eq 0 ]]; then
log error "no matching templates"
return 1
fi

if [[ ${#templates[@]} -eq 1 ]]; then
# Exactly one match → auto-select
selected="${templates[0]}"
else
# Show interactive menu
show_templates_list "$search"

if [[ "$exact" ]]; then
log error "no exact match"
return 1
fi

read -rp "Choose a template (1-${#templates[@]}): " choice

# Validate selection
if ! [[ "$choice" =~ ^[0-9]+$ ]] || ((choice < 1 || choice > ${#templates[@]})); then
log error "invalid selection"
return 1
fi

selected="${templates[choice - 1]}"
fi
selected="$(select_template "$search" "$exact")"

# Copy file
infile="${templates_dir}/${selected}.yaml"
Expand Down
22 changes: 17 additions & 5 deletions src/lib/get_templates_list.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
get_templates_list() {
local search="${1:-.}" # optional search term
local search="${1:-}"

while IFS= read -r -d '' rel; do
# Strip .yaml
local name="${rel%.yaml}"

# If not nested, show only the basename
if [[ "$rel" != */* ]]; then
printf '%s\0' "$name"
else
# Keep the relative directory path
printf '%s\0' "$name"
fi

while IFS= read -r -d '' file; do
basename -s .yaml "$file"
done < <(
find "$templates_dir" -maxdepth 1 -type f -name '*.yaml' -print0 |
find "$templates_dir" \
-type f -name '*.yaml' \
-printf '%P\0' | # <-- %P = path relative to $templates_dir
grep -iz "$search" |
sort -zV
) | tr '\n' '\0'
)
}
37 changes: 37 additions & 0 deletions src/lib/select_template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
select_template() {
local search="$1"
local exact="$2"

# Get templates list matching the search
mapfile -d '' templates < <(get_templates_list "$search")

# No matches
if [[ ${#templates[@]} -eq 0 ]]; then
log error "no matching templates"
return 1
fi

if [[ ${#templates[@]} -eq 1 ]]; then
# Exactly one match → auto-select
echo "${templates[0]}"
return
else
# Show interactive menu
show_templates_list "$search" >&2

if [[ "$exact" ]]; then
log error "no exact match"
return 1
fi

read -rp "Choose a template (1-${#templates[@]}): " choice

# Validate selection
if ! [[ "$choice" =~ ^[0-9]+$ ]] || ((choice < 1 || choice > ${#templates[@]})); then
log error "invalid selection"
return 1
fi

echo "${templates[choice - 1]}"
fi
}
2 changes: 1 addition & 1 deletion test/approvals/repli_new_model_exact
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Templates in tmp/templates:
1. model1
2. model2

• error • repli_new_command → no exact match
• error • select_template → no exact match
4 changes: 2 additions & 2 deletions test/approve
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ if [[ $# -gt 0 ]]; then
done
else
# No args → run all tests
while IFS= read -r file; do
for file in $(find spec -type f -name '*.sh' | sort); do
context "$file"
source "$file"
done < <(find spec -type f -name '*.sh' | sort)
done
fi