Move back commands/options parsing to separate shell scripts
It made the Makefile more difficult to read and this way we can take advantage of `set -e`, `-o pipefail` and friends. Clean up debugging targets
This commit is contained in:
		
							parent
							
								
									effb1be0e6
								
							
						
					
					
						commit
						5c2dd6fa2f
					
				| @ -20,28 +20,8 @@ endif | |||||||
| 
 | 
 | ||||||
| DESTDIR ?= | DESTDIR ?= | ||||||
| 
 | 
 | ||||||
| # Parse hledger's help and output all commands and command aliases in
 | PARSE_COMMANDS := ./parse-commands.sh | ||||||
| # parenthesis. Do not output single letter command aliases, it's not useful.
 | PARSE_OPTIONS := ./parse-options.sh | ||||||
| COMMANDS_TMP := commands.tmp |  | ||||||
| 
 |  | ||||||
| define PARSE_COMMANDS := |  | ||||||
| hledger > $(COMMANDS_TMP) ; |  | ||||||
| { \ |  | ||||||
| 	sed -rn 's/^\s+([a-z][-a-z]+)\s+.*/\1/p' $(COMMANDS_TMP) ; \
 |  | ||||||
| 	sed -rn 's/^\s+[a-z][-a-z]+\s+\(([a-z][ ,a-z]+)\).*/\1/p' $(COMMANDS_TMP) | \
 |  | ||||||
| 	sed 's/\s*,\s*/\n/g' | \
 |  | ||||||
| 	sed '/^.$$/d' ; \
 |  | ||||||
| } | sed '/^hledger/d' | sort -u |  | ||||||
| endef |  | ||||||
| 
 |  | ||||||
| # Parse hledger's help and output long options. Do not propose single letter
 |  | ||||||
| # completions. Options requiring an argument make that explicit by appending the
 |  | ||||||
| # equal sign (=)
 |  | ||||||
| define PARSE_OPTIONS := |  | ||||||
| sed -rn '/^\s+-/p' | \ |  | ||||||
| sed -rn 's/^\s{1,4}(-.)?\s{1,4}(--[a-zA-Z][-_a-zA-Z0-9]+=?).*/\2/p' | \ |  | ||||||
| sort -u |  | ||||||
| endef |  | ||||||
| 
 | 
 | ||||||
| EXTENSIONS := ui web api | EXTENSIONS := ui web api | ||||||
| INSTALLED_EXTENSIONS := $(foreach EXT,$(EXTENSIONS),$(shell type hledger-$(EXT) >/dev/null 2>&1 && echo $(EXT))) | INSTALLED_EXTENSIONS := $(foreach EXT,$(EXTENSIONS),$(shell type hledger-$(EXT) >/dev/null 2>&1 && echo $(EXT))) | ||||||
| @ -87,25 +67,12 @@ commands-list.txt: | |||||||
| 	printf "%s,"  $(COMMANDS) | sed 's/,$$//' > $@ | 	printf "%s,"  $(COMMANDS) | sed 's/,$$//' > $@ | ||||||
| 
 | 
 | ||||||
| generic-options.txt: | generic-options.txt: | ||||||
| 	hledger -h | $(PARSE_OPTIONS) > $@ | 	$(PARSE_OPTIONS) > $@ | ||||||
| 
 | 
 | ||||||
| options-%.txt: | options-%.txt: | ||||||
| 	hledger $* -h | $(PARSE_OPTIONS) > $@ | 	$(PARSE_OPTIONS) $* > $@ | ||||||
| 
 | 
 | ||||||
| .PHONY: clean | .PHONY: clean | ||||||
| clean: | clean: | ||||||
| 	rm -f $(COMMANDS_TMP) commands*.txt generic-options.txt options-*.txt | 	rm -f commands*.txt generic-options.txt options-*.txt | ||||||
| 	rm -f hledger-completion.bash | 	rm -f hledger-completion.bash | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| # Basic REGEX debugging targets. Example usage:
 |  | ||||||
| # diff <(make -s debug-options) <(make -s debug-options CMD=reg)
 |  | ||||||
| 
 |  | ||||||
| .PHONY: debug-commands |  | ||||||
| debug-commands: |  | ||||||
| 	$(PARSE_COMMANDS) |  | ||||||
| 
 |  | ||||||
| .PHONY: debug-options |  | ||||||
| debug-options: CMD := |  | ||||||
| debug-options: |  | ||||||
| 	hledger $(CMD) -h | $(PARSE_OPTIONS) |  | ||||||
|  | |||||||
							
								
								
									
										13
									
								
								shell-completion/parse-commands.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										13
									
								
								shell-completion/parse-commands.sh
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,13 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | # Parse hledger's help and output all commands and command aliases in | ||||||
|  | # parenthesis. Do not output single letter command aliases, it's not useful. | ||||||
|  | set -euo pipefail | ||||||
|  | 
 | ||||||
|  | declare commands_help | ||||||
|  | commands_help=$(hledger) | ||||||
|  | { | ||||||
|  |     sed -rn 's/^\s+([a-z][-a-z]+)\s+.*/\1/p' <<< "$commands_help" | ||||||
|  |     sed -rn 's/^\s+[a-z][-a-z]+\s+\(([a-z][ ,a-z]+)\).*/\1/p' <<< "$commands_help" | | ||||||
|  |     sed 's/\s*,\s*/\n/g' | | ||||||
|  |     sed '/^.$/d' | ||||||
|  | } | sed '/^hledger/d' | sort -u | ||||||
							
								
								
									
										14
									
								
								shell-completion/parse-options.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										14
									
								
								shell-completion/parse-options.sh
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | # Parse hledger's help and output long options. Do not propose single letter | ||||||
|  | # completions. Options requiring an argument make that explicit by appending the | ||||||
|  | # equal sign (=) | ||||||
|  | set -euo pipefail | ||||||
|  | 
 | ||||||
|  | declare subcommand=${1:-} | ||||||
|  | declare hledgerArgs=(--help) | ||||||
|  | [[ -n $subcommand ]] && hledgerArgs=("$subcommand" "${hledgerArgs[@]}") | ||||||
|  | 
 | ||||||
|  | hledger "${hledgerArgs[@]}" | | ||||||
|  |   sed -rn '/^\s+-/p' | | ||||||
|  |   sed -rn 's/^\s{1,4}(-.)?\s{1,4}(--[a-zA-Z][-_a-zA-Z0-9]+=?).*/\2/p' | | ||||||
|  |   sort -u | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user