cli-prep #53
@ -3,11 +3,12 @@ import argparse
|
||||
import sys
|
||||
|
||||
from . import admin, ssh
|
||||
from .errors import ClanError
|
||||
|
||||
has_argcomplete = True
|
||||
try:
|
||||
import argcomplete
|
||||
except ImportError: # pragma: no cover
|
||||
except ImportError:
|
||||
has_argcomplete = False
|
||||
|
||||
|
||||
@ -30,8 +31,12 @@ def main() -> None:
|
||||
|
||||
args = parser.parse_args()
|
||||
if hasattr(args, "func"):
|
||||
args.func(args) # pragma: no cover
|
||||
try:
|
||||
args.func(args)
|
||||
except ClanError as e:
|
||||
print(f"{sys.argv[0]}: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -18,7 +18,7 @@ def create(args: argparse.Namespace) -> None:
|
||||
)
|
||||
|
||||
|
||||
def edit(args: argparse.Namespace) -> None: # pragma: no cover
|
||||
def edit(args: argparse.Namespace) -> None:
|
||||
# TODO add some cli options to change certain options without relying on a text editor
|
||||
clan_flake = f"{args.folder}/flake.nix"
|
||||
if os.path.isfile(clan_flake):
|
||||
@ -34,7 +34,7 @@ def edit(args: argparse.Namespace) -> None: # pragma: no cover
|
||||
)
|
||||
|
||||
|
||||
def rebuild(args: argparse.Namespace) -> None: # pragma: no cover
|
||||
def rebuild(args: argparse.Namespace) -> None:
|
||||
# TODO get clients from zerotier cli?
|
||||
if args.host:
|
||||
print(f"would redeploy {args.host} from clan {args.folder}")
|
||||
@ -42,7 +42,7 @@ def rebuild(args: argparse.Namespace) -> None: # pragma: no cover
|
||||
print(f"would redeploy all hosts from clan {args.folder}")
|
||||
|
||||
|
||||
def destroy(args: argparse.Namespace) -> None: # pragma: no cover
|
||||
def destroy(args: argparse.Namespace) -> None:
|
||||
# TODO get clan folder & hosts from somwhere (maybe ~/.config/clan/$name /)
|
||||
# send some kind of kill signal, then remove the folder
|
||||
if args.yes:
|
||||
@ -53,14 +53,14 @@ def destroy(args: argparse.Namespace) -> None: # pragma: no cover
|
||||
)
|
||||
|
||||
|
||||
def backup(args: argparse.Namespace) -> None: # pragma: no cover
|
||||
def backup(args: argparse.Namespace) -> None:
|
||||
if args.host:
|
||||
print(f"would backup {args.host} from clan {args.folder}")
|
||||
else:
|
||||
print(f"would backup all hosts from clan {args.folder}")
|
||||
|
||||
|
||||
def git(args: argparse.Namespace) -> None: # pragma: no cover
|
||||
def git(args: argparse.Namespace) -> None:
|
||||
subprocess.Popen(
|
||||
[
|
||||
"git",
|
||||
|
@ -53,7 +53,7 @@ def qrcode_scan(pictureFile: str) -> str:
|
||||
)
|
||||
|
||||
|
||||
def main(args: argparse.Namespace) -> None: # pragma: no cover
|
||||
def main(args: argparse.Namespace) -> None:
|
||||
if args.json:
|
||||
with open(args.json) as file:
|
||||
ssh_data = json.load(file)
|
||||
|
@ -62,7 +62,7 @@ class ZerotierController:
|
||||
resp = urllib.request.urlopen(req)
|
||||
return json.load(resp)
|
||||
|
||||
def status(self) -> dict[str, Any]: # pragma: no cover
|
||||
def status(self) -> dict[str, Any]:
|
||||
return self._http_request("/status")
|
||||
|
||||
def create_network(self, data: dict[str, Any] = {}) -> dict[str, Any]:
|
||||
@ -75,9 +75,7 @@ class ZerotierController:
|
||||
def get_network(self, id: str) -> dict[str, Any]:
|
||||
return self._http_request(f"/controller/network/{id}")
|
||||
|
||||
def update_network(
|
||||
self, id: str, new_config: dict[str, Any]
|
||||
) -> dict[str, Any]: # pragma: no cover
|
||||
def update_network(self, id: str, new_config: dict[str, Any]) -> dict[str, Any]:
|
||||
return self._http_request(
|
||||
f"/controller/network/{id}", method="POST", data=new_config
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user