hypershell_tokio_components/providers/
join_args.rs1use core::marker::PhantomData;
2use std::path::PathBuf;
3
4use cgp::prelude::*;
5use hypershell_components::components::{
6 CanExtractCommandArg, CommandArgExtractor, CommandArgExtractorComponent, HasCommandArgType,
7};
8use hypershell_components::dsl::JoinArgs;
9
10pub struct JoinExtractArgs;
11
12#[cgp_provider]
13impl<Context, Arg, Args> CommandArgExtractor<Context, JoinArgs<Cons<Arg, Args>>> for JoinExtractArgs
14where
15 Context: CanExtractCommandArg<Arg> + HasCommandArgType<CommandArg = PathBuf>,
16 Self: CommandArgExtractor<Context, JoinArgs<Args>>,
17{
18 fn extract_command_arg(
19 context: &Context,
20 _phantom: PhantomData<JoinArgs<Cons<Arg, Args>>>,
21 ) -> PathBuf {
22 let arg_a = context.extract_command_arg(PhantomData);
23 let arg_b = Self::extract_command_arg(context, PhantomData::<JoinArgs<Args>>);
24
25 if arg_b.as_os_str().is_empty() {
26 arg_a
27 } else {
28 arg_a.join(arg_b)
29 }
30 }
31}
32
33#[cgp_provider]
34impl<Context> CommandArgExtractor<Context, JoinArgs<Nil>> for JoinExtractArgs
35where
36 Context: HasCommandArgType<CommandArg = PathBuf>,
37{
38 fn extract_command_arg(_context: &Context, _phantom: PhantomData<JoinArgs<Nil>>) -> PathBuf {
39 PathBuf::new()
40 }
41}