clan-cli: remove useless run_no_stdout function
This commit is contained in:
@@ -403,23 +403,3 @@ def run(
|
|||||||
raise ClanCmdError(cmd_out)
|
raise ClanCmdError(cmd_out)
|
||||||
|
|
||||||
return cmd_out
|
return cmd_out
|
||||||
|
|
||||||
|
|
||||||
def run_no_stdout(
|
|
||||||
cmd: list[str],
|
|
||||||
opts: RunOpts | None = None,
|
|
||||||
) -> CmdOut:
|
|
||||||
"""
|
|
||||||
Like run, but automatically suppresses all output, if not in DEBUG log level.
|
|
||||||
If in DEBUG log level the stdout of commands will be shown.
|
|
||||||
"""
|
|
||||||
if opts is None:
|
|
||||||
opts = RunOpts()
|
|
||||||
|
|
||||||
if cmdlog.isEnabledFor(logging.DEBUG):
|
|
||||||
opts.log = opts.log if opts.log.value > Log.STDERR.value else Log.STDERR
|
|
||||||
|
|
||||||
return run(
|
|
||||||
cmd,
|
|
||||||
opts,
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ from typing import Any
|
|||||||
|
|
||||||
from clan_lib.api import API, dataclass_to_dict, from_dict
|
from clan_lib.api import API, dataclass_to_dict, from_dict
|
||||||
|
|
||||||
from clan_cli.cmd import run_no_stdout
|
from clan_cli.cmd import run
|
||||||
from clan_cli.errors import ClanCmdError, ClanError
|
from clan_cli.errors import ClanCmdError, ClanError
|
||||||
from clan_cli.flake import Flake
|
from clan_cli.flake import Flake
|
||||||
from clan_cli.git import commit_file
|
from clan_cli.git import commit_file
|
||||||
@@ -80,7 +80,7 @@ def load_inventory_eval(flake_dir: Flake) -> Inventory:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
proc = run_no_stdout(cmd)
|
proc = run(cmd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = proc.stdout.strip()
|
res = proc.stdout.strip()
|
||||||
@@ -380,7 +380,7 @@ def get_inventory_current_priority(flake: Flake) -> dict:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
proc = run_no_stdout(cmd)
|
proc = run(cmd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = proc.stdout.strip()
|
res = proc.stdout.strip()
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from functools import cached_property
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from clan_cli.cmd import Log, RunOpts, run_no_stdout
|
from clan_cli.cmd import Log, RunOpts, run
|
||||||
from clan_cli.errors import ClanCmdError, ClanError
|
from clan_cli.errors import ClanCmdError, ClanError
|
||||||
from clan_cli.facts import public_modules as facts_public_modules
|
from clan_cli.facts import public_modules as facts_public_modules
|
||||||
from clan_cli.facts import secret_modules as facts_secret_modules
|
from clan_cli.facts import secret_modules as facts_secret_modules
|
||||||
@@ -188,7 +188,7 @@ class Machine:
|
|||||||
# however there is a soon to be merged PR that requires deployment
|
# however there is a soon to be merged PR that requires deployment
|
||||||
# as root to match NixOS: https://github.com/nix-darwin/nix-darwin/pull/1341
|
# as root to match NixOS: https://github.com/nix-darwin/nix-darwin/pull/1341
|
||||||
return json.loads(
|
return json.loads(
|
||||||
run_no_stdout(
|
run(
|
||||||
nix_eval(
|
nix_eval(
|
||||||
[
|
[
|
||||||
f"{self.flake}#darwinConfigurations.{self.name}.options.system",
|
f"{self.flake}#darwinConfigurations.{self.name}.options.system",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from clan_cli.cmd import RunOpts, run_no_stdout
|
from clan_cli.cmd import RunOpts, run
|
||||||
from clan_cli.completions import (
|
from clan_cli.completions import (
|
||||||
add_dynamic_completer,
|
add_dynamic_completer,
|
||||||
complete_machines,
|
complete_machines,
|
||||||
@@ -32,7 +32,7 @@ def list_state_folders(machine: Machine, service: None | str = None) -> None:
|
|||||||
res = "{}"
|
res = "{}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
proc = run_no_stdout(cmd, opts=RunOpts(prefix=machine.name))
|
proc = run(cmd, RunOpts(prefix=machine.name))
|
||||||
res = proc.stdout.strip()
|
res = proc.stdout.strip()
|
||||||
except ClanCmdError as e:
|
except ClanCmdError as e:
|
||||||
msg = "Clan might not have meta attributes"
|
msg = "Clan might not have meta attributes"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import json
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from clan_cli.cmd import run_no_stdout
|
from clan_cli.cmd import run
|
||||||
from clan_cli.errors import ClanError
|
from clan_cli.errors import ClanError
|
||||||
from clan_cli.nix import nix_eval
|
from clan_cli.nix import nix_eval
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ def list_tagged_machines(flake_url: str | Path) -> dict[str, Any]:
|
|||||||
"--json",
|
"--json",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
proc = run_no_stdout(cmd)
|
proc = run(cmd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = proc.stdout.strip()
|
res = proc.stdout.strip()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from clan_cli.inventory import (
|
|||||||
set_inventory,
|
set_inventory,
|
||||||
)
|
)
|
||||||
from clan_cli.machines.create import CreateOptions, create_machine
|
from clan_cli.machines.create import CreateOptions, create_machine
|
||||||
from clan_cli.nix import nix_eval, run_no_stdout
|
from clan_cli.nix import nix_eval, run
|
||||||
from clan_cli.tests.fixtures_flakes import FlakeForTest
|
from clan_cli.tests.fixtures_flakes import FlakeForTest
|
||||||
from clan_lib.api.modules import list_modules
|
from clan_lib.api.modules import list_modules
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ def test_add_module_to_inventory(
|
|||||||
"--json",
|
"--json",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
proc = run_no_stdout(cmd)
|
proc = run(cmd)
|
||||||
res = json.loads(proc.stdout.strip())
|
res = json.loads(proc.stdout.strip())
|
||||||
|
|
||||||
assert res["machine1"]["authorizedKeys"] == [ssh_key.decode()]
|
assert res["machine1"]["authorizedKeys"] == [ssh_key.decode()]
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ from dataclasses import dataclass, field
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Literal
|
from typing import Any, Literal
|
||||||
|
|
||||||
from clan_cli.cmd import RunOpts
|
from clan_cli.cmd import RunOpts, run
|
||||||
from clan_cli.errors import ClanError
|
from clan_cli.errors import ClanError
|
||||||
from clan_cli.nix import nix_shell, run_no_stdout
|
from clan_cli.flake import Flake
|
||||||
|
from clan_cli.nix import nix_shell
|
||||||
|
|
||||||
from . import API
|
from . import API
|
||||||
|
|
||||||
@@ -52,8 +53,8 @@ class Directory:
|
|||||||
|
|
||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def get_directory(current_path: str) -> Directory:
|
def get_directory(flake: Flake) -> Directory:
|
||||||
curr_dir = Path(current_path)
|
curr_dir = flake.path
|
||||||
directory = Directory(path=str(curr_dir))
|
directory = Directory(path=str(curr_dir))
|
||||||
|
|
||||||
if not curr_dir.is_dir():
|
if not curr_dir.is_dir():
|
||||||
@@ -135,7 +136,7 @@ def show_block_devices() -> Blockdevices:
|
|||||||
"PATH,NAME,RM,SIZE,RO,MOUNTPOINTS,TYPE,ID-LINK",
|
"PATH,NAME,RM,SIZE,RO,MOUNTPOINTS,TYPE,ID-LINK",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
proc = run_no_stdout(cmd, RunOpts(needs_user_terminal=True))
|
proc = run(cmd, RunOpts(needs_user_terminal=True))
|
||||||
res = proc.stdout.strip()
|
res = proc.stdout.strip()
|
||||||
|
|
||||||
blk_info: dict[str, Any] = json.loads(res)
|
blk_info: dict[str, Any] = json.loads(res)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import argparse
|
|||||||
import re
|
import re
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from clan_cli.cmd import run_no_stdout
|
from clan_cli.cmd import run
|
||||||
from clan_cli.nix import nix_shell
|
from clan_cli.nix import nix_shell
|
||||||
|
|
||||||
from . import API
|
from . import API
|
||||||
@@ -100,7 +100,7 @@ def show_mdns() -> DNSInfo:
|
|||||||
"--terminate",
|
"--terminate",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
proc = run_no_stdout(cmd)
|
proc = run(cmd)
|
||||||
data = parse_avahi_output(proc.stdout)
|
data = parse_avahi_output(proc.stdout)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|||||||
Reference in New Issue
Block a user