WeiChiaChang/stacks-cli

Handle missing scheme

Opened this issue · 5 comments

ppvg commented

Entering a URL without a scheme causes the process to exit silently:

$ stacks-cli
? Which website stack do you wanna browse ? (e.g. https://github.com) github.com
╔═════════╤═════════╤═══════════════╤═══════════════╤════════════╗
║ 🏷  type │ 👀  name │ 💪  confidence │ ❓  categories │ 💻  website ║
╚═════════╧═════════╧═══════════════╧═══════════════╧════════════╝
$ echo $?
0

Would it be reasonable to assume https:// or https:// if the entered URL lacks a scheme?

ppvg commented

That fixes the silent exit. 👍

It would be great if it would also specifically handle the missing scheme in a more friendly way, for example by defaulting to https:///http:// or with a helpful error message.

Why use an entire validation library?

if(inputstr.indexOf("http://") < 0 && inputstr.indexOf("https://") < 0){
    console.log("No scheme found, defaulting to http");
    inputstr = "http://" + inputstr;
}

That's all you need.

o3LL commented

Send a PR @dospunk !