예제 #1
0
def parse_args(argv):
    parser = argparse.ArgumentParser(prog='esphomeyaml')
    parser.add_argument('configuration', help='Your YAML configuration file.')

    subparsers = parser.add_subparsers(help='Commands', dest='command')
    subparsers.required = True
    subparsers.add_parser('config',
                          help='Validate the configuration and spit it out.')

    subparsers.add_parser('compile',
                          help='Read the configuration and compile a program.')

    parser_upload = subparsers.add_parser('upload',
                                          help='Validate the configuration '
                                          'and upload the latest binary.')
    parser_upload.add_argument('--upload-port',
                               help="Manually specify the upload port to use. "
                               "For example /dev/cu.SLAB_USBtoUART.")
    parser_upload.add_argument('--host-port',
                               help="Specify the host port.",
                               type=int)
    parser_upload.add_argument(
        '--use-esptoolpy',
        help="Use esptool.py for the uploading (only for ESP8266)",
        action='store_true')

    parser_logs = subparsers.add_parser('logs',
                                        help='Validate the configuration '
                                        'and show all MQTT logs.')
    parser_logs.add_argument('--topic',
                             help='Manually set the topic to subscribe to.')
    parser_logs.add_argument('--username', help='Manually set the username.')
    parser_logs.add_argument('--password', help='Manually set the password.')
    parser_logs.add_argument('--client-id', help='Manually set the client id.')
    parser_logs.add_argument('--serial-port',
                             help="Manually specify a serial port to use"
                             "For example /dev/cu.SLAB_USBtoUART.")
    parser_logs.add_argument(
        '--escape',
        help="Escape ANSI color codes for running in dashboard",
        action='store_true')

    parser_run = subparsers.add_parser(
        'run',
        help='Validate the configuration, create a binary, '
        'upload it, and start MQTT logs.')
    parser_run.add_argument('--upload-port',
                            help="Manually specify the upload port to use. "
                            "For example /dev/cu.SLAB_USBtoUART.")
    parser_run.add_argument('--host-port',
                            help="Specify the host port to use for OTA",
                            type=int)
    parser_run.add_argument('--no-logs',
                            help='Disable starting MQTT logs.',
                            action='store_true')
    parser_run.add_argument(
        '--topic', help='Manually set the topic to subscribe to for logs.')
    parser_run.add_argument('--username',
                            help='Manually set the MQTT username for logs.')
    parser_run.add_argument('--password',
                            help='Manually set the MQTT password for logs.')
    parser_run.add_argument('--client-id',
                            help='Manually set the client id for logs.')
    parser_run.add_argument(
        '--escape',
        help="Escape ANSI color codes for running in dashboard",
        action='store_true')
    parser_run.add_argument(
        '--use-esptoolpy',
        help="Use esptool.py for the uploading (only for ESP8266)",
        action='store_true')

    parser_clean = subparsers.add_parser(
        'clean-mqtt',
        help="Helper to clear an MQTT topic from "
        "retain messages.")
    parser_clean.add_argument('--topic',
                              help='Manually set the topic to subscribe to.')
    parser_clean.add_argument('--username', help='Manually set the username.')
    parser_clean.add_argument('--password', help='Manually set the password.')
    parser_clean.add_argument('--client-id',
                              help='Manually set the client id.')

    subparsers.add_parser('wizard',
                          help="A helpful setup wizard that will guide "
                          "you through setting up esphomeyaml.")

    subparsers.add_parser('mqtt-fingerprint',
                          help="Get the SSL fingerprint from a MQTT broker.")

    subparsers.add_parser('version',
                          help="Print the esphomeyaml version and exit.")

    dashboard = subparsers.add_parser(
        'dashboard', help="Create a simple webserver for a dashboard.")
    dashboard.add_argument("--port",
                           help="The HTTP port to open connections on.",
                           type=int,
                           default=6052)

    return parser.parse_args(argv[1:])
