use crate::Conventions;
use alux_ext::ext;
pub trait CliCommandsAlg {
type Commands;
fn cli_empty(&self) -> Self::Commands;
fn cli_merge(&self, left: Self::Commands, right: Self::Commands) -> Self::Commands;
}
pub trait CliOperationAlg<Operation, Inputs, Mode> {
type Commands;
fn cli_operation(
&self,
name: &'static str,
operation: Operation,
inputs: Inputs,
mode: Mode,
conventions: Conventions,
) -> Self::Commands;
}
pub trait CliNestAlg {
type Commands;
fn cli_nest(&self, name: &'static str, commands: Self::Commands) -> Self::Commands;
fn cli_nest_with(&self, name: &'static str, compile: impl FnOnce(&Self) -> Self::Commands) -> Self::Commands
where
Self: Sized,
{
self.cli_nest(name, compile(self))
}
}
pub trait CliContextAlg<Operation, Inputs, Mode> {
type Inner;
type InnerCommands;
type Commands;
fn cli_inner(&self) -> Self::Inner;
fn cli_within(
&self,
operation: Operation,
inputs: Inputs,
mode: Mode,
commands: Self::InnerCommands,
) -> Self::Commands;
}
pub trait CliProgramAlg<Compiler> {
type Commands;
fn compile_cli(self, compiler: &Compiler) -> Self::Commands;
}
#[ext(name = CliProgramExt)]
pub impl<This> This {
fn compile_cli<Program>(&self, program: Program) -> Program::Commands
where
Program: CliProgramAlg<This>,
{
program.compile_cli(self)
}
}