Notes, improve args, some UX
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
def commit(
|
||||
dry_run: bool = False,
|
||||
force: bool = False,
|
||||
no_apply: bool = False,
|
||||
no_commit: bool = False,
|
||||
):
|
||||
from commands.util.choice import confirm_overwrite
|
||||
|
||||
|
||||
def commit(dry_run: bool = False, force: bool = False):
|
||||
if dry_run:
|
||||
pass
|
||||
print("Commit, force:", force)
|
||||
print(confirm_overwrite())
|
||||
|
||||
@@ -1,2 +1,14 @@
|
||||
import os
|
||||
import commands.util.git as git
|
||||
|
||||
|
||||
def init(force: bool = False):
|
||||
print("Init")
|
||||
dir = os.getcwd()
|
||||
if force:
|
||||
[os.remove(dir) for dir in os.listdir(dir)]
|
||||
git.init(dir)
|
||||
os.mkdir(dir + "/config")
|
||||
os.mkdir(dir + "/etc")
|
||||
with open(dir + "/config.yaml") as file:
|
||||
file.write("")
|
||||
print("Initialized a new archmgr repository")
|
||||
|
||||
30
commands/util/choice.py
Normal file
30
commands/util/choice.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def choice(default: str, options: str, msg: str) -> str:
|
||||
default = default.lower()
|
||||
formatted_options = "".join(
|
||||
[(opt + "/" if opt != default else default.upper() + "/") for opt in options]
|
||||
)[:-1]
|
||||
choice = input(msg + " [" + formatted_options + "] ")
|
||||
if choice == "":
|
||||
return default
|
||||
else:
|
||||
return choice.lower()
|
||||
|
||||
|
||||
def confirm(is_true_default: bool, msg: Optional[str] = ""):
|
||||
return (
|
||||
choice(
|
||||
"y" if is_true_default else "n",
|
||||
"yn",
|
||||
(msg if msg != "" and msg != None else "Do you really want to continue?"),
|
||||
)
|
||||
== "y"
|
||||
)
|
||||
|
||||
|
||||
def confirm_overwrite(msg: Optional[str] = ""):
|
||||
return confirm(
|
||||
False, (msg if msg != "" else "Do you really want to overwrite your changes?")
|
||||
)
|
||||
13
commands/util/diff.py
Normal file
13
commands/util/diff.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from typing import List
|
||||
|
||||
|
||||
def compute_diff(paths: List[str]):
|
||||
pass
|
||||
|
||||
|
||||
def file_diff(path: str):
|
||||
pass
|
||||
|
||||
|
||||
def pkg_diff():
|
||||
pass
|
||||
@@ -0,0 +1,5 @@
|
||||
import subprocess
|
||||
|
||||
|
||||
def init(dirname: str):
|
||||
subprocess.call("git init", cwd=dirname)
|
||||
|
||||
Reference in New Issue
Block a user