mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 09:38:29 +00:00
Добавить начальную структуру проекта с основными файлами и конфигурацией
This commit is contained in:
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
0
src/dcr/__init__.py
Normal file
0
src/dcr/__init__.py
Normal file
13
src/dcr/cli/__init__.py
Normal file
13
src/dcr/cli/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from .help import help
|
||||
from .init import init
|
||||
from .new import new
|
||||
from .run import run
|
||||
from .build import build
|
||||
|
||||
__all__ = [
|
||||
"help",
|
||||
"init",
|
||||
"new",
|
||||
"run",
|
||||
"build",
|
||||
]
|
||||
34
src/dcr/cli/build.py
Normal file
34
src/dcr/cli/build.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import subprocess
|
||||
from dcr.config import flags
|
||||
|
||||
|
||||
def check_dir(dir: str | None = None) -> list[str]:
|
||||
if dir in (None, ".", "./"):
|
||||
return os.listdir(os.getcwd())
|
||||
else:
|
||||
return os.listdir(os.getcwd() + "/" + dir)
|
||||
|
||||
|
||||
def build(args: list[str] | str) -> int:
|
||||
if "dcr.toml" not in check_dir():
|
||||
print("error: Not font dcr.toml")
|
||||
return 1
|
||||
if "target" not in check_dir():
|
||||
os.mkdir("./target")
|
||||
|
||||
if len(args) == 1 and args[0] in flags:
|
||||
profile: str = args[0][2:]
|
||||
else:
|
||||
print("error: Unkown flags")
|
||||
return 1
|
||||
if len(args) == 0:
|
||||
profile: str = "debug"
|
||||
|
||||
if profile not in check_dir("target"):
|
||||
os.mkdir(f"./target/{profile}")
|
||||
if "main.c" in check_dir("src"):
|
||||
print(f"Run build project as profiles {profile}")
|
||||
subprocess.run(["gcc", "./src/main.c", "-o", f"./target/{profile}/main"])
|
||||
print("Build complite")
|
||||
return 0
|
||||
3
src/dcr/cli/help.py
Normal file
3
src/dcr/cli/help.py
Normal file
@@ -0,0 +1,3 @@
|
||||
def help() -> int:
|
||||
print("Help")
|
||||
return 0
|
||||
32
src/dcr/cli/init.py
Normal file
32
src/dcr/cli/init.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import os
|
||||
|
||||
|
||||
def init(args) -> int:
|
||||
items = os.listdir(os.getcwd())
|
||||
project_name = os.path.basename(os.getcwd())
|
||||
|
||||
if items:
|
||||
print("ERROR: directory is not empty")
|
||||
return 1
|
||||
|
||||
os.mkdir("src")
|
||||
|
||||
with open("./src/main.c", "w") as file:
|
||||
file.write(
|
||||
"#include <stdio.h>\n\n"
|
||||
"int main(void) {\n"
|
||||
' printf("Hello World!\\n");\n'
|
||||
" return 0;\n"
|
||||
"}\n"
|
||||
)
|
||||
|
||||
with open("./dcr.toml", "w") as file:
|
||||
file.write(
|
||||
"[package]\n"
|
||||
f'name = "{project_name}"\n'
|
||||
'version = "0.1.0"\n'
|
||||
'edition = "2026"\n\n'
|
||||
"[dependencies]\n"
|
||||
)
|
||||
|
||||
return 0
|
||||
34
src/dcr/cli/new.py
Normal file
34
src/dcr/cli/new.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
|
||||
|
||||
def new(args: list[str]) -> int:
|
||||
items: list[str] = os.listdir(os.getcwd())
|
||||
if len(args) == 0 or len(args) > 1:
|
||||
print("ERROR")
|
||||
return 1
|
||||
project_name: str = args[0]
|
||||
if project_name in items:
|
||||
print("ERROR")
|
||||
return 1
|
||||
|
||||
os.makedirs(f"./{project_name}/src")
|
||||
|
||||
with open(f"./{project_name}/src/main.c", "w") as file:
|
||||
file.write(
|
||||
"#include <stdio.h>\n\n"
|
||||
"int main(void) {\n"
|
||||
' printf("Hello World!\\n");\n'
|
||||
" return 0;\n"
|
||||
"}\n"
|
||||
)
|
||||
|
||||
with open(f"./{project_name}/dcr.toml", "w") as file:
|
||||
file.write(
|
||||
"[package]\n"
|
||||
f'name = "{project_name}"\n'
|
||||
'version = "0.1.0"\n'
|
||||
'edition = "2026"\n\n'
|
||||
"[dependencies]\n"
|
||||
)
|
||||
|
||||
return 0
|
||||
30
src/dcr/cli/run.py
Normal file
30
src/dcr/cli/run.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from dcr.config import flags
|
||||
from .build import build
|
||||
|
||||
|
||||
def check_dir(dir: str | None = None) -> list[str]:
|
||||
if dir in (None, ".", "./"):
|
||||
return os.listdir(os.getcwd())
|
||||
else:
|
||||
return os.listdir(os.getcwd() + "/" + dir)
|
||||
|
||||
|
||||
def run(args: list[str]) -> int:
|
||||
if "dcr.toml" not in os.listdir(os.getcwd()):
|
||||
print("error: Not fond dcr.toml")
|
||||
return 1
|
||||
|
||||
if len(args) == 0:
|
||||
profile: str = "debug"
|
||||
elif len(args) == 1 and args[0] in flags:
|
||||
profile = args[0][2:]
|
||||
else:
|
||||
print("error: Unkown flags")
|
||||
return 1
|
||||
|
||||
build(args)
|
||||
print("Run project")
|
||||
return subprocess.run([f"./target/{profile}/main"]).returncode
|
||||
1
src/dcr/config.py
Normal file
1
src/dcr/config.py
Normal file
@@ -0,0 +1 @@
|
||||
flags: list[str] = ["--release", "--debug"]
|
||||
25
src/dcr/main.py
Normal file
25
src/dcr/main.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import dcr.cli as cli
|
||||
import sys
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if len(sys.argv) < 2 or sys.argv[1] == "--help":
|
||||
cli.help()
|
||||
return 0
|
||||
|
||||
cmd: str = sys.argv[1]
|
||||
args: str | list[str] = sys.argv[2:]
|
||||
|
||||
match cmd:
|
||||
case "new":
|
||||
cli.new(args)
|
||||
case "init":
|
||||
cli.init(args)
|
||||
case "build":
|
||||
cli.build(args)
|
||||
case "run":
|
||||
cli.run(args)
|
||||
case _:
|
||||
print("Unknown command")
|
||||
|
||||
return 0
|
||||
0
src/dcr/utils/__init__.py
Normal file
0
src/dcr/utils/__init__.py
Normal file
0
src/test/__init__.py
Normal file
0
src/test/__init__.py
Normal file
Reference in New Issue
Block a user