File tree Expand file tree Collapse file tree 9 files changed +101
-3
lines changed Expand file tree Collapse file tree 9 files changed +101
-3
lines changed Original file line number Diff line number Diff line change @@ -112,19 +112,19 @@ def completions_function
112112 end
113113
114114 def save_comp_yaml ( filename = nil )
115- filename ||= "completions.yaml"
115+ filename ||= "#{ Settings . target_dir } / completions.yaml"
116116 File . write filename , completions . to_yaml
117117 say "created !txtgrn!#{ filename } "
118118 say ""
119119 say "This file can be converted to a completions script using the !txtgrn!completely!txtrst! gem."
120120 end
121121
122122 def save_comp_script ( filename = nil )
123- filename ||= "completions.bash"
123+ filename ||= "#{ Settings . target_dir } / completions.bash"
124124 File . write filename , completions_script
125125 say "created !txtgrn!#{ filename } "
126126 say ""
127- say "To enable completions, run:"
127+ say "In order to enable completions, run:"
128128 say ""
129129 say " !txtpur!$ source #{ filename } "
130130 end
Original file line number Diff line number Diff line change 1+ created spec/tmp/src/lib/send_completions.sh
2+
3+ In order to use it in your script, create a command or a flag (for example: cli completions or cli --completions) that calls the send_completions function.
4+ Your users can then run something like this to enable completions:
5+
6+ $ eval "$(cli completions)"
Original file line number Diff line number Diff line change 1+ send_completions() {
2+ echo $'#!/usr/bin/env bash'
3+ echo $''
4+ echo $'# This bash completions script was generated by'
5+ echo $'# completely (https://github.com/dannyben/completely)'
6+ echo $'# Modifying it manually is not recommended'
7+ echo $'_cli_completions() {'
8+ echo $' local cur=${COMP_WORDS[COMP_CWORD]}'
9+ echo $''
10+ echo $' case "$COMP_LINE" in'
11+ echo $' \'cli download\'*) COMPREPLY=($(compgen -W "--force --help -f -h" -- "$cur")) ;;'
12+ echo $' \'cli upload\'*) COMPREPLY=($(compgen -W "--help --password --user -h -p -u" -- "$cur")) ;;'
13+ echo $' \'cli\'*) COMPREPLY=($(compgen -W "--help --version -h -v download upload" -- "$cur")) ;;'
14+ echo $' esac'
15+ echo $'}'
16+ echo $''
17+ echo $'complete -F _cli_completions cli'
18+ }
Original file line number Diff line number Diff line change 1+ created spec/tmp/completions.bash
2+
3+ In order to enable completions, run:
4+
5+ $ source spec/tmp/completions.bash
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ # This bash completions script was generated by
4+ # completely (https://github.com/dannyben/completely)
5+ # Modifying it manually is not recommended
6+ _cli_completions () {
7+ local cur=${COMP_WORDS[COMP_CWORD]}
8+
9+ case " $COMP_LINE " in
10+ ' cli download' * ) COMPREPLY=($( compgen -W " --force --help -f -h" -- " $cur " ) ) ;;
11+ ' cli upload' * ) COMPREPLY=($( compgen -W " --help --password --user -h -p -u" -- " $cur " ) ) ;;
12+ ' cli' * ) COMPREPLY=($( compgen -W " --help --version -h -v download upload" -- " $cur " ) ) ;;
13+ esac
14+ }
15+
16+ complete -F _cli_completions cli
Original file line number Diff line number Diff line change 1+ created spec/tmp/completions.yaml
2+
3+ This file can be converted to a completions script using the completely gem.
Original file line number Diff line number Diff line change 1+ ---
2+ cli:
3+ - "--help"
4+ - "--version"
5+ - "-h"
6+ - "-v"
7+ - download
8+ - upload
9+ cli download:
10+ - "--force"
11+ - "--help"
12+ - "-f"
13+ - "-h"
14+ cli upload:
15+ - "--help"
16+ - "--password"
17+ - "--user"
18+ - "-h"
19+ - "-p"
20+ - "-u"
Original file line number Diff line number Diff line change 1+ created spec/tmp/src/bashly.yml
2+ run bashly generate to create the bash script
Original file line number Diff line number Diff line change 9999 end
100100 end
101101
102+ context "with comp command" do
103+ before do
104+ reset_tmp_dir create_src : true
105+ expect { subject . run %w[ init ] } . to output_approval ( 'cli/add/init' )
106+ end
107+
108+ context "with yaml subcommand" do
109+ it "creates completions.yaml" do
110+ expect { subject . run %w[ add comp yaml ] } . to output_approval ( 'cli/add/comp-yaml' )
111+ expect ( File . read "#{ target_dir } /completions.yaml" ) . to match_approval ( 'cli/add/comp-yaml-file' )
112+ end
113+ end
114+
115+ context "with script subcommand" do
116+ it "creates completions.bash" do
117+ expect { subject . run %w[ add comp script ] } . to output_approval ( 'cli/add/comp-script' )
118+ expect ( File . read "#{ target_dir } /completions.bash" ) . to match_approval ( 'cli/add/comp-script-file' )
119+ end
120+ end
121+
122+ context "with function subcommand" do
123+ it "creates lib/send_completions.sh" do
124+ expect { subject . run %w[ add comp function ] } . to output_approval ( 'cli/add/comp-function' )
125+ expect ( File . read "#{ source_dir } /lib/send_completions.sh" ) . to match_approval ( 'cli/add/comp-function-file' )
126+ end
127+ end
128+ end
129+
102130end
You can’t perform that action at this time.
0 commit comments