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
6 changes: 5 additions & 1 deletion examples/catch-all-advanced/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ bashly generate
# ...use the double dash (--) operator to disable input normalization
./cli download source target --force -- -abc --option=value

# catch_all receives everything after the delimiter, even when an optional
# positional argument is still available
./cli download source -- -anything

./cli upload -h
./cli upload
./cli upload file1 "file 2" file3
./cli upload file1 "file 2" file3
1 change: 1 addition & 0 deletions examples/end-of-options-delimiter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
download
102 changes: 102 additions & 0 deletions examples/end-of-options-delimiter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# End-of-Options Delimiter Example

Demonstrates how `--` marks the end of options, allowing subsequent values that
start with `-` to be parsed as positional arguments.

This example was generated with:

```bash
$ bashly init --minimal
$ bashly generate
```

-----

## `bashly.yml`

````yaml
name: download
help: Sample minimal application without commands
version: 0.1.0

args:
- name: source
required: true
help: URL to download from
- name: target
help: "Target filename (default: same as source)"

flags:
- long: --force
short: -f
help: Overwrite existing files

examples:
- download example.com
- download example.com ./output -f
````



## Output

### `$ ./download`

````shell
missing required argument: SOURCE
usage: download SOURCE [TARGET] [OPTIONS]


````

### `$ ./download -h`

````shell
download - Sample minimal application without commands

Usage:
download SOURCE [TARGET] [OPTIONS]
download --help | -h
download --version | -v

Options:
--force, -f
Overwrite existing files

--help, -h
Show this help

--version, -v
Show version number

Arguments:
SOURCE
URL to download from

TARGET
Target filename (default: same as source)

Examples:
download example.com
download example.com ./output -f



````

### `$ ./download --force -- -source.txt -target.txt`

````shell
# This file is located at 'src/root_command.sh'.
# It contains the implementation for the 'download' command.
# The code you write here will be wrapped by a function named 'root_command()'.
# Feel free to edit this file; your changes will persist when regenerating.
args:
- ${args[--force]} = 1
- ${args[source]} = -source.txt
- ${args[target]} = -target.txt


````


19 changes: 19 additions & 0 deletions examples/end-of-options-delimiter/src/bashly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: download
help: Sample minimal application without commands
version: 0.1.0

args:
- name: source
required: true
help: URL to download from
- name: target
help: "Target filename (default: same as source)"

flags:
- long: --force
short: -f
help: Overwrite existing files

examples:
- download example.com
- download example.com ./output -f
5 changes: 5 additions & 0 deletions examples/end-of-options-delimiter/src/root_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
echo "# This file is located at 'src/root_command.sh'."
echo "# It contains the implementation for the 'download' command."
echo "# The code you write here will be wrapped by a function named 'root_command()'."
echo "# Feel free to edit this file; your changes will persist when regenerating."
inspect_args
13 changes: 13 additions & 0 deletions examples/end-of-options-delimiter/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

rm -f ./src/*.sh

set -x

bashly generate

### Try Me ###

./download
./download -h
./download --force -- -source.txt -target.txt
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 3.9
.\"
.TH "download" "1" "August 2026" "Version 0.1.0" "Sample application"
.TH "download" "1" "September 2026" "Version 0.1.0" "Sample application"
.SH NAME
\f[B]download\f[R] \- Sample application
.SH SYNOPSIS
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% August 2026
% September 2026

NAME
==================================================
Expand Down
10 changes: 10 additions & 0 deletions lib/bashly/views/command/parse_requirements_while.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ if catch_all.enabled?
> break
> ;;
>
else
> --)
> shift
> while [[ $# -gt 0 ]]; do
> key="$1"
= render(:parse_requirements_case).indent(8)
> done
> break
> ;;
>
end

> -?*)
Expand Down
11 changes: 11 additions & 0 deletions spec/approvals/examples/catch-all-advanced
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ other_args:
- ${other_args[*]} = -abc --option=value
- ${other_args[0]} = -abc
- ${other_args[1]} = --option=value
+ ./cli download source -- -anything
# This file is located at 'src/download_command.sh'.
# It contains the implementation for the 'cli download' command.
# The code you write here will be wrapped by a function named 'cli_download_command()'.
# Feel free to edit this file; your changes will persist when regenerating.
args:
- ${args[source]} = source

other_args:
- ${other_args[*]} = -anything
- ${other_args[0]} = -anything
+ ./cli upload -h
cli upload - Upload a file

Expand Down
46 changes: 46 additions & 0 deletions spec/approvals/examples/end-of-options-delimiter
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
+ bashly generate
creating user files in src
created src/root_command.sh
created ./download
run ./download --help to test your bash script
+ ./download
missing required argument: SOURCE
usage: download SOURCE [TARGET] [OPTIONS]
+ ./download -h
download - Sample minimal application without commands

Usage:
download SOURCE [TARGET] [OPTIONS]
download --help | -h
download --version | -v

Options:
--force, -f
Overwrite existing files

--help, -h
Show this help

--version, -v
Show version number

Arguments:
SOURCE
URL to download from

TARGET
Target filename (default: same as source)

Examples:
download example.com
download example.com ./output -f

+ ./download --force -- -source.txt -target.txt
# This file is located at 'src/root_command.sh'.
# It contains the implementation for the 'download' command.
# The code you write here will be wrapped by a function named 'root_command()'.
# Feel free to edit this file; your changes will persist when regenerating.
args:
- ${args[--force]} = 1
- ${args[source]} = -source.txt
- ${args[target]} = -target.txt
Loading