Skip to content

Commit

Permalink
Copy autocomplete into the home directory to ensure it's not lost
Browse files Browse the repository at this point in the history
  • Loading branch information
smarterclayton committed Apr 8, 2013
1 parent 659863f commit 7c6da94
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
32 changes: 20 additions & 12 deletions autocomplete/rhc_bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ _rhc()
if [[ "$cur" == -* ]]; then
opts="--clean --config --debug --insecure --mock --noprompt --password --rhlogin --server --ssl-ca-file --ssl-client-cert-file --ssl-version --timeout --token"
elif [ -z $cur ]; then
opts="account account-logout alias alias-add alias-delete-cert alias-list alias-remove alias-update-cert app app-create app-delete app-force-stop app-reload app-restart app-show app-ssh app-start app-stop app-tidy apps authorization authorization-add authorization-delete authorization-delete-all cartridge cartridge-add cartridge-list cartridge-reload cartridge-remove cartridge-restart cartridge-scale cartridge-show cartridge-start cartridge-status cartridge-stop cartridge-storage domain domain-create domain-delete domain-show domain-update git-clone port-forward server setup snapshot snapshot-restore snapshot-save sshkey sshkey-add sshkey-list sshkey-remove sshkey-show tail threaddump"
opts="account alias alias-add alias-delete-cert alias-list alias-remove alias-update-cert app app-create app-delete app-force-stop app-reload app-restart app-show app-ssh app-start app-stop app-tidy apps authorization authorization-add authorization-delete authorization-delete-all cartridge cartridge-add cartridge-list cartridge-reload cartridge-remove cartridge-restart cartridge-scale cartridge-show cartridge-start cartridge-status cartridge-stop cartridge-storage domain domain-create domain-delete domain-show domain-update git-clone logout port-forward server setup snapshot snapshot-restore snapshot-save sshkey sshkey-add sshkey-list sshkey-remove sshkey-show tail threaddump"
else
opts="account account-logout add-alias add-authorization add-cartridge add-sshkey alias alias-add alias-delete-cert alias-list alias-remove alias-update-cert app app-create app-delete app-force-stop app-reload app-restart app-show app-ssh app-start app-stop app-tidy apps authorization authorization-add authorization-delete authorization-delete-all cartridge cartridge-add cartridge-list cartridge-reload cartridge-remove cartridge-restart cartridge-scale cartridge-show cartridge-start cartridge-status cartridge-stop cartridge-storage create-app create-domain delete-all-authorization delete-app delete-authorization delete-cert-alias delete-domain domain domain-alter domain-create domain-delete domain-destroy domain-show domain-update force-stop-app git-clone list-alias list-cartridge list-sshkey logout logout-account port-forward reload-app reload-cartridge remove-alias remove-cartridge remove-sshkey restart-app restart-cartridge restore-snapshot save-snapshot scale-cartridge server setup show-app show-cartridge show-domain show-sshkey snapshot snapshot-restore snapshot-save ssh ssh-app sshkey sshkey-add sshkey-delete sshkey-list sshkey-remove sshkey-show start-app start-cartridge status-cartridge stop-app stop-cartridge storage-cartridge tail threaddump tidy-app update-cert-alias update-domain"
opts="account account-logout add-alias add-authorization add-cartridge add-sshkey alias alias-add alias-delete-cert alias-list alias-remove alias-update-cert app app-create app-delete app-force-stop app-reload app-restart app-show app-snapshot app-ssh app-start app-stop app-tidy apps authorization authorization-add authorization-delete authorization-delete-all cartridge cartridge-add cartridge-list cartridge-reload cartridge-remove cartridge-restart cartridge-scale cartridge-show cartridge-start cartridge-status cartridge-stop cartridge-storage cartridges create-app create-domain delete-all-authorization delete-app delete-authorization delete-cert-alias delete-domain domain domain-alter domain-create domain-delete domain-destroy domain-show domain-update force-stop-app git-clone list-alias list-cartridge list-sshkey logout port-forward reload-app reload-cartridge remove-alias remove-cartridge remove-sshkey restart-app restart-cartridge restore-snapshot save-snapshot scale-cartridge server setup show-app show-cartridge show-domain show-sshkey snapshot snapshot-restore snapshot-save ssh ssh-app sshkey sshkey-add sshkey-delete sshkey-list sshkey-remove sshkey-show start-app start-cartridge status-cartridge stop-app stop-cartridge storage-cartridge tail threaddump tidy-app update-cert-alias update-domain"
fi
else
prev="${COMP_WORDS[@]:0:COMP_CWORD}"
Expand All @@ -24,7 +24,7 @@ _rhc()
if [[ "$cur" == -* ]]; then
opts=""
else
opts="logout"
opts=""
fi
;;

