Skip to content

Commit

Permalink
Adding zsh completer and a couple more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
garnaat committed Jan 26, 2013
1 parent fea05c8 commit d91f62e
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
62 changes: 62 additions & 0 deletions bin/zsh_complete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Source this file to activate auto completion for zsh using the bash compatibility
# helper.
#
# source /path/to/zsh_complete.sh
#
# Typically that would be called somewhere in your .zshrc
#
# Note, the overwrite of _bash_complete() is to export COMP_LINE and COMP_POINT
# That is only required for zsh <= edab1d3dbe61da7efe5f1ac0e40444b2ec9b9570
#
# https://github.com/zsh-users/zsh/commit/edab1d3dbe61da7efe5f1ac0e40444b2ec9b9570
#
# zsh relases prior to that version do not export the required env variables!
#
# It is planned to write a proper zsh auto completion soon. Please talk
# to Frank Becker <[email protected]>.

autoload -U bashcompinit
bashcompinit -i

_bash_complete() {
local ret=1
local -a suf matches
local -x COMP_POINT COMP_CWORD
local -a COMP_WORDS COMPREPLY BASH_VERSINFO
local -x COMP_LINE="$words"
local -A savejobstates savejobtexts

(( COMP_POINT = 1 + ${#${(j. .)words[1,CURRENT]}} + $#QIPREFIX + $#IPREFIX + $#PREFIX ))
(( COMP_CWORD = CURRENT - 1))
COMP_WORDS=( $words )
BASH_VERSINFO=( 2 05b 0 1 release )

savejobstates=( ${(kv)jobstates} )
savejobtexts=( ${(kv)jobtexts} )

[[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' )

matches=( ${(f)"$(compgen $@ -- ${words[CURRENT]})"} )

if [[ -n $matches ]]; then
if [[ ${argv[${argv[(I)filenames]:-0}-1]} = -o ]]; then
compset -P '*/' && matches=( ${matches##*/} )
compset -S '/*' && matches=( ${matches%%/*} )
compadd -Q -f "${suf[@]}" -a matches && ret=0
else
compadd -Q "${suf[@]}" -a matches && ret=0
fi
fi

if (( ret )); then
if [[ ${argv[${argv[(I)default]:-0}-1]} = -o ]]; then
_default "${suf[@]}" && ret=0
elif [[ ${argv[${argv[(I)dirnames]:-0}-1]} = -o ]]; then
_directories "${suf[@]}" && ret=0
fi
fi

return ret
}

complete -C aws_completer aws
12 changes: 12 additions & 0 deletions tests/unit/elb/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
46 changes: 46 additions & 0 deletions tests/unit/elb/test_register_instances_with_load_balancer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import unittest
import awscli.clidriver


class TestRegisterInstancesWithLoadBalancer(unittest.TestCase):

def setUp(self):
self.driver = awscli.clidriver.CLIDriver()
self.prefix = 'aws elb register-instances-with-load-balancer'

def test_one_instance(self):
cmdline = self.prefix
cmdline += ' --load-balancer-name my-lb'
cmdline += ' --instances {"instance_id":"i-12345678"}'
result = {'LoadBalancerName': 'my-lb',
'Instances.member.1.InstanceId': 'i-12345678'}
params = self.driver.test(cmdline)
self.assertEqual(params, result)

def test_two_instance(self):
cmdline = self.prefix
cmdline += ' --load-balancer-name my-lb'
cmdline += ' --instances {"instance_id":"i-12345678"}'
cmdline += ' {"instance_id":"i-87654321"}'
result = {'LoadBalancerName': 'my-lb',
'Instances.member.1.InstanceId': 'i-12345678',
'Instances.member.2.InstanceId': 'i-87654321'}
params = self.driver.test(cmdline)
self.assertEqual(params, result)


if __name__ == "__main__":
unittest.main()

0 comments on commit d91f62e

Please sign in to comment.