• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    '*.bloaty',
26    '*.c',
27    '*.cc',
28    '*.css',
29    '*.cpp',
30    '*.cmake',
31    'CMakeLists.txt',
32    '*.dts',
33    '*.dtsi',
34    '*.gn',
35    '*.gni',
36    '*.go',
37    '*.h',
38    '*.hpp',
39    '*.ld',
40    '*.md',
41    '*.options',
42    '*.proto',
43    '*.py',
44    '*.rs',
45    '*.rst',
46    '*.s',
47    '*.S',
48    '*.toml',
49)
50
51
52def add_parser_arguments(
53    parser: argparse.ArgumentParser,
54) -> argparse.ArgumentParser:
55    """Sets up an argument parser for pw watch."""
56    parser = add_project_builder_arguments(parser)
57
58    watch_group = parser.add_argument_group(title='Watch Options')
59
60    watch_group.add_argument(
61        '--patterns',
62        help=('Comma delimited list of globs to watch to trigger recompile.'),
63        default=WATCH_PATTERN_DELIMITER.join(WATCH_PATTERNS),
64    )
65
66    watch_group.add_argument(
67        '--ignore-patterns',
68        dest='ignore_patterns_string',
69        help=('Comma delimited list of globs to ignore events from.'),
70    )
71
72    watch_group.add_argument(
73        '--exclude-list',
74        nargs='+',
75        type=Path,
76        help=(
77            'Directories to ignore during pw watch. This option may be '
78            'repeated. Directories are passed as separate arguments.'
79        ),
80        default=[],
81    )
82
83    watch_group.add_argument(
84        '--no-restart',
85        dest='restart',
86        action='store_false',
87        help='do not restart ongoing builds if files change',
88    )
89
90    watch_group.add_argument(
91        '--serve-docs',
92        dest='serve_docs',
93        action='store_true',
94        default=False,
95        help='Start a webserver for docs on localhost. The port for this '
96        ' webserver can be set with the --serve-docs-port option. '
97        ' Defaults to http://127.0.0.1:8000',
98    )
99
100    watch_group.add_argument(
101        '--serve-docs-port',
102        dest='serve_docs_port',
103        type=int,
104        default=8000,
105        help='Set the port for the docs webserver. Default: 8000.',
106    )
107
108    watch_group.add_argument(
109        '--serve-docs-path',
110        dest='serve_docs_path',
111        type=Path,
112        default='docs/gen/docs',
113        help='Set the path for the docs to serve. Default: docs/gen/docs'
114        ' in the build directory.',
115    )
116
117    watch_group.add_argument(
118        '-f',
119        '--fullscreen',
120        action='store_true',
121        help='Use a fullscreen interface.',
122    )
123
124    return parser
125