mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 13:15:57 +08:00
Added a diagnose flag
Allowing the user to opt-in or out of diagnosing the file
This commit is contained in:
parent
cec022f330
commit
49305474ea
@ -72,7 +72,7 @@ def formatFile(file: Path, settings):
|
||||
config.write(f, space_around_delimiters=settings["format"].get("format-profile-space-around-delimiters", True))
|
||||
|
||||
|
||||
def main(files, setting_path, to_format, to_fix, report):
|
||||
def main(files, setting_path, to_format, to_fix, to_diagnose, report):
|
||||
if not setting_path:
|
||||
setting_path = Path(getcwd(), ".printer-linter")
|
||||
|
||||
@ -83,29 +83,30 @@ def main(files, setting_path, to_format, to_fix, report):
|
||||
with open(setting_path, "r") as f:
|
||||
settings = yaml.load(f, yaml.FullLoader)
|
||||
|
||||
full_body_check = {}
|
||||
for file in files:
|
||||
if file.is_dir():
|
||||
for fp in file.rglob("**/*"):
|
||||
full_body_check |= examineFile(fp, settings)
|
||||
else:
|
||||
full_body_check |= examineFile(file, settings)
|
||||
|
||||
results = yaml.dump(full_body_check, default_flow_style=False, indent=4, width=240)
|
||||
if report:
|
||||
report.write_text(results)
|
||||
else:
|
||||
print(results)
|
||||
|
||||
if to_fix:
|
||||
if to_fix or to_diagnose:
|
||||
full_body_check = {}
|
||||
for file in files:
|
||||
if file.is_dir():
|
||||
for fp in file.rglob("**/*"):
|
||||
if f"{file.as_posix()}" in full_body_check:
|
||||
fixFile(fp, settings, full_body_check)
|
||||
full_body_check |= examineFile(fp, settings)
|
||||
else:
|
||||
if f"{file.as_posix()}" in full_body_check:
|
||||
fixFile(file, settings, full_body_check)
|
||||
full_body_check |= examineFile(file, settings)
|
||||
|
||||
results = yaml.dump(full_body_check, default_flow_style=False, indent=4, width=240)
|
||||
if report:
|
||||
report.write_text(results)
|
||||
else:
|
||||
print(results)
|
||||
|
||||
if to_fix:
|
||||
for file in files:
|
||||
if file.is_dir():
|
||||
for fp in file.rglob("**/*"):
|
||||
if f"{file.as_posix()}" in full_body_check:
|
||||
fixFile(fp, settings, full_body_check)
|
||||
else:
|
||||
if f"{file.as_posix()}" in full_body_check:
|
||||
fixFile(file, settings, full_body_check)
|
||||
|
||||
if to_format:
|
||||
for file in files:
|
||||
@ -122,8 +123,9 @@ if __name__ == "__main__":
|
||||
parser.add_argument("--setting", required=False, type=Path, help="Path to the `.printer-linter` setting file")
|
||||
parser.add_argument("--report", required=False, type=Path, help="Path where the diagnostic report should be stored")
|
||||
parser.add_argument("--format", action="store_true", help="Format the files")
|
||||
parser.add_argument("--diagnose", action="store_true", help="Diagnose the files")
|
||||
parser.add_argument("--fix", action="store_true", help="Attempt to apply the suggested fixes on the files")
|
||||
parser.add_argument("Files", metavar="F", type=Path, nargs="+", help="Files or directories to format")
|
||||
|
||||
args = parser.parse_args()
|
||||
main(args.Files, args.setting, args.format, args.fix, args.report)
|
||||
main(args.Files, args.setting, args.format, args.fix, args.diagnose, args.report)
|
||||
|
Loading…
x
Reference in New Issue
Block a user