Created
May 31, 2022 14:44
-
-
Save liuzheng1990/4338a3e3243a98d8115fbb998c43ec2d to your computer and use it in GitHub Desktop.
cli inerface for demo of downloader package
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment