Skip to content

Commit 5c64a05

Browse files
refactor: add --doc, --blog flags to "ap dev", hide "ap doc" etc. to avoid confusion
1 parent 27c386b commit 5c64a05

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

afterpython/cli/commands/dev.py

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,61 @@
2727
is_flag=True,
2828
help="Start the development server for all content types and the project website",
2929
)
30+
@click.option(
31+
"--doc",
32+
is_flag=True,
33+
help="Start the development server for documentation content",
34+
)
35+
@click.option(
36+
"--blog",
37+
is_flag=True,
38+
help="Start the development server for blog content",
39+
)
40+
@click.option(
41+
"--tutorial",
42+
is_flag=True,
43+
help="Start the development server for tutorial content",
44+
)
45+
@click.option(
46+
"--example",
47+
is_flag=True,
48+
help="Start the development server for example content",
49+
)
50+
@click.option(
51+
"--guide",
52+
is_flag=True,
53+
help="Start the development server for guide content",
54+
)
3055
@click.option(
3156
"--execute", is_flag=True, help="Execute Jupyter notebooks for all content types"
3257
)
3358
@click.option(
3459
"--no-website",
60+
"-n",
3561
is_flag=True,
3662
help="Skip running the website dev server (pnpm dev). Useful when you want to run pnpm dev manually with custom options.",
3763
)
38-
def dev(ctx, all: bool, execute: bool, no_website: bool):
64+
def dev(
65+
ctx,
66+
all: bool,
67+
doc: bool,
68+
blog: bool,
69+
tutorial: bool,
70+
example: bool,
71+
guide: bool,
72+
execute: bool,
73+
no_website: bool,
74+
):
3975
"""Run the development server for the project website.
4076
41-
If --all is enabled, starts MyST dev servers for all content types (doc/blog/tutorial/example/guide)
42-
and the project website.
77+
By default, runs only the website without any content servers.
78+
Use --all to start all content types, or specify individual content types with --doc, --blog, etc.
79+
80+
Examples:
81+
ap dev # Website only
82+
ap dev --all # Website + all content types
83+
ap dev --doc # Website + doc content
84+
ap dev --doc --blog # Website + doc and blog content
4385
4486
Any extra arguments are passed to the MyST servers (via 'ap doc/blog/tutorial/example/guide' commands).
4587
See "myst start --help" for more details.
@@ -79,14 +121,35 @@ def cleanup_processes():
79121
except Exception:
80122
pass
81123

124+
# Determine which content types to run
125+
if all:
126+
enabled_content_types = set(CONTENT_TYPES)
127+
else:
128+
# Check individual flags
129+
content_flags = {
130+
"doc": doc,
131+
"blog": blog,
132+
"tutorial": tutorial,
133+
"example": example,
134+
"guide": guide,
135+
}
136+
assert set(content_flags.keys()) == set(CONTENT_TYPES), (
137+
"Incomplete content flags"
138+
)
139+
enabled_content_types = {ct for ct, flag in content_flags.items() if flag}
140+
82141
try:
83-
if all:
142+
if enabled_content_types:
84143
# Clear .env.development before writing new ports
85144
env_file = paths.website_path / ".env.development"
86145
env_file.write_text("") # Clear existing content
87146

88147
next_port = 3000
89148
for content_type in CONTENT_TYPES:
149+
# Skip content types that are not enabled
150+
if content_type not in enabled_content_types:
151+
continue
152+
90153
# Find available port for MyST server
91154
myst_port = find_available_port(start_port=next_port)
92155
next_port = myst_port + 1
@@ -134,7 +197,7 @@ def cleanup_processes():
134197
click.echo(
135198
"Skipping website dev server (--no-website flag). Run 'pnpm dev' manually in afterpython/_website/ with your custom options."
136199
)
137-
if all:
200+
if enabled_content_types:
138201
# Keep the process running to maintain MyST servers
139202
click.echo("Press Ctrl+C to stop MyST servers...")
140203
while True:

afterpython/cli/commands/start.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
ignore_unknown_options=True,
1717
allow_extra_args=True,
1818
),
19+
"hidden": True, # Hide these commands from help output
1920
}
2021

2122

afterpython/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
NODEENV_VERSION = "24.11.0"
5-
CONTENT_TYPES: list[tContentType] = ["doc", "blog", "tutorial", "example", "guide"]
5+
CONTENT_TYPES: set[tContentType] = {"doc", "blog", "tutorial", "example", "guide"}

0 commit comments

Comments
 (0)