Skip to content

Instantly share code, notes, and snippets.

@liuzheng1990
Created May 31, 2022 14:44
Show Gist options
  • Select an option

  • Save liuzheng1990/4338a3e3243a98d8115fbb998c43ec2d to your computer and use it in GitHub Desktop.

Select an option

Save liuzheng1990/4338a3e3243a98d8115fbb998c43ec2d to your computer and use it in GitHub Desktop.

Revisions

  1. liuzheng1990 created this gist May 31, 2022.
    27 changes: 27 additions & 0 deletions cli.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    """
    The command-line interface for the downloader
    """
    import argparse
    from .downloader import download


    def main():
    parser = argparse.ArgumentParser(
    description="An over-simplified downloader to demonstrate python packaging."
    )
    parser.add_argument(
    "url", type=str,
    help="The URL of the resource to be downloaded."
    )
    parser.add_argument(
    "--output", "-o",
    help=("Destination local file path. If not set, the resource "
    "will be downloaded to the current working directory, with filename "
    "same as the basename of the URL")
    )
    args = parser.parse_args()
    file_size = download(args.url, dest_path=args.output)
    print("Download successful! (size: {} B)".format(file_size))

    if __name__ == "__main__":
    main()