|
37 | 37 |
|
38 | 38 |
|
39 | 39 | def get_network_file(args: Namespace) -> NetworkFile:
|
40 |
| - network_dir: str = os.path.abspath(args.network_dir) |
41 |
| - |
42 |
| - if not os.path.exists(network_dir): |
43 |
| - raise ValueError("f{network_dir} does not exist") |
44 |
| - |
45 |
| - classic_path = os.path.join(network_dir, "nixops.nix") |
46 |
| - flake_path = os.path.join(network_dir, "flake.nix") |
47 |
| - |
48 |
| - classic_exists: bool = os.path.exists(classic_path) |
| 40 | + network_path: str = "" |
| 41 | + flake_path: str = "" |
| 42 | + |
| 43 | + if args.network_path is not None: |
| 44 | + network_path = os.path.abspath(args.network_path) |
| 45 | + if os.path.isdir(network_path): |
| 46 | + network_path = os.path.join(network_path, "nixops.nix") |
| 47 | + if not os.path.exists(network_path): |
| 48 | + raise ValueError(f"{network_path} does not exist") |
| 49 | + return NetworkFile(network=network_path, is_flake=False) |
| 50 | + |
| 51 | + if args.flake_path is not None: |
| 52 | + flake_path = os.path.abspath(args.flake_path) |
| 53 | + if os.path.isdir(flake_path): |
| 54 | + flake_path = os.path.join(flake_path, "flake.nix") |
| 55 | + if not os.path.exists(flake_path): |
| 56 | + raise ValueError(f"{flake_path} does not exist") |
| 57 | + return NetworkFile(network=flake_path, is_flake=True) |
| 58 | + |
| 59 | + network_path = os.path.join(os.getcwd(), "nixops.nix") |
| 60 | + flake_path = os.path.join(os.getcwd(), "flake.nix") |
| 61 | + |
| 62 | + network_exists: bool = os.path.exists(network_path) |
49 | 63 | flake_exists: bool = os.path.exists(flake_path)
|
50 | 64 |
|
51 |
| - if all((flake_exists, classic_exists)): |
52 |
| - raise ValueError("Both flake.nix and nixops.nix cannot coexist") |
53 |
| - |
54 |
| - if classic_exists: |
55 |
| - return NetworkFile(network=classic_path, is_flake=False) |
| 65 | + if all((flake_exists, network_exists)): |
| 66 | + raise ValueError("Both flake.nix and nixops.nix found in current directory") |
56 | 67 |
|
57 |
| - if flake_exists: |
58 |
| - return NetworkFile(network=network_dir, is_flake=True) |
| 68 | + if not network_exists and not flake_exists: |
| 69 | + raise ValueError("Neither flake.nix nor nixops.nix exists in current directory") |
59 | 70 |
|
60 |
| - raise ValueError(f"Neither flake.nix nor nixops.nix exists in {network_dir}") |
| 71 | + if network_exists: |
| 72 | + return NetworkFile(network=network_path, is_flake=False) |
| 73 | + else: |
| 74 | + return NetworkFile(network=network_path, is_flake=True) |
61 | 75 |
|
62 | 76 |
|
63 | 77 | def set_common_depl(depl: nixops.deployment.Deployment, args: Namespace) -> None:
|
@@ -1154,12 +1168,20 @@ def add_subparser(
|
1154 | 1168 | subparsers: _SubParsersAction, name: str, help: str
|
1155 | 1169 | ) -> ArgumentParser:
|
1156 | 1170 | subparser = subparsers.add_parser(name, help=help)
|
1157 |
| - subparser.add_argument( |
| 1171 | + network = subparser.add_mutually_exclusive_group() |
| 1172 | + network.add_argument( |
1158 | 1173 | "--network",
|
1159 |
| - dest="network_dir", |
| 1174 | + "-n", |
| 1175 | + dest="network_path", |
| 1176 | + metavar="FILE", |
| 1177 | + help="path to network file or a directory containing nixops.nix", |
| 1178 | + ) |
| 1179 | + network.add_argument( |
| 1180 | + "--flake", |
| 1181 | + "-f", |
| 1182 | + dest="flake_path", |
1160 | 1183 | metavar="FILE",
|
1161 |
| - default=os.getcwd(), |
1162 |
| - help="path to a directory containing either nixops.nix or flake.nix", |
| 1184 | + help="path to flake or a directory containing flake.nix", |
1163 | 1185 | )
|
1164 | 1186 | subparser.add_argument(
|
1165 | 1187 | "--deployment",
|
|
0 commit comments