hypershell_tokio_components/providers/
update_command.rs1use core::marker::PhantomData;
2use std::ffi::OsStr;
3
4use cgp::prelude::*;
5use hypershell_components::components::CanExtractCommandArg;
6use hypershell_components::dsl::{FieldArgs, WithArgs};
7use tokio::process::Command;
8
9use crate::components::{CommandUpdater, CommandUpdaterComponent};
10
11pub struct ExtractArgs;
12
13#[cgp_provider]
14impl<Context, Arg, Args> CommandUpdater<Context, WithArgs<Cons<Arg, Args>>> for ExtractArgs
15where
16 Context: CanExtractCommandArg<Arg>,
17 Context::CommandArg: AsRef<OsStr> + Send,
18 Self: CommandUpdater<Context, WithArgs<Args>>,
19{
20 fn update_command(
21 context: &Context,
22 _phantom: PhantomData<WithArgs<Cons<Arg, Args>>>,
23 command: &mut Command,
24 ) {
25 let arg = context.extract_command_arg(PhantomData);
26 command.arg(arg);
27
28 Self::update_command(context, PhantomData::<WithArgs<Args>>, command);
29 }
30}
31
32#[cgp_provider]
33impl<Context> CommandUpdater<Context, WithArgs<Nil>> for ExtractArgs {
34 fn update_command(
35 _context: &Context,
36 _phantom: PhantomData<WithArgs<Nil>>,
37 _command: &mut Command,
38 ) {
39 }
40}
41
42#[cgp_new_provider]
43impl<Context, Tag> CommandUpdater<Context, FieldArgs<Tag>> for ExtractFieldArgs
44where
45 Context: HasField<Tag>,
46 for<'a> &'a Context::Value: IntoIterator<Item: AsRef<OsStr>>,
47{
48 fn update_command(
49 context: &Context,
50 _phantom: PhantomData<FieldArgs<Tag>>,
51 command: &mut Command,
52 ) {
53 let args = context.get_field(PhantomData);
54 command.args(args);
55 }
56}