Skip to content

Commit d9a27fa

Browse files
committed
feat(init): Offer to add a keyboard on first init
When running "zmk init" to clone a repo, if build.yaml does not include any keyboards, we now assume the user is setting things up for the first time and offer to add a keyboard right away. This simply jumps into the function for "zmk keyboard new" if the user says yes.
1 parent 3df5639 commit d9a27fa

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

zmk/commands/init.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111

1212
import rich
1313
import typer
14+
from rich.console import Console
1415
from rich.prompt import Confirm, Prompt
1516
from rich.table import Table
1617

18+
from ..build import BuildMatrix
1719
from ..config import Config, get_config
1820
from ..exceptions import FatalError
1921
from ..prompt import UrlPrompt
2022
from ..repo import Repo, find_containing_repo, is_repo
23+
from .keyboard.add import keyboard_add
2124

2225
TEMPLATE_URL = (
2326
"https://github.com/new?template_name=unified-zmk-config-template"
@@ -59,6 +62,8 @@ def init(ctx: typer.Context) -> None:
5962
table.add_row('[green]"zmk cd"', "Move to the repo directory.")
6063
console.print(table)
6164

65+
_add_first_keyboard(ctx, console, repo)
66+
6267
# TODO: add some help for how to commit and push changes
6368

6469

@@ -133,3 +138,15 @@ def _clone_repo(url: str, name: str):
133138
subprocess.check_call(["git", "clone", url, name])
134139
except subprocess.CalledProcessError as ex:
135140
raise typer.Exit(code=ex.returncode)
141+
142+
143+
def _add_first_keyboard(ctx: typer.Context, console: Console, repo: Repo):
144+
matrix = BuildMatrix.from_repo(repo)
145+
if matrix.include:
146+
return
147+
148+
console.print()
149+
console.print("This looks like a new repo.")
150+
151+
if Confirm.ask("Would you like to add a keyboard now?", default=True):
152+
keyboard_add(ctx)

0 commit comments

Comments
 (0)