Skip to main content

hx_plugins/api/
config.rs

1//! Configuration API for plugins.
2//!
3//! Provides: (hx/config-get), (hx/env-get), (hx/env-set!)
4
5use crate::context::{with_context, with_context_mut};
6use crate::error::Result;
7use std::env;
8use steel::SteelVal;
9use steel::steel_vm::engine::Engine;
10use steel::steel_vm::register_fn::RegisterFn;
11
12/// Register config API functions.
13pub fn register(engine: &mut Engine) -> Result<()> {
14    engine.register_fn("hx/config-get", config_get);
15    engine.register_fn("hx/env-get", env_get);
16    engine.register_fn("hx/env-set!", env_set);
17    engine.register_fn("hx/verbose?", is_verbose);
18    Ok(())
19}
20
21/// Get a configuration value.
22/// Note: This is a placeholder - full implementation would need access to hx.toml.
23fn config_get(_section: String, _key: String) -> SteelVal {
24    // TODO: Implement config access once we have the manifest in context
25    SteelVal::BoolV(false)
26}
27
28/// Get an environment variable.
29fn env_get(name: String) -> SteelVal {
30    match env::var(&name) {
31        Ok(value) => SteelVal::StringV(value.into()),
32        Err(_) => SteelVal::BoolV(false),
33    }
34}
35
36/// Set an environment variable for child processes.
37fn env_set(name: String, value: String) -> SteelVal {
38    with_context_mut(|ctx| {
39        ctx.set_env(name, value);
40    });
41    SteelVal::Void
42}
43
44/// Check if verbose mode is enabled.
45fn is_verbose() -> SteelVal {
46    with_context(|ctx| SteelVal::BoolV(ctx.verbose)).unwrap_or(SteelVal::BoolV(false))
47}