Provide a better error message for 'nvd list' on non-NixOS systems (fixes #21).

This commit is contained in:
Bryan Gardiner 2024-10-27 13:04:01 -07:00
parent e58c00f322
commit 734da23492
No known key found for this signature in database
GPG key ID: 53EFBCA063E6183C
3 changed files with 15 additions and 2 deletions

View file

@ -2,6 +2,9 @@
## 0.2.5 (unreleased) ## 0.2.5 (unreleased)
- Improve the error message when calling `nvd list`, and `/run/current-system`
doesn't exist (issue #21).
## 0.2.4 (2024-09-29) ## 0.2.4 (2024-09-29)
- Added an `nvd history` command for diffing successive generations of a - Added an `nvd history` command for diffing successive generations of a

12
src/nvd
View file

@ -61,6 +61,8 @@ NIX_BIN_DIR = None
USE_NIX_COMMAND_FEATURE = False # Whether to explicitly enable the nix-command feature. USE_NIX_COMMAND_FEATURE = False # Whether to explicitly enable the nix-command feature.
USE_COLOUR = False USE_COLOUR = False
LIST_DEFAULT_ROOT = "/run/current-system"
SGR_RESET = 0 SGR_RESET = 0
SGR_BOLD = 1 SGR_BOLD = 1
SGR_FG = 30 SGR_FG = 30
@ -937,6 +939,12 @@ def run_list(
if not path.exists(): if not path.exists():
sys.stderr.write(f"Path does not exist: {path}\n") sys.stderr.write(f"Path does not exist: {path}\n")
if str(path) == LIST_DEFAULT_ROOT:
sys.stderr.write(
"Perhaps this isn't a NixOS system?\n"
"Pass -r/--root to change the target of 'nvd list'.\n"
"For example: nvd list -r ~/.nix-profile\n"
)
sys.exit(1) sys.exit(1)
path = path.resolve() path = path.resolve()
@ -1233,8 +1241,8 @@ def parse_args():
add_sort_arg(list_parser) add_sort_arg(list_parser)
list_parser.add_argument( list_parser.add_argument(
"-r", "--root", "-r", "--root",
default="/run/current-system", default=LIST_DEFAULT_ROOT,
help="The The Nix store path to work with.") help=f"The Nix store path to work with (default {LIST_DEFAULT_ROOT}).")
list_parser.add_argument( list_parser.add_argument(
nargs="*", nargs="*",
default=[], default=[],

View file

@ -216,6 +216,8 @@ package are present.
For the For the
.B list .B list
command, this is the root store path to use, or a link to the store path to use. command, this is the root store path to use, or a link to the store path to use.
The default is
.B /run/current-system.
.TP .TP
<name-pattern> <name-pattern>
For the For the