56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
"""Main CLI"""
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
CPP_MAIN = """#include <iostream>
|
|
#include "functions.h"
|
|
using namespace std;
|
|
|
|
int main() {
|
|
return 0;
|
|
}
|
|
"""
|
|
|
|
CPP_FUNCTIONS = """#include "functions.h"
|
|
"""
|
|
|
|
def build_cpp_workspace(name: str) -> None:
|
|
"""Create a basic C++ workspace with main.cpp, functions.cpp, and functions.h."""
|
|
exercise_path = Path(name.replace(" ", "_")).resolve()
|
|
exercise_path.mkdir(exist_ok=True)
|
|
|
|
files = {
|
|
"main.cpp": CPP_MAIN,
|
|
"functions.cpp": CPP_FUNCTIONS,
|
|
"functions.h": "",
|
|
}
|
|
|
|
for filename, content in files.items():
|
|
file_path = exercise_path / filename
|
|
if not file_path.exists():
|
|
file_path.write_text(content, encoding="utf-8")
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
"""Parse CLI arguments."""
|
|
parser = argparse.ArgumentParser(description="Build language-specific exercise workspace.")
|
|
parser.add_argument("-n", "--name", required=True, help="Exercise name")
|
|
parser.add_argument("-l", "--language", default="cpp", help="Exercise language")
|
|
return parser.parse_args()
|
|
|
|
def main() -> None:
|
|
args = parse_args()
|
|
builders = {
|
|
"cpp": build_cpp_workspace,
|
|
# add other languages later
|
|
}
|
|
|
|
builder = builders.get(args.language)
|
|
if builder:
|
|
builder(args.name)
|
|
else:
|
|
raise ValueError(f"Unsupported language: {args.language}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|