Skip to content

Commit a484ff4

Browse files
committed
- Allow setting the SCRIPT_PATH argument via the COMPLETELY_SCRIPT_PATH environment variable
1 parent 531d4d4 commit a484ff4

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

lib/completely/commands/base.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ def completions
3333
end
3434

3535
def config_path
36-
args['CONFIG_PATH'] || ENV['COMPLETELY_CONFIG_PATH'] || 'completely.yaml'
36+
@config_path ||= args['CONFIG_PATH'] || ENV['COMPLETELY_CONFIG_PATH'] || 'completely.yaml'
37+
end
38+
39+
def script_path
40+
@script_path ||= args['SCRIPT_PATH'] || ENV['COMPLETELY_SCRIPT_PATH'] || "#{config_basename}.bash"
3741
end
3842

3943
def config_basename

lib/completely/commands/generate.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@ module Commands
55
class Generate < Base
66
help "Generate the bash completion script to a file"
77

8-
usage "completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]"
8+
usage "completely generate [CONFIG_PATH SCRIPT_PATH --function NAME --wrap NAME]"
99
usage "completely generate (-h|--help)"
1010

1111
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

1414
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"
15+
param "SCRIPT_PATH", "Path to the output bash script. When not provided, the name of the input file will be used with a .bash extension\nCan also be set by an environment variable"
1616

1717
environment_config_path
18+
environment "COMPLETELY_SCRIPT_PATH", "Path to the output bash script"
1819
environment_debug
1920

2021
def run
2122
wrap = args['--wrap']
2223
output = wrap ? wrapper_function(wrap) : script
23-
File.write output_path, output
24-
say "Saved !txtpur!#{output_path}"
24+
File.write script_path, output
25+
say "Saved !txtpur!#{script_path}"
2526
syntax_warning unless completions.valid?
2627
end
2728

@@ -31,10 +32,6 @@ def wrapper_function(wrapper_name)
3132
completions.wrapper_function wrapper_name
3233
end
3334

34-
def output_path
35-
@output_path ||= args['OUTPUT_PATH'] || "#{config_basename}.bash"
36-
end
37-
3835
end
3936
end
4037
end

spec/approvals/cli/generate/help

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Generate the bash completion script to a file
22

33
Usage:
4-
completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]
4+
completely generate [CONFIG_PATH SCRIPT_PATH --function NAME --wrap NAME]
55
completely generate (-h|--help)
66

77
Options:
@@ -20,14 +20,18 @@ Parameters:
2020
Path to the YAML configuration file [default: completely.yaml]
2121
Can also be set by an environment variable
2222

23-
OUTPUT_PATH
23+
SCRIPT_PATH
2424
Path to the output bash script. When not provided, the name of the input
2525
file will be used with a .bash extension
26+
Can also be set by an environment variable
2627

2728
Environment Variables:
2829
COMPLETELY_CONFIG_PATH
2930
Path to a completely configuration file [default: completely.yaml]
3031

32+
COMPLETELY_SCRIPT_PATH
33+
Path to the output bash script
34+
3135
COMPLETELY_DEBUG
3236
It not empty, the generated script will include an additional debugging
3337
snippet that outputs the compline and current word to a text file when a

spec/completely/commands/generate_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
end
4545
end
4646

47-
48-
context "with CONFIG_PATH OUTPUT_PATH" do
47+
context "with CONFIG_PATH SCRIPT_PATH" do
4948
before { reset_tmp_dir }
5049

5150
it "generates the bash script to the specified path" do

0 commit comments

Comments
 (0)