feat: system config DSL, services, CLI with rustc diagnostics
- System config parser (system/packages/services/boot/users blocks) - Boot block: kernel, init, efi, swap, bootloader, root partition - System-wide features, rollback config, swap partition - Service block: per-init variants (runit, s6, etc.), system init selection via boot.init - Feature-gated dependencies, config values accept numbers/bools/strings - CLI: parse-package, parse-config, validate subcommands - Rustc-style error diagnostics with source context, carets, help text - Diagnostic module with ANSI color output
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace kappa::cli {
|
||||
|
||||
struct SourceLocation {
|
||||
std::string_view file;
|
||||
int line = 0;
|
||||
int col = 0;
|
||||
};
|
||||
|
||||
void print_error(std::ostream& os,
|
||||
std::string_view source,
|
||||
SourceLocation loc,
|
||||
std::string_view message);
|
||||
|
||||
void print_error(std::ostream& os,
|
||||
std::string_view source,
|
||||
SourceLocation loc,
|
||||
std::string_view message,
|
||||
std::string_view help);
|
||||
|
||||
void print_note(std::ostream& os,
|
||||
std::string_view source,
|
||||
SourceLocation loc,
|
||||
std::string_view message);
|
||||
|
||||
} // namespace kappa::cli
|
||||
@@ -44,6 +44,14 @@ struct EnvEntry {
|
||||
bool soft = false;
|
||||
};
|
||||
|
||||
struct ServiceInit {
|
||||
std::string exec;
|
||||
std::string type;
|
||||
std::string user;
|
||||
std::vector<int> ports;
|
||||
std::unordered_map<std::string, std::string> env;
|
||||
};
|
||||
|
||||
struct PackageDef {
|
||||
std::string name;
|
||||
std::string version;
|
||||
@@ -56,6 +64,7 @@ struct PackageDef {
|
||||
std::vector<ConfigFile> config_files;
|
||||
std::vector<Patch> patches;
|
||||
std::vector<EnvEntry> env_entries;
|
||||
std::unordered_map<std::string, ServiceInit> service;
|
||||
std::unordered_set<std::string> const_keys;
|
||||
Phase prepare;
|
||||
Phase build;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include "kappa/dsl/ast.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace kappa::dsl {
|
||||
|
||||
struct RollbackConfig {
|
||||
int keep = 0;
|
||||
};
|
||||
|
||||
struct SystemBlock {
|
||||
std::string hostname;
|
||||
std::string timezone;
|
||||
std::vector<EnvEntry> env;
|
||||
std::unordered_map<std::string, std::string> config;
|
||||
std::unordered_map<std::string, FeatureDef> features;
|
||||
RollbackConfig rollback;
|
||||
};
|
||||
|
||||
struct PackageRef {
|
||||
std::string name;
|
||||
std::string version;
|
||||
std::unordered_map<std::string, FeatureDef> features;
|
||||
std::unordered_map<std::string, std::string> config;
|
||||
};
|
||||
|
||||
struct BootBlock {
|
||||
std::string kernel;
|
||||
std::string init;
|
||||
std::string efi;
|
||||
std::string swap;
|
||||
std::string bootloader;
|
||||
std::unordered_map<std::string, std::string> params;
|
||||
};
|
||||
|
||||
struct UserRef {
|
||||
std::string name;
|
||||
std::string shell;
|
||||
std::vector<std::string> groups;
|
||||
std::unordered_map<std::string, std::string> extra;
|
||||
};
|
||||
|
||||
struct ServiceRef {
|
||||
std::string name;
|
||||
bool enable = false;
|
||||
std::unordered_map<std::string, std::string> config;
|
||||
};
|
||||
|
||||
struct SystemConfig {
|
||||
SystemBlock system;
|
||||
std::vector<PackageRef> packages;
|
||||
std::vector<ServiceRef> services;
|
||||
BootBlock boot;
|
||||
std::vector<UserRef> users;
|
||||
};
|
||||
|
||||
SystemConfig parse_system_config(std::string_view source);
|
||||
|
||||
} // namespace kappa::dsl
|
||||
@@ -34,6 +34,7 @@ enum class TokenType {
|
||||
KwLicense,
|
||||
KwPatches,
|
||||
KwEnv,
|
||||
KwService,
|
||||
KwPrepare,
|
||||
KwBuild,
|
||||
KwCheck,
|
||||
|
||||
Reference in New Issue
Block a user