mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-09 06:47:59 -06:00
Fix examples for renamed leaf endpoint surface
Update the remote shell examples to use unshell::leaves and the leaf_endpoint feature-gated endpoint module, and restore the local macro aliasing needed after removing the direct unshell dependency from unshell-leaves.
This commit is contained in:
@@ -2,10 +2,18 @@
|
||||
//! protocol runtime.
|
||||
//!
|
||||
//! Each leaf module always exports its shared protocol-facing types. Role-specific
|
||||
//! implementations are selected with the crate-wide `endpoint` and `tui`
|
||||
//! implementations are selected with the crate-wide `leaf_endpoint` and `leaf_tui`
|
||||
//! features, and can optionally be re-exported behind one stable alias.
|
||||
|
||||
use unshell::protocol::DataMessage;
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate self as unshell;
|
||||
|
||||
pub extern crate alloc;
|
||||
|
||||
use unshell_protocol::DataMessage;
|
||||
|
||||
pub use unshell_macros::{Leaf, Procedure, procedures};
|
||||
pub use unshell_protocol as protocol;
|
||||
|
||||
/// Re-exports one role-specific type behind a stable public alias.
|
||||
///
|
||||
@@ -20,18 +28,18 @@ macro_rules! role_leaf {
|
||||
tui => $tui:path $(,)?
|
||||
}
|
||||
) => {
|
||||
#[cfg(all(feature = "endpoint", feature = "tui"))]
|
||||
#[cfg(all(feature = "leaf_endpoint", feature = "leaf_tui"))]
|
||||
compile_error!(concat!(
|
||||
"`",
|
||||
stringify!($alias),
|
||||
"` can only alias one concrete role at a time; enable either `endpoint` or `tui`, not both"
|
||||
"` can only alias one concrete role at a time; enable either `leaf_endpoint` or `leaf_tui`, not both"
|
||||
));
|
||||
|
||||
#[cfg(feature = "endpoint")]
|
||||
#[cfg(feature = "leaf_endpoint")]
|
||||
$(#[$meta])*
|
||||
$vis type $alias = $endpoint;
|
||||
|
||||
#[cfg(all(not(feature = "endpoint"), feature = "tui"))]
|
||||
#[cfg(all(not(feature = "leaf_endpoint"), feature = "leaf_tui"))]
|
||||
$(#[$meta])*
|
||||
$vis type $alias = $tui;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@ pub use errors::ShellLeafError;
|
||||
pub use session::ProcedureOpen;
|
||||
pub use transport::{LISTEN_ADDR, send_forward, spawn_frame_reader, write_frames};
|
||||
|
||||
use super::{OpenRequest, agent_path};
|
||||
use super::OpenRequest;
|
||||
|
||||
/// Leaf state for the remote shell endpoint runtime.
|
||||
///
|
||||
@@ -94,3 +94,7 @@ pub fn build_agent_runtime() -> ProcedureRuntime<RemoteShellEndpoint, ProcedureO
|
||||
);
|
||||
ProcedureRuntime::new(endpoint, RemoteShellEndpoint::default())
|
||||
}
|
||||
|
||||
fn agent_path() -> Vec<String> {
|
||||
vec![String::from("agent")]
|
||||
}
|
||||
|
||||
@@ -2,26 +2,21 @@
|
||||
//!
|
||||
//! The module always exports the protocol contract for the leaf. Role-specific
|
||||
//! implementations live behind crate-wide features:
|
||||
//! - `endpoint` builds the PTY-backed runtime leaf
|
||||
//! - `tui` builds a placeholder client-side TUI surface
|
||||
//! - `leaf_endpoint` builds the PTY-backed runtime leaf
|
||||
//! - `leaf_tui` builds a placeholder client-side TUI surface
|
||||
|
||||
use rkyv::{Archive, Deserialize, Serialize};
|
||||
|
||||
#[cfg(feature = "endpoint")]
|
||||
mod endpoint;
|
||||
#[cfg(feature = "tui")]
|
||||
mod tui;
|
||||
#[cfg(feature = "leaf_endpoint")]
|
||||
pub mod endpoint;
|
||||
#[cfg(feature = "leaf_tui")]
|
||||
pub mod tui;
|
||||
|
||||
#[cfg(feature = "endpoint")]
|
||||
pub use endpoint::{
|
||||
LISTEN_ADDR, RemoteShellEndpoint, ShellLeafError, build_agent_runtime,
|
||||
build_controller_endpoint, send_forward, spawn_frame_reader, write_frames,
|
||||
};
|
||||
#[cfg(feature = "tui")]
|
||||
#[cfg(feature = "leaf_endpoint")]
|
||||
pub use endpoint::RemoteShellEndpoint;
|
||||
#[cfg(feature = "leaf_tui")]
|
||||
pub use tui::RemoteShellTui;
|
||||
|
||||
use unshell::protocol::tree::encode_call_reply;
|
||||
|
||||
/// Open-request payload for the remote shell leaf.
|
||||
///
|
||||
/// The shell currently needs no structured arguments, but a named payload type is
|
||||
@@ -36,57 +31,3 @@ crate::role_leaf! {
|
||||
tui => tui::RemoteShellTui,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the example endpoint path used by the remote shell samples.
|
||||
pub fn agent_path() -> Vec<String> {
|
||||
path(&["agent"])
|
||||
}
|
||||
|
||||
/// Returns the canonical leaf id used by endpoint and TUI code.
|
||||
#[cfg(feature = "endpoint")]
|
||||
pub fn shell_leaf_name() -> String {
|
||||
RemoteShellEndpoint::protocol_leaf_name()
|
||||
}
|
||||
|
||||
/// Returns the canonical opening `procedure_id` for the shell leaf.
|
||||
#[cfg(feature = "endpoint")]
|
||||
pub fn shell_open_procedure() -> String {
|
||||
endpoint::ProcedureOpen::protocol_procedure_id()
|
||||
}
|
||||
|
||||
/// Encodes the empty open-request payload used by the shell example.
|
||||
#[cfg(all(not(feature = "endpoint"), feature = "tui"))]
|
||||
pub fn shell_leaf_name() -> String {
|
||||
RemoteShellTui::protocol_leaf_name()
|
||||
}
|
||||
|
||||
/// Returns the canonical opening `procedure_id` for the shell leaf.
|
||||
#[cfg(all(not(feature = "endpoint"), feature = "tui"))]
|
||||
pub fn shell_open_procedure() -> String {
|
||||
let mut procedure_id = shell_leaf_name();
|
||||
procedure_id.push_str(".open");
|
||||
procedure_id
|
||||
}
|
||||
|
||||
/// Encodes the empty open-request payload used by the shell example.
|
||||
#[cfg(not(any(feature = "endpoint", feature = "tui")))]
|
||||
pub fn shell_leaf_name() -> String {
|
||||
String::from("remote_shell")
|
||||
}
|
||||
|
||||
/// Returns the canonical opening `procedure_id` for the shell leaf.
|
||||
#[cfg(not(any(feature = "endpoint", feature = "tui")))]
|
||||
pub fn shell_open_procedure() -> String {
|
||||
let mut procedure_id = shell_leaf_name();
|
||||
procedure_id.push_str(".open");
|
||||
procedure_id
|
||||
}
|
||||
|
||||
/// Encodes the empty open-request payload used by the shell example.
|
||||
pub fn shell_open_payload() -> Vec<u8> {
|
||||
encode_call_reply(&OpenRequest).expect("remote shell open payload should encode")
|
||||
}
|
||||
|
||||
fn path(parts: &[&str]) -> Vec<String> {
|
||||
parts.iter().map(|part| (*part).to_owned()).collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user