Skip to content

Allow empty string as flag argument #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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 lib/bashly/views/flag/case.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# :flag.case
<%= aliases.join " | " %> )
% if arg
if [[ $2 ]]; then
if [[ -n ${2+x} ]]; then
args[<%= name %>]="$2"
shift
shift
Expand Down
17 changes: 17 additions & 0 deletions spec/approvals/examples/empty-args
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
creating user files in src
skipped src/initialize.sh (exists)
skipped src/test_command.sh (exists)
created ./cli
run ./cli --help to test your bash script
+ ./cli test ''
# this file is located in 'src/test_command.sh'
# code for 'cli test' goes here
# you can edit it freely and regenerate (it will not be overwritten)
args:
- ${args[arg]} =
+ ./cli test --flag ''
# this file is located in 'src/test_command.sh'
# code for 'cli test' goes here
# you can edit it freely and regenerate (it will not be overwritten)
args:
- ${args[--flag]} =
1 change: 1 addition & 0 deletions spec/fixtures/workspaces/empty-args/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cli
12 changes: 12 additions & 0 deletions spec/fixtures/workspaces/empty-args/src/bashly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: cli
help: Sample application
version: 0.1.0

commands:
- name: test
help: Run test
flags:
- long: --flag
arg: value
args:
- name: arg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add another arg, so that we have one optional and one required? As I have learned in #130, there are two places these args are handled.

6 changes: 6 additions & 0 deletions spec/fixtures/workspaces/empty-args/src/initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code here runs inside the initialize() function
# Use it for anything that you need to run before any other function, like
# setting environment vairables:
# CONFIG_FILE=settings.ini
#
# Feel free to empty (but not delete) this file.
4 changes: 4 additions & 0 deletions spec/fixtures/workspaces/empty-args/src/test_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
echo "# this file is located in 'src/test_command.sh'"
echo "# code for 'cli test' goes here"
echo "# you can edit it freely and regenerate (it will not be overwritten)"
inspect_args
11 changes: 11 additions & 0 deletions spec/fixtures/workspaces/empty-args/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

# This fixture tests Bash 4+-only syntax
# It is executed as part of the Runfile examples test

bundle exec bashly generate

set -x

./cli test ''
./cli test --flag ''
2 changes: 1 addition & 1 deletion spec/fixtures/workspaces/flag-args-with-dash/argflag
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ parse_requirements() {

# :flag.case
--options | -o )
if [[ $2 ]]; then
if [[ -n ${2+x} ]]; then
args[--options]="$2"
shift
shift
Expand Down