diff --git a/nixops/__main__.py b/nixops/__main__.py index 593483195..bf495fcfa 100755 --- a/nixops/__main__.py +++ b/nixops/__main__.py @@ -528,14 +528,20 @@ ) subparser = add_subparser( - subparsers, "eval", help="eval the given file is nix code in the network expression" + subparsers, + "eval", + help="evaluate a Nix expression with the NixOps network as arguments", ) subparser.set_defaults(op=op_eval) -subparser.add_argument("code", metavar="CODE", help="code") +subparser.add_argument("file", metavar="FILE", help="file containing a Nix expression") subparser.add_argument( - "--json", action="store_true", help="print the option value in JSON format" + "--json", action="store_true", help="convert and print the return value as JSON" +) +subparser.add_argument( + "--strict", + action="store_true", + help="enable strict evaluation, (use with --json if value is more than a level deep)", ) -subparser.add_argument("--strict", action="store_true", help="enable strict evaluation") subparser = add_subparser( subparsers, diff --git a/nixops/deployment.py b/nixops/deployment.py index 7573f4b90..3e1a9fe87 100644 --- a/nixops/deployment.py +++ b/nixops/deployment.py @@ -503,7 +503,7 @@ def evaluate(self) -> None: ) self.definitions[name] = defn - def evaluate_code(self, code: str, json: bool = False, strict: bool = False) -> str: + def evaluate_code(self, file: str, json: bool = False, strict: bool = False) -> str: """Evaluate nix code in the deployment specification.""" exprs = self.nix_exprs @@ -524,7 +524,7 @@ def evaluate_code(self, code: str, json: bool = False, strict: bool = False) -> "false", "--arg", "evalFile", - code, + file, ] + (["--strict"] if strict else []) + (["--json"] if json else []), diff --git a/nixops/script_defs.py b/nixops/script_defs.py index faac0d3b7..f47049a08 100644 --- a/nixops/script_defs.py +++ b/nixops/script_defs.py @@ -897,7 +897,7 @@ def op_eval(args): with deployment(args) as depl: depl.evaluate() sys.stdout.write( - depl.evaluate_code(args.code, json=args.json, strict=args.strict) + depl.evaluate_code(args.file, json=args.json, strict=args.strict) )