File tree Expand file tree Collapse file tree 12 files changed +74
-52
lines changed
Expand file tree Collapse file tree 12 files changed +74
-52
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ Each of these examples demonstrates one aspect or feature of bashly.
3939- [ private-reveal] ( private-reveal#readme ) - allowing users to reveal private commands, flags or environment variables
4040- [ stdin] ( stdin#readme ) - reading input from stdin
4141- [ filters] ( filters#readme ) - preventing commands from running unless custom conditions are met
42- - [ argfile] ( argfile#readme ) - auto-load arguments from a file
42+ - [ argfile] ( argfile#readme ) - auto-load flag defaults from a file
4343- [ commands-expose] ( commands-expose#readme ) - showing subcommands in the parent's help
4444- [ key-value-pairs] ( key-value-pairs#readme ) - parsing key=value arguments and flags
4545- [ command-examples-on-error] ( command-examples-on-error#readme ) - showing examples on error
Original file line number Diff line number Diff line change 11# Argfile Example
22
3- Demonstrates how to autoload additional arguments from a file using the
4- ` argfile ` command option.
3+ Demonstrates how to autoload flag defaults from a file using the ` argfile `
4+ command option.
55
66This example was generated with:
77
@@ -23,7 +23,7 @@ name: download
2323help : Sample application with autoloaded arguments
2424version : 0.1.0
2525
26- # Allow users to configure args and flags in a file named '.download'
26+ # Allow users to configure flag defaults in a file named '.download'
2727argfile : .download
2828
2929args :
4949
5050````
5151
52+ Only flag lines are loaded from the argfile. Each flag value must appear on the
53+ same line as the flag. Non-flag lines are ignored.
54+
5255
5356## Output
5457
6770
6871````
6972
73+ ### ` $ ./download --help `
74+
75+ ```` shell
76+ download - Sample application with autoloaded arguments
77+
78+ Usage:
79+ download SOURCE [OPTIONS]
80+ download --help | -h
81+ download --version | -v
82+ ````
83+
7084### ` $ ./download somesource --log cli.log `
7185
7286```` shell
8397````
8498
8599
86-
Original file line number Diff line number Diff line change @@ -7,11 +7,6 @@ def catch_all_used_anywhere?
77 deep_commands ( include_self : true ) . any? { |x | x . catch_all . enabled? }
88 end
99
10- # Returns true if the command or any of its descendants has `argfile`
11- def argfile_used_anywhere?
12- deep_commands ( include_self : true ) . any? ( &:argfile )
13- end
14-
1510 # Returns a full list of the Command names and aliases combined
1611 def command_aliases
1712 commands . map ( &:aliases ) . flatten
Original file line number Diff line number Diff line change 11= view_marker
22
3- > load_command_argfile "{{ argfile }}" "$@"
4- > set -- "${argfile_input[@]}"
3+ > local argfile_line argfile_key argfile_value escaped
4+ > [[ -f "{{ argfile }}" ]] || return
5+ >
6+ > while IFS= read -r argfile_line || [[ -n "$argfile_line" ]]; do
7+ > [[ "$argfile_line" =~ ^[[:space:]]*(-{1,2}[^[:space:]]+)([[:space:]]+(.+))?[[:space:]]*$ ]] || continue
8+ > argfile_key="${BASH_REMATCH[1]}"
9+ > argfile_value="${BASH_REMATCH[3]:-}"
10+ > argfile_value="${argfile_value#"${argfile_value%%[![:space:]]*}"}"
11+ > argfile_value="${argfile_value%"${argfile_value##*[![:space:]]}"}"
12+ > [[ "$argfile_value" =~ ^\"(.*)\"$ || "$argfile_value" =~ ^\'(.*)\'$ ]] && argfile_value="${BASH_REMATCH[1]}"
13+ >
14+ > case "$argfile_key" in
15+ = flags.map { |flag| flag.render(:argfile_case) }.join.indent 4
16+ > esac
17+ > done < "{{ argfile }}"
518>
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 44= render :version_command
55= render :usage
66= render :normalize_input
7- = render :argfile_helpers if argfile_used_anywhere?
87= render :inspect_args if Settings.enabled? :inspect_args
98= render :user_lib if user_lib.any?
109= render :command_functions
Original file line number Diff line number Diff line change 88> local key
99>
1010
11- = render(:argfile_filter).indent 2 if argfile
1211= render(:fixed_flags_filter).indent 2
12+ = render(:argfile_filter).indent 2 if argfile
1313= render(:environment_variables_filter).indent 2
1414= render(:dependencies_filter).indent 2
1515= render(:command_filter).indent 2
Original file line number Diff line number Diff line change 1+ = view_marker
2+
3+ > {{ aliases.join " | " }})
4+ = render(arg ? :argfile_case_arg : :argfile_case_no_arg).indent 2
5+ > ;;
6+ >
Original file line number Diff line number Diff line change 1+ = view_marker
2+
3+ > if [[ -n "$argfile_value" ]]; then
4+
5+ if repeatable
6+ > escaped="$(printf '%q' "$argfile_value")"
7+ > if [[ -z ${args['{{ name }}']+x} ]]; then
8+ > args['{{ name }}']="$escaped"
9+ if unique
10+ > unique_lookup["{{ name }}:$escaped"]=1
11+ > elif [[ -z "${unique_lookup["{{ name }}:$escaped"]:-}" ]]; then
12+ > args['{{ name }}']="${args['{{ name }}']} $escaped"
13+ > unique_lookup["{{ name }}:$escaped"]=1
14+ else
15+ > else
16+ > args['{{ name }}']="${args['{{ name }}']} $escaped"
17+ end
18+ > fi
19+ else
20+ > [[ -n ${args['{{ name }}']+x} ]] || args['{{ name }}']="$argfile_value"
21+ end
22+
23+ > fi
Original file line number Diff line number Diff line change 1+ = view_marker
2+
3+ if repeatable
4+ > ((args['{{ name }}'] += 1))
5+ else
6+ > [[ -n ${args['{{ name }}']+x} ]] || args['{{ name }}']=1
7+ end
You can’t perform that action at this time.
0 commit comments