correct docopt syntax and validation with schema

This commit is contained in:
LecygneNoir 2018-03-02 14:04:52 +01:00
parent 8863c6856d
commit 3e0865ad43

View file

@ -5,17 +5,17 @@
ptyt_upload - tool to upload videos to Peertube and Youtube ptyt_upload - tool to upload videos to Peertube and Youtube
Usage: Usage:
ptyt_upload --file=/path/to/video [options] ptyt_upload.py --file=<FILE> [options]
ptyt_upload -h | --help ptyt_upload.py -h | --help
ptyt_upload --version ptyt_upload.py --version
Options: Options:
--file=PATH Path to the video to upload. --name=NAME Name of the video to upload. default to video file name
--name=STRING Name of the video to upload. (default to video file name) -d, --description=STRING Description of the video.
-d --description=STRING Description of the video. -t, --tags=STRING Tags for the video. comma separated
-t --tags=STRING Tags for the video. (comma separated)
--version Show version.
-h --help Show this help. -h --help Show this help.
--version Show version.
""" """
@ -54,15 +54,13 @@ if __name__ == '__main__':
import pt_upload import pt_upload
options = docopt(__doc__, version=VERSION) options = docopt(__doc__, version=VERSION)
print options
schema = Schema({ schema = Schema({
'--file': And(str, lambda s: validateVideo(s), error='file is not supported, please use mp4'), '--file': And(str, lambda s: validateVideo(s), error='file is not supported, please use mp4'),
Optional('--name'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")), Optional('--name'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
Optional('--description'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")), Optional('--description'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
Optional('--d'): Or(None, And(str, lambda x: not x.isdigit(), error="The video name should be a string")),
Optional('--tags'): Or(None, And(str, lambda x: not x.isdigit(), error="Tags should be a string")), Optional('--tags'): Or(None, And(str, lambda x: not x.isdigit(), error="Tags should be a string")),
Optional('--t'): Or(None, And(str, lambda x: not x.isdigit(), error="Tags should be a string")),
'-h': bool,
'--help': bool, '--help': bool,
'--version': bool '--version': bool
}) })
@ -72,4 +70,4 @@ if __name__ == '__main__':
except SchemaError as e: except SchemaError as e:
exit(e) exit(e)
# yt_upload.run(args) yt_upload.run(options)