Skip to content

Instantly share code, notes, and snippets.

@sophiabrandt
Last active February 6, 2024 05:15
Show Gist options
  • Save sophiabrandt/5c48685277002c1b1ceb618245bfd481 to your computer and use it in GitHub Desktop.
Save sophiabrandt/5c48685277002c1b1ceb618245bfd481 to your computer and use it in GitHub Desktop.

Revisions

  1. sophiabrandt revised this gist May 20, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme_template_downloader.nim
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@ proc cli*() =
    writeVersion()
    quit()
    of "d", "default": discard
    of "m", "default": url = "https://gist.github.com/sophiabrandt/0c68c821631e4203415f85043e29749f/raw/660b9a36f24a6cbd861f28ae861574c5a40b87f5/minimal-readme-template.md"
    of "m", "minimal": url = "https://gist.github.com/sophiabrandt/0c68c821631e4203415f85043e29749f/raw/660b9a36f24a6cbd861f28ae861574c5a40b87f5/minimal-readme-template.md"
    of "t", "template": url = val
    else:
    discard
  2. sophiabrandt renamed this gist May 20, 2020. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions readme_template.nim → readme_template_downloader.nim
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # compile with `nim -d:ssl readme_template.nim`
    # compile with `nim c -d:ssl readme_template_downloader.nim`

    import httpclient, parseopt, os

    @@ -8,18 +8,18 @@ proc downloadTemplate(link: string) =
    var file = open("README.md", fmWrite)
    defer: file.close()
    file.write(client.getContent(link))
    echo("Success - downloaded template to `README.md`.")
    echo("Success - downloaded template to README.md.")
    except IOError as err:
    echo("Failed to download template: " & err.msg)

    proc writeHelp() =
    echo """
    README Template Downloader 0.1.0 (download a README Template)
    Allowed arguments:
    - h | --help : show help
    - v | --version : show version
    - d | --default : dowloads "BEST-README-Template"
    - m | --minimal : dowloads from https://www.makeareadme.com/
    - t | --template : download link for template ("RAW")
    """

    @@ -44,6 +44,7 @@ proc cli*() =
    writeVersion()
    quit()
    of "d", "default": discard
    of "m", "default": url = "https://gist.github.com/sophiabrandt/0c68c821631e4203415f85043e29749f/raw/660b9a36f24a6cbd861f28ae861574c5a40b87f5/minimal-readme-template.md"
    of "t", "template": url = val
    else:
    discard
  3. sophiabrandt created this gist Feb 6, 2020.
    56 changes: 56 additions & 0 deletions readme_template.nim
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    # compile with `nim -d:ssl readme_template.nim`

    import httpclient, parseopt, os

    proc downloadTemplate(link: string) =
    var client = newHttpClient()
    try:
    var file = open("README.md", fmWrite)
    defer: file.close()
    file.write(client.getContent(link))
    echo("Success - downloaded template to `README.md`.")
    except IOError as err:
    echo("Failed to download template: " & err.msg)

    proc writeHelp() =
    echo """
    README Template Downloader 0.1.0 (download a README Template)
    Allowed arguments:
    - h | --help : show help
    - v | --version : show version
    - d | --default : dowloads "BEST-README-Template"
    - t | --template : download link for template ("RAW")
    """

    proc writeVersion() =
    echo "README Template Downloader 0.1.0"

    proc cli*() =
    var url: string = "https://raw.githubusercontent.com/othneildrew/Best-README-Template/master/BLANK_README.md"

    if paramCount() == 0:
    writeHelp()
    quit(0)

    for kind, key, val in getopt():
    case kind
    of cmdLongOption, cmdShortOption:
    case key
    of "help", "h":
    writeHelp()
    quit()
    of "version", "v":
    writeVersion()
    quit()
    of "d", "default": discard
    of "t", "template": url = val
    else:
    discard
    else:
    discard

    downloadTemplate(url)

    when isMainModule:
    cli()