mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-30 12:14:10 +01:00
feat(wm): JSON schemas, and the module's typed options
komorebi.json is described as a JSON Schema, made from the Rust types that read it: komorebic prints the schema of komorebi.json, of an applications.json, of a notification and of a message, and the daemon answers the same four questions on its socket. schema.json and schema.asc.json are committed (just jsonschema). The module's config option is typed from the schema: schemars-nixgen makes nix/komorebi-options.nix from schema.json (just nixgen), so a layout komorebi does not have, or a value of the wrong kind, does not evaluate. The module writes config as a komorebi.json and gives it to the daemon with --config. configFile and the file the module writes are checked against the schema when the system is built. applicationSpecificConfiguration takes files from GitHub, and there are none by default, since no community file for Plasma is known. Two checks keep the generated files honest without the tools that make them. schema-fresh compares the schemas with what komorebic prints, and the hash on the first line of the options with the schema. nix-options-validation evaluates the options against the example configuration, written in Nix and in JSON. nixos-module-eval also evaluates the module with the sources turned off: with applicationSpecificConfiguration.enable = false the sources are left out of the config that is written, and with no config either there is nothing to write and the unit passes no --config. ARCHITECTURE has the guarantee row that names the two checks.
This commit is contained in:
1 parent
ed34286bca
commit
3a3a0f8f24
29 files changed
+2754
-49
No files matched your search
+45
-1
@@ -84,7 +84,10 @@
|
||||
//! The others work without the daemon: `start` runs `komorebi` in the background, with the
|
||||
//! `komorebi.json` it is given with `--config`, `configuration` shows the path of the
|
||||
//! `komorebi.json` the daemon reads, `log` follows its log, `data-directory` shows where its
|
||||
//! socket is, and `completions` prints a completion script for a shell. The hidden `docgen` writes the help of every subcommand as Markdown, wrapped
|
||||
//! socket is, `completions` prints a completion script for a shell, and `static-config-schema`,
|
||||
//! `application-specific-configuration-schema`, `notification-schema` and `socket-schema` print
|
||||
//! the JSON Schema of `komorebi.json`, of an `applications.json`, of a notification and of a
|
||||
//! message. The hidden `docgen` writes the help of every subcommand as Markdown, wrapped
|
||||
//! at 100 columns whatever the width of the terminal, which is how `docs/cli` is made.
|
||||
|
||||
use chrono::Utc;
|
||||
@@ -1029,6 +1032,15 @@ enum SubCommand {
|
||||
MouseFollowsFocus(MouseFollowsFocus),
|
||||
/// Toggle mouse follows focus on all workspaces
|
||||
ToggleMouseFollowsFocus,
|
||||
/// Generate a JSON Schema for applications.json
|
||||
#[clap(alias = "asc-schema")]
|
||||
ApplicationSpecificConfigurationSchema,
|
||||
/// Generate a JSON Schema of subscription notifications
|
||||
NotificationSchema,
|
||||
/// Generate a JSON Schema of socket messages
|
||||
SocketSchema,
|
||||
/// Generate a JSON Schema of the static configuration file
|
||||
StaticConfigSchema,
|
||||
/// Generates a static configuration JSON file based on the current window manager state
|
||||
GenerateStaticConfig,
|
||||
}
|
||||
@@ -1622,6 +1634,38 @@ fn main() -> eyre::Result<()> {
|
||||
SubCommand::MouseFollowsFocus(args) => {
|
||||
send_message(&SocketMessage::MouseFollowsFocus(args.boolean_state.into()))?;
|
||||
}
|
||||
SubCommand::ApplicationSpecificConfigurationSchema => {
|
||||
#[cfg(feature = "schemars")]
|
||||
{
|
||||
let asc = schemars::schema_for!(komorebi_client::ApplicationSpecificConfiguration);
|
||||
let schema = serde_json::to_string_pretty(&asc)?;
|
||||
println!("{schema}");
|
||||
}
|
||||
}
|
||||
SubCommand::NotificationSchema => {
|
||||
#[cfg(feature = "schemars")]
|
||||
{
|
||||
let notification = schemars::schema_for!(komorebi_client::Notification);
|
||||
let schema = serde_json::to_string_pretty(¬ification)?;
|
||||
println!("{schema}");
|
||||
}
|
||||
}
|
||||
SubCommand::SocketSchema => {
|
||||
#[cfg(feature = "schemars")]
|
||||
{
|
||||
let socket_message = schemars::schema_for!(SocketMessage);
|
||||
let schema = serde_json::to_string_pretty(&socket_message)?;
|
||||
println!("{schema}");
|
||||
}
|
||||
}
|
||||
SubCommand::StaticConfigSchema => {
|
||||
#[cfg(feature = "schemars")]
|
||||
{
|
||||
let socket_message = schemars::schema_for!(komorebi_client::StaticConfig);
|
||||
let schema = serde_json::to_string_pretty(&socket_message)?;
|
||||
println!("{schema}");
|
||||
}
|
||||
}
|
||||
SubCommand::SubscribeSocket(args) => {
|
||||
send_message(&SocketMessage::AddSubscriberSocket(args.socket))?;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user