Skip to content

Commit

Permalink
Merge branch 'master' into command-level-tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/azure/cli/main.py
  • Loading branch information
derekbekoe committed Mar 8, 2016
2 parents d177977 + f656a8c commit eee10d7
Show file tree
Hide file tree
Showing 15 changed files with 514 additions and 143 deletions.
38 changes: 14 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
FROM ubuntu:14.04

RUN rm /bin/sh && ln -s /bin/bash /bin/sh
FROM ubuntu:15.10

RUN apt-get update -qq && \
apt-get install -qqy --no-install-recommends\
build-essential \
curl \
ca-certificates \
git \
python-pip \
libffi-dev \
libssl-dev \
python-dev \
python3-pip \
vim \
nano \
jq && \
rm -rf /var/lib/apt/lists/* && \
pip install azure==2.0.0a1 && \
pip install --upgrade requests && \
pip install cryptography && \
pip install pyopenssl ndg-httpsclient pyasn1
rm -rf /var/lib/apt/lists/*

RUN pip3 install azure==2.0.0rc1

ENV AZURECLITEMP /tmp/azure-cli
ENV AZURECLITEMP /opt/azure-cli
ENV PYTHONPATH $PYTHONPATH:$AZURECLITEMP/src
ENV PATH $PATH:$AZURECLITEMP

RUN mkdir -p $AZURECLITEMP
ADD src $AZURECLITEMP/src
COPY src $AZURECLITEMP/src
COPY az.completion.sh $AZURECLITEMP/
COPY az $AZURECLITEMP/

RUN echo '#!/bin/bash'>$AZURECLITEMP/az && \
echo 'python -m azure.cli "$@"'>>$AZURECLITEMP/az && \
chmod +x $AZURECLITEMP/az && \
az
RUN chmod +x $AZURECLITEMP/az
RUN ln /usr/bin/python3 /usr/bin/python
RUN echo "source $AZURECLITEMP/az.completion.sh" >> ~/.bashrc
RUN az

ENV EDITOR vim
ENV EDITOR vim
33 changes: 33 additions & 0 deletions Dockerfile-2.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM ubuntu:14.04

RUN apt-get update -qq && \
apt-get install -qqy --no-install-recommends\
build-essential \
curl \
ca-certificates \
python-pip \
libffi-dev \
libssl-dev \
python-dev \
vim \
jq && \
rm -rf /var/lib/apt/lists/* && \
pip install azure==2.0.0rc1 && \
pip install --upgrade requests && \
pip install cryptography && \
pip install pyopenssl ndg-httpsclient pyasn1

ENV AZURECLITEMP /opt/azure-cli
ENV PYTHONPATH $PYTHONPATH:$AZURECLITEMP/src
ENV PATH $PATH:$AZURECLITEMP

RUN mkdir -p $AZURECLITEMP
COPY src $AZURECLITEMP/src
COPY az.completion.sh $AZURECLITEMP/
COPY az $AZURECLITEMP/

RUN chmod +x $AZURECLITEMP/az
RUN echo "source $AZURECLITEMP/az.completion.sh" >> ~/.bashrc
RUN az

ENV EDITOR vim
3 changes: 1 addition & 2 deletions az
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

export PYTHONPATH="${DIR}/src:${PYTHONPATH}"

python -m azure.cli "$@"

python -m azure.cli "$@"

13 changes: 13 additions & 0 deletions az.completion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if type compdef &>/dev/null; then
#ZSH
_az_complete() {
compadd -- `"${COMP_WORDS[0]}" --complete "${words[@]:1}"`
}
compdef _az_complete az
elif type complete &>/dev/null; then
#BASH
_az_complete() {
COMPREPLY=( $(compgen -W '$("${COMP_WORDS[0]}" --complete "${COMP_WORDS[@]:1}")' -- "${COMP_WORDS[COMP_CWORD]}") )
}
complete -F _az_complete az
fi
29 changes: 6 additions & 23 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<OutputPath>.</OutputPath>
<ProjectTypeGuids>{888888a0-9f3d-457c-b088-3a5042f75d52}</ProjectTypeGuids>
<LaunchProvider>Standard Python launcher</LaunchProvider>
<InterpreterId>{4ae3497d-f45c-4ec2-9e26-57476ef276a0}</InterpreterId>
<InterpreterId>{1dd9c42b-5980-42ce-a2c3-46d3bf0eede4}</InterpreterId>
<InterpreterVersion>3.5</InterpreterVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
Expand All @@ -25,7 +25,12 @@
<Compile Include="azure\cli\commands\account.py" />
<Compile Include="azure\cli\commands\login.py" />
<Compile Include="azure\cli\commands\logout.py" />
<Compile Include="azure\cli\commands\network.py" />
<Compile Include="azure\cli\commands\resourcegroup.py" />
<Compile Include="azure\cli\commands\storage.py" />
<Compile Include="azure\cli\commands\vm.py" />
<Compile Include="azure\cli\commands\_auto_command.py" />
<Compile Include="azure\cli\commands\_command_creation.py" />
<Compile Include="azure\cli\commands\__init__.py" />
<Compile Include="azure\cli\main.py" />
<Compile Include="azure\cli\tests\test_argparse.py">
Expand Down Expand Up @@ -54,28 +59,6 @@
<Folder Include="azure\cli\tests\" />
</ItemGroup>
<ItemGroup>
<Interpreter Include="..\..\Temp\burt\env27b\">
<Id>{83c20e12-84e3-4c10-a1ba-466d2b57483d}</Id>
<BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter>
<Version>2.7</Version>
<Description>env27b (Python 2.7)</Description>
<InterpreterPath>Scripts\python.exe</InterpreterPath>
<WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
<LibraryPath>Lib\</LibraryPath>
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<Architecture>X86</Architecture>
</Interpreter>
<Interpreter Include="..\..\Temp\burt\env35d\">
<Id>{4ae3497d-f45c-4ec2-9e26-57476ef276a0}</Id>
<BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter>
<Version>3.5</Version>
<Description>env35d (Python 3.5)</Description>
<InterpreterPath>Scripts\python.exe</InterpreterPath>
<WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
<LibraryPath>Lib\</LibraryPath>
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<Architecture>X86</Architecture>
</Interpreter>
<Interpreter Include="..\env\">
<Id>{1dd9c42b-5980-42ce-a2c3-46d3bf0eede4}</Id>
<BaseInterpreter>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</BaseInterpreter>
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
azure==2.0.0a1
azure==2.0.0rc1
mock==1.3.0
pylint==1.5.4
six==1.10.0
Expand Down
34 changes: 25 additions & 9 deletions src/azure/cli/_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from ._locale import L, get_file as locale_get_file
from ._logging import logger
from ._output import OutputProducer

# Named arguments are prefixed with one of these strings
ARG_PREFIXES = sorted(('-', '--', '/'), key=len, reverse=True)
Expand Down Expand Up @@ -57,6 +58,10 @@ def _index(string, char, default=sys.maxsize):
except ValueError:
return default

class ArgumentParserResult(object): #pylint: disable=too-few-public-methods
def __init__(self, result, output_format=None):
self.result = result
self.output_format = output_format

class ArgumentParser(object):
def __init__(self, prog):
Expand Down Expand Up @@ -125,6 +130,7 @@ def add_command(self,
#pylint: disable=too-many-branches
#pylint: disable=too-many-statements
#pylint: disable=too-many-locals
#pylint: disable=too-many-return-statements
def execute(self,
args,
show_usage=False,
Expand Down Expand Up @@ -177,9 +183,9 @@ def not_global(a):
show_usage = True

if show_completions:
return self._display_completions(m, args, out)
return ArgumentParserResult(self._display_completions(m, args, out))
if show_usage:
return self._display_usage(nouns, m, out)
return ArgumentParserResult(self._display_usage(nouns, m, out))

parsed = Arguments()
others = Arguments()
Expand All @@ -199,7 +205,7 @@ def not_global(a):
if value is not None:
print(L("argument '{0}' does not take a value").format(key_n),
file=out)
return self._display_usage(nouns, m, out)
return ArgumentParserResult(self._display_usage(nouns, m, out))
parsed.add_from_dotted(target_value[0], True)
else:
# Arg with a value
Expand All @@ -217,15 +223,24 @@ def not_global(a):
parsed[a]
except KeyError:
print(L("Missing required argument {}".format(a)))
return self._display_usage(nouns, m, out)
return ArgumentParserResult(self._display_usage(nouns, m, out))

output_format = None
if others and 'output' in others:
if others['output'] in OutputProducer.format_dict:
output_format = others['output']
del others['output']
else:
print(L("Invalid output format '{}' specified".format(others['output'])))
return ArgumentParserResult(self._display_usage(nouns, m, out))

old_stdout = sys.stdout
try:
sys.stdout = out
return handler(parsed, others)
return ArgumentParserResult(handler(parsed, others), output_format)
except IncorrectUsageError as ex:
print(str(ex), file=out)
return self._display_usage(nouns, m, out)
return ArgumentParserResult(self._display_usage(nouns, m, out))
finally:
sys.stdout = old_stdout

Expand Down Expand Up @@ -264,15 +279,16 @@ def _display_usage(self, nouns, noun_map, out=sys.stdout):
out.flush()
logger.debug('Expected documentation at %s', doc_file)

def _display_completions(self, noun_map, arguments, out=sys.stdout): # pylint: disable=no-self-use
arguments.remove('--complete')
def _display_completions(self, noun_map, arguments, out=sys.stdout):
for a in self.complete_args:
arguments.remove(a)

command_candidates = set([k for k in noun_map if not k.startswith('$')])
if command_candidates and not arguments[-1].startswith('-'):
command_candidates = set([c for c in command_candidates if c.startswith(arguments[-1])])

kwargs = noun_map.get('$kwargs') or []
args_candidates = set('--' + a for a in kwargs if a)
args_candidates = set(('--' if len(a) > 1 else '-') + a for a in kwargs)
if arguments[-1].startswith('-'):
# TODO: We don't have enough metadata about the command to do parameter value
# completion (yet). This should only apply to value arguments, not flag arguments
Expand Down
Loading

0 comments on commit eee10d7

Please sign in to comment.