Skip to content

Commit 38525ef

Browse files
committed
Refactor CLI into separate files
1 parent 8aef96b commit 38525ef

File tree

14 files changed

+149
-264
lines changed

14 files changed

+149
-264
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ devenv.local.nix
2222
# IntelliJ
2323
.idea/
2424
.fleet/
25+
26+
# Output from Karsk
27+
output/

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dev = [
2727
]
2828

2929
[project.scripts]
30-
deploy = "deploy.__main__:cli"
30+
deploy = "deploy.cli:cli"
3131

3232
[tool.pytest.ini_options]
3333
asyncio_mode = "auto"

src/deploy/__main__.py

Lines changed: 0 additions & 127 deletions
This file was deleted.

src/deploy/_check.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/deploy/check.py

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/deploy/cli.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import annotations
2+
3+
import click
4+
5+
from deploy.commands.build import subcommand_build
6+
from deploy.commands.sync import subcommand_sync
7+
from deploy.commands.test import subcommand_test
8+
9+
10+
@click.group()
11+
def cli() -> None:
12+
pass
13+
14+
15+
cli.add_command(subcommand_build)
16+
cli.add_command(subcommand_sync)
17+
cli.add_command(subcommand_test)
18+
19+
20+
if __name__ == "__main__":
21+
cli()
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
from tempfile import NamedTemporaryFile, TemporaryDirectory
1313
import shutil
1414

15-
from deploy.config import Config, GitConfig
15+
import click
16+
17+
from deploy.config import Config, GitConfig, load_config
1618
from deploy.package import Package
1719
from deploy.package_list import PackageList
1820
from deploy.utils import redirect_output
@@ -239,3 +241,31 @@ def _create_wrapper_script(
239241

240242
wrapper_script.write_text(script_content)
241243
wrapper_script.chmod(0o755)
244+
245+
246+
@click.command("build", help="Build Cirrus and dependencies")
247+
@click.argument(
248+
"config-file",
249+
type=Path,
250+
)
251+
@click.option(
252+
"--prefix",
253+
default="./output/prefix",
254+
type=Path,
255+
)
256+
@click.option(
257+
"--force",
258+
"-f",
259+
is_flag=True,
260+
default=False,
261+
help="Force adding a new environment even if one already exists (rollback)",
262+
)
263+
def subcommand_build(config_file: Path, prefix: Path, force: bool) -> None:
264+
config = load_config(config_file)
265+
builder = Build(
266+
config_file.parent,
267+
config,
268+
force=force,
269+
prefix=prefix,
270+
)
271+
builder.build()
Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import asyncio
99
from pathlib import Path
1010

11-
from deploy.config import Config, AreaConfig
11+
import click
12+
13+
from deploy.config import Config, AreaConfig, load_config
1214
from deploy.package_list import PackageList
1315
from deploy.utils import redirect_output
1416

@@ -191,3 +193,37 @@ def do_sync(
191193
dry_run: bool = False,
192194
) -> None:
193195
asyncio.run(_sync(configpath, config, prefix, dest_prefix, no_async, dry_run))
196+
197+
198+
@click.command("sync", help="Synchronise all locations")
199+
@click.argument(
200+
"config-file",
201+
type=Path,
202+
)
203+
@click.option(
204+
"--prefix",
205+
default="./output/prefix",
206+
type=Path,
207+
)
208+
@click.option(
209+
"--no-async",
210+
help="Don't deploy asynchronously",
211+
is_flag=True,
212+
default=False,
213+
)
214+
@click.option(
215+
"--dry-run",
216+
is_flag=True,
217+
default=False,
218+
)
219+
def subcommand_sync(
220+
config_file: Path, prefix: Path, no_async: bool, dry_run: bool
221+
) -> None:
222+
config = load_config(config_file)
223+
do_sync(
224+
config_file.parent,
225+
config,
226+
prefix=prefix,
227+
no_async=no_async,
228+
dry_run=dry_run,
229+
)

0 commit comments

Comments
 (0)