Skip to content

Commit 8ef65e1

Browse files
committed
- Allow setting the CONFIG_PATH argument via the COMPLETELY_CONFIG_PATH environment variable
1 parent 31e2da3 commit 8ef65e1

File tree

14 files changed

+112
-36
lines changed

14 files changed

+112
-36
lines changed

lib/completely/commands/base.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ module Commands
55
class Base < MisterBin::Command
66

77
class << self
8-
def config_path_usage
8+
def param_config_path
99
param "CONFIG_PATH", "Path to the YAML configuration file [default: completely.yaml]"
1010
end
1111

12-
def function_usage
12+
def option_function
1313
option "-f --function NAME", "Modify the name of the function in the generated script"
1414
end
1515

16-
def debug_usage
16+
def environment_debug
1717
environment "COMPLETELY_DEBUG", "It not empty, the generated script will include an additional debugging snippet that outputs the compline and current word to a text file when a completion is requested"
1818
end
1919
end
@@ -29,7 +29,11 @@ def completions
2929
end
3030

3131
def config_path
32-
args['CONFIG_PATH'] || 'completely.yaml'
32+
args['CONFIG_PATH'] || ENV['COMPLETELY_CONFIG_PATH'] || 'completely.yaml'
33+
end
34+
35+
def config_basename
36+
File.basename config_path, File.extname(config_path)
3337
end
3438

3539
def syntax_warning

lib/completely/commands/generate.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ class Generate < Base
88
usage "completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]"
99
usage "completely generate (-h|--help)"
1010

11-
function_usage
11+
option_function
1212
option "-w --wrap NAME", "Wrap the completion script inside a function that echos the script. This is useful if you wish to embed it directly in your script"
1313

14-
config_path_usage
15-
param "OUTPUT_PATH", "Path to the output bash script [default: completely.bash]"
16-
debug_usage
14+
param_config_path
15+
param "OUTPUT_PATH", "Path to the output bash script. When not provided, the name of the input file will be used with a .bash extension"
16+
environment_debug
1717

1818
def run
1919
wrap = args['--wrap']
@@ -30,7 +30,7 @@ def wrapper_function(wrapper_name)
3030
end
3131

3232
def output_path
33-
@output_path ||= args['OUTPUT_PATH'] || "completely.bash"
33+
@output_path ||= args['OUTPUT_PATH'] || "#{config_basename}.bash"
3434
end
3535

3636
end

lib/completely/commands/init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Init < Base
88
usage "completely init [CONFIG_PATH]"
99
usage "completely init (-h|--help)"
1010

11-
config_path_usage
11+
param_config_path
1212

1313
def run
1414
if File.exist? config_path

lib/completely/commands/preview.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class Preview < Base
88
usage "completely preview [CONFIG_PATH --function NAME]"
99
usage "completely preview (-h|--help)"
1010

11-
function_usage
12-
config_path_usage
13-
debug_usage
11+
option_function
12+
param_config_path
13+
environment_debug
1414

1515
def run
1616
puts script

lib/completely/commands/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Test < Base
2121
environment "COMPLETELY_CONFIG_PATH", "Path to a completely configuration file [default: completely.yaml]"
2222
environment "COMPLETELY_SCRIPT_PATH", "Path to a completions script. When set, this script will be tested instead of the completely configuration file"
2323
environment "COMPLETELY_SCRIPT_FUNCTION", "The main completion function to call when using a custom script. If not set, the basename of the script path will be used, prefixed by an underscore"
24-
debug_usage
24+
environment_debug
2525

2626
example %q[completely test "mygit pu"]
2727
example %q[completely test "mygit pull "]

lib/completely/templates/template.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<%= function_name %>() {
88
local cur compline
99
_init_completion -s || return
10+
1011
cur=${COMP_WORDS[COMP_CWORD]}
1112
compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
1213

@@ -20,7 +21,10 @@
2021
case "$compline" in
2122
% patterns.each do |pattern|
2223
% next if pattern.empty?
23-
<%= pattern.case_string %>) COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur")) ;;
24+
<%= pattern.case_string %>)
25+
COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur"))
26+
;;
27+
2428
% end
2529
esac
2630
} &&

spec/approvals/cli/generate/help

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Parameters:
2020
Path to the YAML configuration file [default: completely.yaml]
2121

2222
OUTPUT_PATH
23-
Path to the output bash script [default: completely.bash]
23+
Path to the output bash script. When not provided, the name of the input
24+
file will be used with a .bash extension
2425

2526
Environment Variables:
2627
COMPLETELY_DEBUG

spec/approvals/cli/generated-script

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,27 @@
77
_mygit_completions() {
88
local cur compline
99
_init_completion -s || return
10+
1011
cur=${COMP_WORDS[COMP_CWORD]}
1112
compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
1213

1314
case "$compline" in
14-
'status'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;;
15-
'commit'*) COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur")) ;;
16-
'init'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;;
17-
*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;;
15+
'status'*)
16+
COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur"))
17+
;;
18+
19+
'commit'*)
20+
COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur"))
21+
;;
22+
23+
'init'*)
24+
COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur"))
25+
;;
26+
27+
*)
28+
COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur"))
29+
;;
30+
1831
esac
1932
} &&
2033
complete -F _mygit_completions mygit

spec/approvals/cli/generated-script-alt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,27 @@
77
_mycomps() {
88
local cur compline
99
_init_completion -s || return
10+
1011
cur=${COMP_WORDS[COMP_CWORD]}
1112
compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"
1213

1314
case "$compline" in
14-
'status'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;;
15-
'commit'*) COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur")) ;;
16-
'init'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;;
17-
*) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;;
15+
'status'*)
16+
COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur"))
17+
;;
18+
19+
'commit'*)
20+
COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur"))
21+
;;
22+
23+
'init'*)
24+
COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur"))
25+
;;
26+
27+
*)
28+
COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur"))
29+
;;
30+
1831
esac
1932
} &&
2033
complete -F _mycomps mygit

spec/approvals/cli/generated-wrapped-script

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,27 @@ give_comps() {
88
echo $'_mygit_completions() {'
99
echo $' local cur compline'
1010
echo $' _init_completion -s || return'
11+
echo $''
1112
echo $' cur=${COMP_WORDS[COMP_CWORD]}'
1213
echo $' compline="${COMP_WORDS[@]:1:$COMP_CWORD-1}"'
1314
echo $''
1415
echo $' case "$compline" in'
15-
echo $' \'status\'*) COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur")) ;;'
16-
echo $' \'commit\'*) COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur")) ;;'
17-
echo $' \'init\'*) COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur")) ;;'
18-
echo $' *) COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur")) ;;'
16+
echo $' \'status\'*)'
17+
echo $' COMPREPLY=($(compgen -W "--help --verbose --branch $(git branch 2> /dev/null)" -- "$cur"))'
18+
echo $' ;;'
19+
echo $''
20+
echo $' \'commit\'*)'
21+
echo $' COMPREPLY=($(compgen -A file -W "--help --message --all -a --quiet -q" -- "$cur"))'
22+
echo $' ;;'
23+
echo $''
24+
echo $' \'init\'*)'
25+
echo $' COMPREPLY=($(compgen -A directory -W "--bare" -- "$cur"))'
26+
echo $' ;;'
27+
echo $''
28+
echo $' *)'
29+
echo $' COMPREPLY=($(compgen -W "--help --version status init commit" -- "$cur"))'
30+
echo $' ;;'
31+
echo $''
1932
echo $' esac'
2033
echo $'} &&'
2134
echo $'complete -F _mygit_completions mygit'

0 commit comments

Comments
 (0)