Repository: Azure/azure-cli-extensions

Issue:
az webapp new throws an exception when it can't detect a project type.
### Extension name (the extension in question)
webapp

### Description of issue (in as much detail as possible)
This should fail gracefully:

```
bash-4.3# cd /
bash-4.3# ls
appp       bin        etc        lib        media      proc       run        srv        tmp        var
azure-cli  dev        home       linuxrc    mnt        root       sbin       sys        usr
bash-4.3# az webapp new -n foo
list index out of range
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/knack/cli.py", line 194, in invoke
    cmd_result = self.invocation.execute(args)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 331, in execute
    six.reraise(*sys.exc_info())
  File "/usr/local/lib/python3.6/site-packages/six.py", line 693, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 304, in execute
    result = cmd(params)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 168, in __call__
    return super(AzCliCommand, self).__call__(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/knack/commands.py", line 109, in __call__
    return self.handler(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 348, in default_command_handler
    result = op(**command_args)
  File "/root/.azure/cliextensions/webapp/azext_webapp/custom.py", line 50, in create_deploy_webapp
    lang_details = get_lang_from_content(src_dir)
  File "/root/.azure/cliextensions/webapp/azext_webapp/create_util.py", line 113, in get_lang_from_content
    package_netcore_file = os.path.join(src_path, glob.glob("*.csproj")[0])
IndexError: list index out of range
bash-4.3# 
```

Steps to reproduce: run `az webapp new -n foo` in a *non-empty* directory that does not contain a `package.json` or a `*.csproj` file.



Discussion:

Resolving patch:
diff --git a/src/webapp/azext_webapp/create_util.py b/src/webapp/azext_webapp/create_util.py
--- a/src/webapp/azext_webapp/create_util.py
+++ b/src/webapp/azext_webapp/create_util.py
@@ -106,16 +106,17 @@ def check_app_exists(cmd, rg_name, app_name):
 
 def get_lang_from_content(src_path):
     import glob
-    # NODE: package.json should exisit in the application root dir
-    # NETCORE: NETCORE.csproj should exist in the root dir
+    # NODE: package.json should exist in the application root dir
+    # NETCORE: *.csproj should exist in the application root dir
     runtime_details_dict = dict.fromkeys(['language', 'file_loc', 'default_sku'])
     package_json_file = os.path.join(src_path, 'package.json')
-    package_netcore_file = os.path.join(src_path, glob.glob("*.csproj")[0])
+    package_netcore_glob = glob.glob("*.csproj")
     if os.path.isfile(package_json_file):
         runtime_details_dict['language'] = NODE_RUNTIME_NAME
         runtime_details_dict['file_loc'] = package_json_file
         runtime_details_dict['default_sku'] = 'S1'
-    elif os.path.isfile(package_netcore_file):
+    elif package_netcore_glob:
+        package_netcore_file = os.path.join(src_path, package_netcore_glob[0])
         runtime_details_dict['language'] = NETCORE_RUNTIME_NAME
         runtime_details_dict['file_loc'] = package_netcore_file
         runtime_details_dict['default_sku'] = 'F1'
@@ -138,7 +139,6 @@ def parse_netcore_version(file_path):
 def parse_node_version(file_path):
     import json
     import re
-    version_detected = ['0.0']
     with open(file_path) as data_file:
         data = []
         for d in find_key_in_json(json.load(data_file), 'node'):
@@ -148,7 +148,7 @@ def parse_node_version(file_path):
             # reduce the version to '6.0' from '6.0.0'
             data.append(c[:3])
         version_detected = sorted(data, key=float, reverse=True)
-    return version_detected
+    return version_detected or ['0.0']
 
 
 def detect_netcore_version_tocreate(detected_ver):


Test patch: