api/flash: refactor into 'list_flash_options'
This commit is contained in:
@@ -110,7 +110,7 @@ export const Flash = () => {
|
||||
const keymapQuery = createQuery(() => ({
|
||||
queryKey: ["list_keymaps"],
|
||||
queryFn: async () => {
|
||||
const result = await callApi("list_possible_keymaps", {}).promise;
|
||||
const result = await callApi("list_keymaps", {}).promise;
|
||||
if (result.status === "error") throw new Error("Failed to fetch data");
|
||||
return result.data;
|
||||
},
|
||||
@@ -120,7 +120,7 @@ export const Flash = () => {
|
||||
const langQuery = createQuery(() => ({
|
||||
queryKey: ["list_languages"],
|
||||
queryFn: async () => {
|
||||
const result = await callApi("list_possible_languages", {}).promise;
|
||||
const result = await callApi("list_languages", {}).promise;
|
||||
if (result.status === "error") throw new Error("Failed to fetch data");
|
||||
return result.data;
|
||||
},
|
||||
|
||||
@@ -17,7 +17,7 @@ from clan_cli.vars.generate import generate_vars
|
||||
from clan_cli.vars.upload import populate_secret_vars
|
||||
|
||||
from .automount import pause_automounting
|
||||
from .list import list_possible_keymaps, list_possible_languages
|
||||
from .list import list_keymaps, list_languages
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -59,7 +59,7 @@ def flash_machine(
|
||||
generate_vars([machine])
|
||||
|
||||
if system_config.language:
|
||||
if system_config.language not in list_possible_languages():
|
||||
if system_config.language not in list_languages():
|
||||
msg = (
|
||||
f"Language '{system_config.language}' is not a valid language. "
|
||||
f"Run 'clan flash list languages' to see a list of possible languages."
|
||||
@@ -68,7 +68,7 @@ def flash_machine(
|
||||
system_config_nix["i18n"] = {"defaultLocale": system_config.language}
|
||||
|
||||
if system_config.keymap:
|
||||
if system_config.keymap not in list_possible_keymaps():
|
||||
if system_config.keymap not in list_keymaps():
|
||||
msg = (
|
||||
f"Keymap '{system_config.keymap}' is not a valid keymap. "
|
||||
f"Run 'clan flash list keymaps' to see a list of possible keymaps."
|
||||
|
||||
@@ -2,6 +2,7 @@ import argparse
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import TypedDict
|
||||
|
||||
from clan_lib.api import API
|
||||
from clan_lib.cmd import Log, RunOpts, run
|
||||
@@ -11,8 +12,17 @@ from clan_lib.nix import nix_build
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FlashOptions(TypedDict):
|
||||
languages: list[str]
|
||||
keymaps: list[str]
|
||||
|
||||
|
||||
@API.register
|
||||
def list_possible_languages() -> list[str]:
|
||||
def show_flash_options() -> FlashOptions:
|
||||
return {"languages": list_languages(), "keymaps": list_keymaps()}
|
||||
|
||||
|
||||
def list_languages() -> list[str]:
|
||||
cmd = nix_build(["nixpkgs#glibcLocales"])
|
||||
result = run(cmd, RunOpts(log=Log.STDERR, error_msg="Failed to find glibc locales"))
|
||||
locale_file = Path(result.stdout.strip()) / "share" / "i18n" / "SUPPORTED"
|
||||
@@ -37,8 +47,7 @@ def list_possible_languages() -> list[str]:
|
||||
return languages
|
||||
|
||||
|
||||
@API.register
|
||||
def list_possible_keymaps() -> list[str]:
|
||||
def list_keymaps() -> list[str]:
|
||||
cmd = nix_build(["nixpkgs#kbd"])
|
||||
result = run(cmd, RunOpts(log=Log.STDERR, error_msg="Failed to find kbdinfo"))
|
||||
keymaps_dir = Path(result.stdout.strip()) / "share" / "keymaps"
|
||||
@@ -61,11 +70,11 @@ def list_possible_keymaps() -> list[str]:
|
||||
|
||||
def list_command(args: argparse.Namespace) -> None:
|
||||
if args.cmd == "languages":
|
||||
languages = list_possible_languages()
|
||||
languages = list_languages()
|
||||
for language in languages:
|
||||
print(language)
|
||||
elif args.cmd == "keymaps":
|
||||
keymaps = list_possible_keymaps()
|
||||
keymaps = list_keymaps()
|
||||
for keymap in keymaps:
|
||||
print(keymap)
|
||||
|
||||
|
||||
@@ -343,9 +343,9 @@ def test_generated_shared_secret_sops(
|
||||
shared_generator["script"] = 'echo hello > "$out"/my_shared_secret'
|
||||
m2_config = flake.machines["machine2"]
|
||||
m2_config["nixpkgs"]["hostPlatform"] = "x86_64-linux"
|
||||
m2_config["clan"]["core"]["vars"]["generators"][
|
||||
"my_shared_generator"
|
||||
] = shared_generator.copy()
|
||||
m2_config["clan"]["core"]["vars"]["generators"]["my_shared_generator"] = (
|
||||
shared_generator.copy()
|
||||
)
|
||||
flake.refresh()
|
||||
monkeypatch.chdir(flake.path)
|
||||
machine1 = Machine(name="machine1", flake=Flake(str(flake.path)))
|
||||
@@ -803,9 +803,9 @@ def test_migration(
|
||||
my_service = config["clan"]["core"]["facts"]["services"]["my_service"]
|
||||
my_service["public"]["my_value"] = {}
|
||||
my_service["secret"]["my_secret"] = {}
|
||||
my_service["generator"][
|
||||
"script"
|
||||
] = 'echo -n hello > "$facts"/my_value && echo -n hello > "$secrets"/my_secret'
|
||||
my_service["generator"]["script"] = (
|
||||
'echo -n hello > "$facts"/my_value && echo -n hello > "$secrets"/my_secret'
|
||||
)
|
||||
my_generator = config["clan"]["core"]["vars"]["generators"]["my_generator"]
|
||||
my_generator["files"]["my_value"]["secret"] = False
|
||||
my_generator["files"]["my_secret"]["secret"] = True
|
||||
@@ -875,9 +875,9 @@ def test_fails_when_files_are_left_from_other_backend(
|
||||
regenerate=False,
|
||||
)
|
||||
# Will raise. It was secret before, but now it's not.
|
||||
my_secret_generator["files"]["my_secret"][
|
||||
"secret"
|
||||
] = False # secret -> public (NOT OK)
|
||||
my_secret_generator["files"]["my_secret"]["secret"] = (
|
||||
False # secret -> public (NOT OK)
|
||||
)
|
||||
# WIll not raise. It was not secret before, and it's secret now.
|
||||
my_value_generator["files"]["my_value"]["secret"] = True # public -> secret (OK)
|
||||
flake.refresh()
|
||||
|
||||
@@ -3,7 +3,6 @@ import logging
|
||||
import sys
|
||||
|
||||
from clan_cli.completions import add_dynamic_completer, complete_machines
|
||||
from clan_lib.api import API
|
||||
from clan_lib.errors import ClanError
|
||||
from clan_lib.flake import Flake
|
||||
|
||||
|
||||
@@ -2,13 +2,10 @@ import argparse
|
||||
import logging
|
||||
|
||||
from clan_cli.completions import add_dynamic_completer, complete_machines
|
||||
from clan_lib.api import API
|
||||
from clan_lib.errors import ClanError
|
||||
from clan_lib.flake import Flake
|
||||
from clan_lib.machines.machines import Machine
|
||||
|
||||
from ._types import GeneratorUpdate
|
||||
from .generate import Generator, Prompt, Var, execute_generator
|
||||
from .generate import Var
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user