nut_shell/
lib.rs

1//! # nut-shell
2//!
3//! Lightweight CLI library for embedded systems with zero heap allocation.
4//!
5//! **Key features:**
6//! - **Static allocation** - Everything lives in ROM, zero heap usage
7//! - **Const initialization** - Command trees defined at compile time
8//! - **Optional features** - Authentication, tab completion, command history, async
9//! - **Flexible I/O** - Platform-agnostic character I/O trait
10//! - **Access control** - Hierarchical permissions with generic access levels
11//!
12//! See EXAMPLES.md for complete usage patterns.
13//!
14//! ## Optional Features
15//!
16//! - `authentication` - User login/logout, password hashing, credential providers
17//! - `completion` - Tab completion for commands and paths
18//! - `history` - Command history with up/down arrow navigation
19//! - `async` - Async command execution support
20//!
21//! The library provides a `#[derive(AccessLevel)]` macro that's always available.
22//!
23//! This library is `no_std` compatible.
24
25#![no_std]
26#![warn(missing_docs)]
27#![warn(missing_debug_implementations)]
28#![allow(clippy::result_large_err)]
29
30extern crate heapless;
31
32// Optional dependencies (feature-gated)
33#[cfg(feature = "authentication")]
34extern crate sha2;
35
36#[cfg(feature = "authentication")]
37extern crate subtle;
38
39// Re-export derive macro (always available)
40pub use nut_shell_macros::AccessLevel;
41
42// ============================================================================
43// Module Declarations
44// ============================================================================
45
46// I/O & Access Control Foundation
47pub mod config;
48pub mod io;
49
50// Authentication module (always present, but with different contents based on features)
51pub mod auth;
52
53// Error handling
54pub mod error;
55
56// Tree data model
57pub mod tree;
58
59// Response types
60pub mod response;
61
62// Shell orchestration
63pub mod shell;
64
65// ============================================================================
66// Re-exports - Public API
67// ============================================================================
68
69// Core I/O
70pub use io::CharIo;
71
72// Configuration
73pub use config::{DefaultConfig, MinimalConfig, ShellConfig};
74
75// Error types
76pub use error::CliError;
77
78// Tree types
79pub use tree::{CommandKind, CommandMeta, Directory, Node};
80
81// Access control (always available, even without authentication feature)
82pub use auth::{AccessLevel, User};
83
84// Response types
85pub use response::Response;
86
87// Shell types
88pub use shell::handler::CommandHandler;
89pub use shell::{CliState, HistoryDirection, Request, Shell};
90
91// Optional feature re-exports (authentication-only types)
92#[cfg(feature = "authentication")]
93pub use auth::{ConstCredentialProvider, CredentialProvider, PasswordHasher, Sha256Hasher};
94
95// ============================================================================
96// Library Metadata
97// ============================================================================
98
99/// Library version
100pub const VERSION: &str = env!("CARGO_PKG_VERSION");
101
102/// Library name
103pub const NAME: &str = env!("CARGO_PKG_NAME");
104
105// ============================================================================
106// Tests
107// ============================================================================
108
109#[cfg(test)]
110mod tests {
111    // No tests needed - all public APIs tested in their respective modules
112}