Expand Down Expand Up @@ -308,6 +308,14 @@ _rhc()
fi
;;

"rhc app-snapshot")
if [[ "$cur" == -* ]]; then
opts=""
else
opts=""
fi
;;

"rhc app-ssh")
if [[ "$cur" == -* ]]; then
opts="--app --namespace --ssh"
Expand Down Expand Up @@ -588,6 +596,14 @@ _rhc()
fi
;;

"rhc cartridges")
if [[ "$cur" == -* ]]; then
opts="--verbose"
else
opts=""
fi
;;

"rhc create-app")
if [[ "$cur" == -* ]]; then
opts="--[no-]dns --[no-]git --app --enable-jenkins --from-code --gear-size --namespace --nogit --repo --scaling --type"
Expand Down Expand Up @@ -796,14 +812,6 @@ _rhc()
fi
;;

"rhc logout-account")
if [[ "$cur" == -* ]]; then
opts="--all"
else
opts=""
fi
;;

"rhc port-forward")
if [[ "$cur" == -* ]]; then
opts="--app --namespace"
Expand Down Expand Up @@ -902,7 +910,7 @@ _rhc()

"rhc setup")
if [[ "$cur" == -* ]]; then
opts="--[no-]create-token --clean --server"
opts="--[no-]create-token --autocomplete --clean --server"
else
opts=""
fi
Expand Down
9 changes: 7 additions & 2 deletions lib/rhc/commands/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ class Setup < Base
option ['--autocomplete'], "Instructions for enabling tab-completion"
def run
if options.autocomplete
path = File.join(File.join(Gem.loaded_specs['rhc'].full_gem_path, "autocomplete"), "rhc_bash")
src = File.join(File.join(Gem.loaded_specs['rhc'].full_gem_path, "autocomplete"), "rhc_bash")
dest = File.join(RHC::Config.home_conf_dir, "bash_autocomplete")

FileUtils.mkdir_p(RHC::Config.home_conf_dir)
FileUtils.cp(src, dest)

say <<-LINE.strip_heredoc
To enable tab-completion for RHC under Bash shells, add the following command to
your .bashrc or .bash_profile file:
. #{path}
. #{dest}
Save your shell and then restart. Type "rhc" and then hit the TAB key twice to
trigger completion of your command.
Expand Down
9 changes: 7 additions & 2 deletions spec/rhc/commands/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,15 @@

describe '--autocomplete' do
let(:arguments) { ['setup', '--autocomplete'] }
before do
path = File.join(Gem.loaded_specs['rhc'].full_gem_path, "autocomplete")
FakeFS::FileUtils.mkdir_p(path)
FakeFS::FileUtils.touch(File.join(path, "rhc_bash"))
end

context 'is passed' do
it('should output information') { run_output.should match("To enable tab-completion") }
it('should output the gem path') { run_output.should match File.join(Gem.loaded_specs['rhc'].full_gem_path, 'autocomplete') }
it('should output information') { FakeFS{ run_output.should match("To enable tab-completion") } }
it('should output the gem path') { FakeFS{ run_output.should match File.join(RHC::Config.home_conf_dir, 'bash_autocomplete') } }
end
end
end

0 comments on commit 7c6da94

Please sign in to comment.