Skip to content

Commit 550e962

Browse files
committed
--manifest-path Cargo.toml is not equivalent to not passing the argument if it's a virtual workspace
1 parent 0382986 commit 550e962

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

language_formatters_pre_commit_hooks/pretty_format_rust.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ def pretty_format_rust(argv: typing.Optional[typing.List[str]] = None) -> int:
1818
)
1919
parser.add_argument(
2020
"--manifest-path",
21-
default="Cargo.toml",
2221
dest="manifest_path",
23-
help="The cargo manifest file location (Default: %(default)s)",
22+
help="The cargo manifest file location.",
2423
)
2524

2625
parser.add_argument("filenames", nargs="*", help="Filenames to fix")
2726
args = parser.parse_args(argv)
2827

2928
# Check
30-
status_code, output, _ = run_command("cargo", "fmt", "--manifest-path", args.manifest_path, "--", "--check", *args.filenames)
29+
manifest_slug = [] if args.manifest_path is None else ["--manifest-path", args.manifest_path]
30+
status_code, output, _ = run_command(*(["cargo", "fmt"] + manifest_slug + ["--", "--check", *args.filenames]))
3131
not_well_formatted_files = sorted(line.split()[2] for line in output.splitlines() if line.startswith("Diff in "))
3232
if not_well_formatted_files:
3333
print(
@@ -37,7 +37,7 @@ def pretty_format_rust(argv: typing.Optional[typing.List[str]] = None) -> int:
3737
),
3838
)
3939
if args.autofix:
40-
run_command("cargo", "fmt", "--manifest-path", args.manifest_path, "--", *not_well_formatted_files)
40+
run_command(*(["cargo", "fmt"] + manifest_slug + ["--", *not_well_formatted_files]))
4141
elif status_code != 0:
4242
print("Detected not valid rust source files among {}".format("\n".join(sorted(args.filenames))))
4343

0 commit comments

Comments
 (0)