예제 #2
0
def parse_args(argv):
    parser = argparse.ArgumentParser(prog='esphomeyaml')
    parser.add_argument('-v',
                        '--verbose',
                        help="Enable verbose esphomeyaml logs.",
                        action='store_true')
    parser.add_argument(
        '--dashboard',
        help="Internal flag to set if the command is run from the "
        "dashboard.",
        action='store_true')
    parser.add_argument('configuration', help='Your YAML configuration file.')

    subparsers = parser.add_subparsers(help='Commands', dest='command')
    subparsers.required = True
    subparsers.add_parser('config',
                          help='Validate the configuration and spit it out.')

    parser_compile = subparsers.add_parser(
        'compile', help='Read the configuration and compile a program.')
    parser_compile.add_argument(
        '--only-generate',
        help="Only generate source code, do not compile.",
        action='store_true')

    parser_upload = subparsers.add_parser('upload',
                                          help='Validate the configuration '
                                          'and upload the latest binary.')
    parser_upload.add_argument('--upload-port',
                               help="Manually specify the upload port to use. "
                               "For example /dev/cu.SLAB_USBtoUART.")
    parser_upload.add_argument('--host-port',
                               help="Specify the host port.",
                               type=int)

    parser_logs = subparsers.add_parser('logs',
                                        help='Validate the configuration '
                                        'and show all MQTT logs.')
    parser_logs.add_argument('--topic',
                             help='Manually set the topic to subscribe to.')
    parser_logs.add_argument('--username', help='Manually set the username.')
    parser_logs.add_argument('--password', help='Manually set the password.')
    parser_logs.add_argument('--client-id', help='Manually set the client id.')
    parser_logs.add_argument('--serial-port',
                             help="Manually specify a serial port to use"
                             "For example /dev/cu.SLAB_USBtoUART.")

    parser_run = subparsers.add_parser(
        'run',
        help='Validate the configuration, create a binary, '
        'upload it, and start MQTT logs.')
    parser_run.add_argument('--upload-port',
                            help="Manually specify the upload port/ip to use. "
                            "For example /dev/cu.SLAB_USBtoUART.")
    parser_run.add_argument('--host-port',
                            help="Specify the host port to use for OTA",
                            type=int)
    parser_run.add_argument('--no-logs',
                            help='Disable starting MQTT logs.',
                            action='store_true')
    parser_run.add_argument(
        '--topic', help='Manually set the topic to subscribe to for logs.')
    parser_run.add_argument('--username',
                            help='Manually set the MQTT username for logs.')
    parser_run.add_argument('--password',
                            help='Manually set the MQTT password for logs.')
    parser_run.add_argument('--client-id',
                            help='Manually set the client id for logs.')

    parser_clean = subparsers.add_parser(
        'clean-mqtt',
        help="Helper to clear an MQTT topic from "
        "retain messages.")
    parser_clean.add_argument('--topic',
                              help='Manually set the topic to subscribe to.')
    parser_clean.add_argument('--username', help='Manually set the username.')
    parser_clean.add_argument('--password', help='Manually set the password.')
    parser_clean.add_argument('--client-id',
                              help='Manually set the client id.')

    subparsers.add_parser('wizard',
                          help="A helpful setup wizard that will guide "
                          "you through setting up esphomeyaml.")

    subparsers.add_parser('mqtt-fingerprint',
                          help="Get the SSL fingerprint from a MQTT broker.")

    subparsers.add_parser('version',
                          help="Print the esphomeyaml version and exit.")

    subparsers.add_parser('clean', help="Delete all temporary build files.")

    dashboard = subparsers.add_parser(
        'dashboard', help="Create a simple web server for a dashboard.")
    dashboard.add_argument(
        "--port",
        help="The HTTP port to open connections on. Defaults to 6052.",
        type=int,
        default=6052)
    dashboard.add_argument(
        "--password",
        help="The optional password to require for all requests.",
        type=str,
        default='')
    dashboard.add_argument("--open-ui",
                           help="Open the dashboard UI in a browser.",
                           action='store_true')
    dashboard.add_argument(
        "--hassio",
        help="Internal flag used to tell esphomeyaml is started as a Hass.io "
        "add-on.",
        action="store_true")
    dashboard.add_argument("--socket",
                           help="Make the dashboard serve under a unix socket",
                           type=str)

    subparsers.add_parser(
        'hass-config',
        help="Dump the configuration entries that should be added "
        "to Home Assistant when not using MQTT discovery.")

    return parser.parse_args(argv[1:])