Skip to content

Commit

Permalink
feat(args): add --pacman-path flag
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Sep 3, 2024
1 parent 49ff187 commit 770cf3d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ Print warning when using privilege escalation tool other than `sudo`.

##### PacmanPath (default: pacman)
Path to pacman executable.
Will be overriden by `--pacman-path` flag.

##### PreserveEnv (default: `PKGDEST,VISUAL,EDITOR,http_proxy,https_proxy,ftp_proxy,HTTP_PROXY,HTTPS_PROXY,FTP_PROXY,ALL_PROXY`)
Preserve environment variables of current user when running pikaur as root (comma-separated).
Expand Down
6 changes: 6 additions & 0 deletions pikaur/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ def get_pikaur_str_opts(action: str | None = None) -> ArgSchema:
PikaurConfig().misc.PreserveEnv.get_str(),
translate("preserve environment variables (comma-separated)"),
),
(
None, "pacman-path",
PikaurConfig().misc.PacmanPath.get_str(),
translate("override path to pacman executable"),
),
]
if not action:
for each_action in ALL_ACTIONS:
Expand Down Expand Up @@ -459,6 +464,7 @@ class PikaurArgs(Namespace):
makepkg_config: str | None
mflags: str | None
makepkg_path: str | None
pacman_path: str
quiet: bool
sysupgrade: int
devel: int
Expand Down
3 changes: 1 addition & 2 deletions pikaur/help_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
parse_args,
reconstruct_args,
)
from .config import PikaurConfig
from .i18n import PIKAUR_NAME, translate
from .pikaprint import print_stdout
from .spawn import spawn
Expand Down Expand Up @@ -41,7 +40,7 @@ def cli_print_help() -> None:
args = parse_args()

proc = spawn([
PikaurConfig().misc.PacmanPath.get_str(),
args.pacman_path,
*reconstruct_args(args, ignore_args=get_pikaur_long_opts()),
])
if not proc.stdout_text:
Expand Down
4 changes: 2 additions & 2 deletions pikaur/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def cli_pkgbuild() -> None:
def cli_print_version() -> None:
args = parse_args()
proc = spawn([
PikaurConfig().misc.PacmanPath.get_str(), "--version",
args.pacman_path, "--version",
])
pacman_version = proc.stdout_text.splitlines()[1].strip(" .-") if proc.stdout_text else "N/A"
print_version(
Expand Down Expand Up @@ -345,7 +345,7 @@ def cli_entry_point() -> None:
# Just bypass all the args to pacman
logger.debug("Pikaur operation not found for args: {}", sys.argv)
logger.debug(args)
pacman_args = [PikaurConfig().misc.PacmanPath.get_str(), *args.raw_without_pikaur_specific]
pacman_args = [args.pacman_path, *args.raw_without_pikaur_specific]
if require_sudo:
pacman_args = sudo(pacman_args)
sys.exit(
Expand Down
4 changes: 1 addition & 3 deletions pikaur/pacman.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from .alpm import PyAlpmWrapper
from .args import PACMAN_APPEND_OPTS, get_pacman_str_opts, parse_args, reconstruct_args
from .config import PikaurConfig
from .exceptions import DependencyError, PackagesNotFoundInRepoError
from .i18n import translate
from .lock import FancyLock
Expand Down Expand Up @@ -59,8 +58,7 @@ def get_pacman_command( # pylint: disable=too-many-branches
) -> list[str]:
ignore_args = ignore_args or []
args = parse_args()
pacman_path = PikaurConfig().misc.PacmanPath.get_str()
pacman_cmd = [pacman_path]
pacman_cmd = [args.pacman_path]
if color_enabled():
pacman_cmd += ["--color=always"]
else:
Expand Down
6 changes: 3 additions & 3 deletions pikaur/pkg_cache_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .args import parse_args, reconstruct_args
from .config import DECORATION, BuildCachePath, PackageCachePath, PikaurConfig
from .config import DECORATION, BuildCachePath, PackageCachePath
from .exceptions import SysExit
from .i18n import translate
from .logging_extras import create_logger
Expand Down Expand Up @@ -41,7 +41,7 @@ def clean_repo_cache() -> None:
if args.noconfirm:
returncode = pikspect(
sudo([
PikaurConfig().misc.PacmanPath.get_str(),
args.pacman_path,
*reconstruct_args(args, ignore_args=["noconfirm"]),
]),
extra_questions={YesNo.ANSWER_Y: [
Expand All @@ -61,7 +61,7 @@ def clean_repo_cache() -> None:
returncode = 255
else:
returncode = interactive_spawn(sudo([
PikaurConfig().misc.PacmanPath.get_str(),
args.pacman_path,
*reconstruct_args(args, ignore_args=["noconfirm"]),
])).returncode
raise SysExit(returncode)
Expand Down

0 comments on commit 770cf3d

Please sign in to comment.