feat: default project_directory to current dir in `mkdocs new` by Gdhanush-13 · Pull Request #4090 · mkdocs/mkdocs · GitHub
Skip to content

feat: default project_directory to current dir in mkdocs new#4090

Open
Gdhanush-13 wants to merge 2 commits into
mkdocs:masterfrom
Gdhanush-13:fix/default-project-directory-for-new-command
Open

feat: default project_directory to current dir in mkdocs new#4090
Gdhanush-13 wants to merge 2 commits into
mkdocs:masterfrom
Gdhanush-13:fix/default-project-directory-for-new-command

Conversation

@Gdhanush-13

Copy link
Copy Markdown

Summary

When running mkdocs new without specifying a project directory, the command currently raises an error because project_directory is a required argument. This PR makes the argument optional by defaulting to '.' (the current working directory), so mkdocs new behaves identically to mkdocs new ..

This is a small quality-of-life improvement that reduces friction for users who want to initialize a project in their current directory.

Changes

  • mkdocs/__main__.py: Added default='.' to the project_directory click argument.
  • mkdocs/tests/cli_tests.py: Added test_new_default to verify the CLI defaults to '.' when no argument is provided.
  • mkdocs/tests/new_tests.py: Added test_new_current_dir to verify new('.') correctly creates mkdocs.yml and docs/index.md in the current directory.

Motivation

Closes #1988

As noted in the issue, running mkdocs new without a path should default to '.' rather than requiring the user to explicitly type mkdocs new .. This matches the behavior of similar CLI tools (e.g., git init, npm init) that default to the current directory.

When running mkdocs new without specifying a project directory,
default to the current directory (.) instead of raising an error.
This makes mkdocs new behave identically to mkdocs new .,
reducing friction for users who want to initialize a project in
their current working directory.

Fixes mkdocs#1988
Signed-off-by: Gdhanush_13 <dhanushdhanu1300@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Use current directory as default when running "mkdocs new" with no path

1 participant