Skip to content

Instantly share code, notes, and snippets.

@gglin001
Created January 31, 2024 07:58
Show Gist options
  • Save gglin001/a53d8a1d700e21e94c9eef3e6cc98265 to your computer and use it in GitHub Desktop.
Save gglin001/a53d8a1d700e21e94c9eef3e6cc98265 to your computer and use it in GitHub Desktop.
cmake_split.py
import argparse
import os
parser = argparse.ArgumentParser()
parser.add_argument("raw", type=str, help="raw")
parser.add_argument("--inplace", "-i", action="store_false", help="inplace")
args = parser.parse_args()
# args = []
# cmd = "cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug ..."
# args.append(cmd)
# args = parser.parse_args(args)
print(args)
if not args.raw:
parser.print_help()
exit(0)
cmds: [str] = args.raw
is_path = False
if os.path.exists(args.raw):
is_path = True
cmds = open(args.raw, "r").readlines()
else:
cmds = [args.raw]
for cmd in cmds:
if not cmd.startswith("cmake"):
continue
elif len(cmd) < 10: # `cmake \`
continue
elif cmd.endswith(("\\", "\\ ")):
continue
cmd = cmd.replace("cmake ", "\ncmake \ \n ")
cmd = cmd.replace(" -D", " \ \n -D")
cmd = cmd.replace(" -S", " \ \n -S")
cmd = cmd.replace(" -B", " \ \n -B")
cmd = cmd.replace(" -G", " \ \n -G")
if is_path and args.inplace:
with open(args.raw, "a") as f:
print(cmd, file=f, flush=True)
else:
print(cmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment