import click

from prompt_toolkit import prompt
from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.layout.lexers import PygmentsLexer
from prompt_toolkit.styles.from_pygments import style_from_pygments
from pygments.styles import get_style_by_name

from .completer import HttpPromptCompleter
from .context import Context
from .execution import execute
from .lexer import HttpPromptLexer


@click.command()
@click.argument('url')
def cli(url):
    click.echo("Welcome to HTTP Prompt!")
    context = Context(url)

    # For prompt-toolkit
    history = InMemoryHistory()
    lexer = PygmentsLexer(HttpPromptLexer)
    completer = HttpPromptCompleter(context)
    style = style_from_pygments(get_style_by_name('monokai'))

    while True:
        try:
            text = prompt('%s> ' % context.url, completer=completer,
                          lexer=lexer, style=style, history=history)
        except EOFError:
            break  # Control-D pressed
        else:
            execute(text, context)

    click.echo("Goodbye!")

import click

from prompt_toolkit import prompt
from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.layout.lexers import PygmentsLexer
from prompt_toolkit.styles.from_pygments import style_from_pygments
from pygments.styles import get_style_by_name

from .completer import HttpPromptCompleter
from .context import Context
from .execution import execute
from .lexer import HttpPromptLexer


def fix_incomplete_url(url):
    if url.startswith('s://') or url.startswith('://'):
        url = 'http' + url
    elif url.startswith('//'):
        url = 'http:' + url
    elif not url.startswith('http://') and not url.startswith('https://'):
        url = 'http://' + url
    return url


@click.command()
@click.argument('url', default='http://localhost')
def cli(url):
    click.echo("Welcome to HTTP Prompt!")

    url = fix_incomplete_url(url)
    context = Context(url)

    # For prompt-toolkit
    history = InMemoryHistory()
    lexer = PygmentsLexer(HttpPromptLexer)
    completer = HttpPromptCompleter(context)
    style = style_from_pygments(get_style_by_name('monokai'))

    while True:
        try:
            text = prompt('%s> ' % context.url, completer=completer,
                          lexer=lexer, style=style, history=history)
        except EOFError:
            break  # Control-D pressed
        else:
            execute(text, context)

    click.echo("Goodbye!")

Fix incomplete URL from command line
Fix incomplete URL from command line

  import click
  
  from prompt_toolkit import prompt
  from prompt_toolkit.history import InMemoryHistory
  from prompt_toolkit.layout.lexers import PygmentsLexer
  from prompt_toolkit.styles.from_pygments import style_from_pygments
  from pygments.styles import get_style_by_name
  
  from .completer import HttpPromptCompleter
  from .context import Context
  from .execution import execute
  from .lexer import HttpPromptLexer
  
  
+ def fix_incomplete_url(url):
+     if url.startswith('s://') or url.startswith('://'):
+         url = 'http' + url
+     elif url.startswith('//'):
+         url = 'http:' + url
+     elif not url.startswith('http://') and not url.startswith('https://'):
+         url = 'http://' + url
+     return url
+ 
+ 
  @click.command()
- @click.argument('url')
+ @click.argument('url', default='http://localhost')
  def cli(url):
      click.echo("Welcome to HTTP Prompt!")
+ 
+     url = fix_incomplete_url(url)
      context = Context(url)
  
      # For prompt-toolkit
      history = InMemoryHistory()
      lexer = PygmentsLexer(HttpPromptLexer)
      completer = HttpPromptCompleter(context)
      style = style_from_pygments(get_style_by_name('monokai'))
  
      while True:
          try:
              text = prompt('%s> ' % context.url, completer=completer,
                            lexer=lexer, style=style, history=history)
          except EOFError:
              break  # Control-D pressed
          else:
              execute(text, context)
  
      click.echo("Goodbye!")
  
Fix incomplete URL from command line
## Code Before:
import click

from prompt_toolkit import prompt
from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.layout.lexers import PygmentsLexer
from prompt_toolkit.styles.from_pygments import style_from_pygments
from pygments.styles import get_style_by_name

from .completer import HttpPromptCompleter
from .context import Context
from .execution import execute
from .lexer import HttpPromptLexer


@click.command()
@click.argument('url')
def cli(url):
    click.echo("Welcome to HTTP Prompt!")
    context = Context(url)

    # For prompt-toolkit
    history = InMemoryHistory()
    lexer = PygmentsLexer(HttpPromptLexer)
    completer = HttpPromptCompleter(context)
    style = style_from_pygments(get_style_by_name('monokai'))

    while True:
        try:
            text = prompt('%s> ' % context.url, completer=completer,
                          lexer=lexer, style=style, history=history)
        except EOFError:
            break  # Control-D pressed
        else:
            execute(text, context)

    click.echo("Goodbye!")

## Instruction:
Fix incomplete URL from command line
## Code After:
import click

from prompt_toolkit import prompt
from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.layout.lexers import PygmentsLexer
from prompt_toolkit.styles.from_pygments import style_from_pygments
from pygments.styles import get_style_by_name

from .completer import HttpPromptCompleter
from .context import Context
from .execution import execute
from .lexer import HttpPromptLexer


def fix_incomplete_url(url):
    if url.startswith('s://') or url.startswith('://'):
        url = 'http' + url
    elif url.startswith('//'):
        url = 'http:' + url
    elif not url.startswith('http://') and not url.startswith('https://'):
        url = 'http://' + url
    return url


@click.command()
@click.argument('url', default='http://localhost')
def cli(url):
    click.echo("Welcome to HTTP Prompt!")

    url = fix_incomplete_url(url)
    context = Context(url)

    # For prompt-toolkit
    history = InMemoryHistory()
    lexer = PygmentsLexer(HttpPromptLexer)
    completer = HttpPromptCompleter(context)
    style = style_from_pygments(get_style_by_name('monokai'))

    while True:
        try:
            text = prompt('%s> ' % context.url, completer=completer,
                          lexer=lexer, style=style, history=history)
        except EOFError:
            break  # Control-D pressed
        else:
            execute(text, context)

    click.echo("Goodbye!")
