{ "CLI App Skeleton": { "prefix": "cli_app", "body": [ "import argparse", "import sys", "import logging", "", "logger = logging.getLogger(__name__)", "", "def main() -> int:", "\t# Handle program arguments", "\tap = argparse.ArgumentParser(prog='$1', description='$2')", "\t$3", "\tap.add_argument('-v', '--verbose', help='Enable verbose logging', action='store_true')" "\targs = ap.parse_args()", "", "\t# Configure logging", "\tlogging.basicConfig(", "\t\tlevel=logging.DEBUG if args.verbose else logging.INFO,", "\t\tformat='%(levelname)s:\t%(message)s',", "\t)", "", "\treturn 0", "", "if __name__ == \"__main__\":", "\tsys.exit(main())" ] }, "Request error handler": { "prefix": "rerror", "body": [ "if int($1.status_code / 100) != 2:", "\treturn $2" ] }, "Path to the current file": { "prefix": "__filepath__", "body": "Path(__file__)" }, "Path to the current file's parent directory": { "prefix": "__filedir__", "body": "Path(__file__).parent" }, "Disable formatting for block": { "prefix": "nofmt", "body": [ "# fmt: off", "$1", "# fmt: on", "$2" ] }, "Import Path from pathlib": { "prefix": "impath", "body": "from pathlib import Path" }, "Get a logger instance": { "prefix": "logger", "body": "logger = logging.getLogger(${1|__name__,'werkzeug'|})" }, "Import dataclass": { "prefix":"impdataclass", "body": "from dataclasses import dataclass${1:, field}" }, "Import datetime": { "prefix":"impdatetime", "body": "from datetime import datetime" }, "Import enums": { "prefix":"impenum", "body": "from enum import Enum${1:, auto}" } }