Notes, improve args, some UX
This commit is contained in:
@@ -27,7 +27,7 @@ print(
|
||||
)
|
||||
|
||||
if args.cmd == "commit":
|
||||
commit.commit(args.dry_run, args.force, args.no_apply, args.no_commit)
|
||||
commit.commit(args.dry_run, args.force, args.no_commit)
|
||||
elif args.cmd == "config":
|
||||
config.config()
|
||||
elif args.cmd == "init":
|
||||
|
||||
12
cli/args.py
12
cli/args.py
@@ -5,10 +5,10 @@ import argcomplete
|
||||
def add_cli_args():
|
||||
ap = argparse.ArgumentParser(
|
||||
"archmgr",
|
||||
description="A nixos-like declarative config and package manager for Arch Linux (or any other cdistro, with some tweaks)",
|
||||
description="A nixos-like declarative config and package manager for Arch Linux (or any other distro, with some tweaks)",
|
||||
usage="archmgr [command] [options]",
|
||||
)
|
||||
ap.add_argument("--version", "-v", action="version", version="%(prog)s V0.0.1")
|
||||
ap.add_argument("-v", "--version", action="version", version="%(prog)s V0.0.1")
|
||||
sp = ap.add_subparsers(
|
||||
title="commands",
|
||||
metavar="Use 'archmgr [command] --help' to see help for each command",
|
||||
@@ -21,13 +21,7 @@ def add_cli_args():
|
||||
commit = sp.add_parser(
|
||||
"commit", help="apply pending changes and commit to git repo"
|
||||
)
|
||||
commit.add_argument("--force", "-f", help="force apply", action="store_true")
|
||||
commit.add_argument(
|
||||
"--no-apply", "-n", help="do not apply to local system", action="store_true"
|
||||
)
|
||||
commit.add_argument(
|
||||
"--no-commit", "-N", help="do not commit changes to repo", action="store_true"
|
||||
)
|
||||
commit.add_argument("-f", "--force", help="force apply", action="store_true")
|
||||
commit.add_argument(
|
||||
"--no-render", "-r", help="do not re-render renderables", action="store_true"
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
8
notes.md
Normal file
8
notes.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Concept for tracking changes
|
||||
- Create new commit (if possible)
|
||||
- If force is unset: Diff system's files against current state by copying them into the current state branch
|
||||
- Then, diff the package state against the state branch by dumping it
|
||||
- Else, or if no diff, continue
|
||||
- Copy normal config files into correct directories
|
||||
- Render and copy renderables
|
||||
- Retrieve explicitly installed packages and remove those that are not present in goal and install those that are not present in current state
|
||||
Reference in New Issue
Block a user