1#!/usr/bin/env python 2# Copyright 2022 The Pigweed Authors 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); you may not 5# use this file except in compliance with the License. You may obtain a copy of 6# the License at 7# 8# https://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13# License for the specific language governing permissions and limitations under 14# the License. 15"""Pigweed Watch argparser.""" 16 17import argparse 18from pathlib import Path 19 20from pw_build.project_builder_argparse import add_project_builder_arguments 21 22WATCH_PATTERN_DELIMITER = ',' 23 24WATCH_PATTERNS = ( 25 '*.bazel', 26 '*.bzl', 27 '*.bloaty', 28 '*.c', 29 '*.cc', 30 '*.css', 31 '*.cpp', 32 '*.cmake', 33 'CMakeLists.txt', 34 '*.dts', 35 '*.dtsi', 36 '*.emb', 37 '*.gn', 38 '*.gni', 39 '*.go', 40 '*.h', 41 '*.hpp', 42 '*.html', 43 '*.js', 44 '*.ld', 45 '*.md', 46 '*.options', 47 '*.proto', 48 '*.py', 49 '*.rs', 50 '*.rst', 51 '*.s', 52 '*.S', 53 '*.toml', 54 '*.ts', 55) 56 57 58def add_parser_arguments( 59 parser: argparse.ArgumentParser, 60) -> argparse.ArgumentParser: 61 """Sets up an argument parser for pw watch.""" 62 parser = add_project_builder_arguments(parser) 63 64 watch_group = parser.add_argument_group(title='Watch Options') 65 66 watch_group.add_argument( 67 '--patterns', 68 help=('Comma delimited list of globs to watch to trigger recompile.'), 69 default=WATCH_PATTERN_DELIMITER.join(WATCH_PATTERNS), 70 ) 71 72 watch_group.add_argument( 73 '--ignore-patterns', 74 dest='ignore_patterns_string', 75 help=('Comma delimited list of globs to ignore events from.'), 76 ) 77 78 watch_group.add_argument( 79 '--exclude-list', 80 nargs='+', 81 type=Path, 82 help=( 83 'Directories to ignore during pw watch. This option may be ' 84 'repeated. Directories are passed as separate arguments.' 85 ), 86 default=[], 87 ) 88 89 watch_group.add_argument( 90 '--restart', 91 action=argparse.BooleanOptionalAction, 92 default=True, 93 help='Whether to restart ongoing builds if files change.', 94 ) 95 96 watch_group.add_argument( 97 '--serve-docs', 98 dest='serve_docs', 99 action='store_true', 100 default=False, 101 help='Start a webserver for docs on localhost. The port for this ' 102 ' webserver can be set with the --serve-docs-port option. ' 103 ' Defaults to http://127.0.0.1:8000', 104 ) 105 106 watch_group.add_argument( 107 '--serve-docs-port', 108 dest='serve_docs_port', 109 type=int, 110 default=8000, 111 help='Set the port for the docs webserver. Default: 8000.', 112 ) 113 114 watch_group.add_argument( 115 '--serve-docs-path', 116 dest='serve_docs_path', 117 type=Path, 118 default='docs/gen/docs', 119 help=( 120 'Set the path for the docs to serve. Default: docs/gen/docs ' 121 'in the build directory.' 122 ), 123 ) 124 125 watch_group.add_argument( 126 '-f', 127 '--fullscreen', 128 action='store_true', 129 help='Use a fullscreen interface.', 130 ) 131 132 return parser 133