polyenv icon indicating copy to clipboard operation
polyenv copied to clipboard

List available languages

Open FrankKair opened this issue 7 years ago • 4 comments

It would be nice to have a command to list the available languages and how should one call them, or even have some alias.

For example, to run C++, one has to call $ polyenv cpp-gcc test.cpp which is really non intuitive.

This is the json with all the available languages: https://tio.run/languages.json

FrankKair avatar Jul 12 '18 15:07 FrankKair

def available_languages():
    import requests
    url = "https://tio.run/languages.json"
    response = requests.get(url)
    data = response.json()
    return [f"{data[key]['name']} {key}" for key, value in data.items()]


def search_languages(target):
    languages = available_languages()
    return [lang for lang in languages if target.lower() in lang.lower()]


for lang in search_languages('c++'):
    print(lang)

FrankKair avatar Jul 22 '18 23:07 FrankKair

@williamjamir What do you think? What about something like $ polyenv languages to print all the available languages (with the available_languages() function) and $ polyenv languages cpp to work like a | grep -i, to help users search for their desired language.

FrankKair avatar Jul 24 '18 01:07 FrankKair

I think polyenv languages is a good solution for this, I'm just concerned with how we would implement.

  1. We can use @click.group and have two different commands (therefore losing the "default calling")
  2. Keep the default invocation, but making all arguments as optional (including "languages") and enforcing by hand that if languages is None language and file_path should be passed

williamjamir avatar Jul 25 '18 02:07 williamjamir

We can also show this list of "available language" when the class 'TioRequest' raises an exception about a wrong language type.

williamjamir avatar Jul 25 '18 13:07 williamjamir