Skip to main content

Module context

Module context 

Source
Expand description

Central execution context for click-rs.

The Context struct holds state relevant for script execution at every level. It manages parameter values, parent-child relationships, and provides access to shared metadata and resources.

§Thread-Local Context Stack

Click uses a thread-local stack to provide implicit access to the current context. Use push_context, pop_context, and get_current_context to manage this stack.

§Example

use click::context::{Context, ContextBuilder, push_context, pop_context, get_current_context};
use std::sync::Arc;

let ctx = ContextBuilder::new()
    .info_name("myapp")
    .build();
let ctx = Arc::new(ctx);

push_context(Arc::clone(&ctx));
assert!(get_current_context().is_some());
pop_context();
assert!(get_current_context().is_none());

Structs§

Context
The central execution context for click-rs.
ContextBuilder
Builder for creating Context instances with custom settings.

Functions§

get_current_context
Get the current context from the thread-local stack.
pop_context
Pop and return the top context from the thread-local context stack.
push_context
Push a context onto the thread-local context stack.

Type Aliases§

BoxedValue
Type alias for shared values that can be stored in context maps. Uses Arc to allow cloning and sharing across parent-child contexts.
HelpRenderer
A pluggable help renderer that can be installed into a context.