#![allow(clippy::type_complexity)]
use std::ops::{Deref, DerefMut};
use peace_resources::Resources;
use peace_rt_model::{
params::{KeyUnknown, ParamsKeys, ParamsKeysImpl},
Workspace,
};
use crate::{
ctx::{
cmd_ctx_builder::{
MultiProfileNoFlowBuilder, MultiProfileSingleFlowBuilder, NoProfileNoFlowBuilder,
SingleProfileNoFlowBuilder, SingleProfileSingleFlowBuilder,
},
CmdCtxBuilder,
},
scopes::{
type_params::{
FlowNotSelected, FlowParamsNone, ProfileNotSelected, ProfileParamsNone,
WorkspaceParamsNone,
},
SingleProfileSingleFlow,
},
};
#[derive(Debug)]
pub struct CmdCtx<Scope> {
pub(crate) scope: Scope,
}
impl<Scope> CmdCtx<Scope> {
pub fn scope(&self) -> &Scope {
&self.scope
}
pub fn scope_mut(&mut self) -> &mut Scope {
&mut self.scope
}
}
impl CmdCtx<()> {
pub fn builder_no_profile_no_flow<'ctx, E, O>(
output: &'ctx mut O,
workspace: &'ctx Workspace,
) -> CmdCtxBuilder<
'ctx,
O,
NoProfileNoFlowBuilder<
E,
ParamsKeysImpl<KeyUnknown, KeyUnknown, KeyUnknown>,
WorkspaceParamsNone,
>,
> {
CmdCtxBuilder::no_profile_no_flow(output, workspace)
}
pub fn builder_multi_profile_no_flow<'ctx, E, O>(
output: &'ctx mut O,
workspace: &'ctx Workspace,
) -> CmdCtxBuilder<
'ctx,
O,
MultiProfileNoFlowBuilder<
E,
ProfileNotSelected,
ParamsKeysImpl<KeyUnknown, KeyUnknown, KeyUnknown>,
WorkspaceParamsNone,
ProfileParamsNone,
>,
> {
CmdCtxBuilder::multi_profile_no_flow(output, workspace)
}
pub fn builder_multi_profile_single_flow<'ctx, E, O>(
output: &'ctx mut O,
workspace: &'ctx Workspace,
) -> CmdCtxBuilder<
'ctx,
O,
MultiProfileSingleFlowBuilder<
E,
ProfileNotSelected,
FlowNotSelected,
ParamsKeysImpl<KeyUnknown, KeyUnknown, KeyUnknown>,
WorkspaceParamsNone,
ProfileParamsNone,
FlowParamsNone,
>,
> {
CmdCtxBuilder::multi_profile_single_flow(output, workspace)
}
pub fn builder_single_profile_no_flow<'ctx, E, O>(
output: &'ctx mut O,
workspace: &'ctx Workspace,
) -> CmdCtxBuilder<
'ctx,
O,
SingleProfileNoFlowBuilder<
E,
ProfileNotSelected,
ParamsKeysImpl<KeyUnknown, KeyUnknown, KeyUnknown>,
WorkspaceParamsNone,
ProfileParamsNone,
>,
> {
CmdCtxBuilder::single_profile_no_flow(output, workspace)
}
pub fn builder_single_profile_single_flow<'ctx, E, O>(
output: &'ctx mut O,
workspace: &'ctx Workspace,
) -> CmdCtxBuilder<
'ctx,
O,
SingleProfileSingleFlowBuilder<
E,
ProfileNotSelected,
FlowNotSelected,
ParamsKeysImpl<KeyUnknown, KeyUnknown, KeyUnknown>,
WorkspaceParamsNone,
ProfileParamsNone,
FlowParamsNone,
>,
> {
CmdCtxBuilder::single_profile_single_flow(output, workspace)
}
}
impl<'ctx, E, O, PKeys, ResTs0> CmdCtx<SingleProfileSingleFlow<'ctx, E, O, PKeys, ResTs0>>
where
PKeys: ParamsKeys + 'static,
{
pub fn resources_update<ResTs1, F>(
self,
f: F,
) -> CmdCtx<SingleProfileSingleFlow<'ctx, E, O, PKeys, ResTs1>>
where
F: FnOnce(Resources<ResTs0>) -> Resources<ResTs1>,
{
let CmdCtx { scope } = self;
let scope = scope.resources_update(f);
CmdCtx { scope }
}
}
impl<Scope> Deref for CmdCtx<Scope> {
type Target = Scope;
fn deref(&self) -> &Self::Target {
&self.scope
}
}
impl<Scope> DerefMut for CmdCtx<Scope> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.scope
}
}