hypershell_tokio_components/
presets.rs1#[cgp::re_export_imports]
2mod preset {
3 use std::path::PathBuf;
4 use std::string::String;
5 use std::vec::Vec;
6
7 use cgp::core::component::UseDelegate;
8 use cgp::extra::handler::{HandlerComponent, PipeHandlers, UseInputDelegate};
9 use cgp::prelude::{cgp_preset, *};
10 use hypershell_components::components::{
11 CommandArgExtractorComponent, CommandArgTypeProviderComponent,
12 };
13 use hypershell_components::dsl::{
14 BytesToStream, FieldArg, FieldArgs, JoinArgs, ReadFile, SimpleExec, StaticArg,
15 StreamToBytes, StreamToStdout, StreamToString, StreamingExec, WithArgs, WriteFile,
16 };
17 use hypershell_components::providers::{ExtractStringCommandArg, ReturnInput};
18
19 use crate::components::CommandUpdaterComponent;
20 use crate::dsl::{CoreExec, ToTokioAsyncRead};
21 use crate::providers::{
22 AsyncReadToStream, ExtractArgs, ExtractFieldArgs, FuturesToTokioAsyncRead,
23 HandleBytesToStream, HandleBytesToTokioAsyncRead, HandleCoreExec, HandleReadFile,
24 HandleSimpleExec, HandleStreamToStdout, HandleStreamingExec, HandleTokioAsyncReadToBytes,
25 HandleTokioAsyncReadToString, HandleWriteFile, JoinExtractArgs, WrapTokioAsyncRead,
26 };
27 use crate::types::{FuturesAsyncReadStream, TokioAsyncReadStream};
28
29 cgp_preset! {
30 HypershellTokioPreset {
31 CommandArgTypeProviderComponent:
32 UseType<PathBuf>,
33 HandlerComponent:
34 TokioHandlerPreset::Provider,
35 CommandArgExtractorComponent:
36 CommandArgExtractorPreset::Provider,
37 CommandUpdaterComponent:
38 CommandUpdaterPreset::Provider,
39 }
40 }
41
42 cgp_preset! {
43 #[wrap_provider(UseDelegate)]
44 TokioHandlerPreset {
45 <Path, Args> SimpleExec<Path, Args>:
46 HandleSimpleExec,
47 <Path, Args> StreamingExec<Path, Args>:
48 PipeHandlers<Product![
49 ToTokioAsyncReadHandlers::Provider,
50 HandleStreamingExec,
51 WrapTokioAsyncRead,
52 ]>,
53 <Path, Args> CoreExec<Path, Args>:
54 HandleCoreExec,
55 <Path> ReadFile<Path>:
56 PipeHandlers<Product![
57 HandleReadFile,
58 WrapTokioAsyncRead,
59 ]>,
60 <Path> WriteFile<Path>:
61 PipeHandlers<Product![
62 ToTokioAsyncReadHandlers::Provider,
63 HandleWriteFile,
64 ]>,
65 StreamToBytes:
66 HandleTokioAsyncReadToBytes,
67 StreamToString:
68 HandleTokioAsyncReadToString,
69 BytesToStream:
70 HandleBytesToTokioAsyncRead,
71 StreamToStdout:
72 PipeHandlers<Product![
73 ToTokioAsyncReadHandlers::Provider,
74 HandleStreamToStdout,
75 ]>,
76 ToTokioAsyncRead:
77 ToTokioAsyncReadHandlers::Provider,
78 }
79 }
80
81 cgp_preset! {
82 #[wrap_provider(UseDelegate)]
83 CommandArgExtractorPreset {
84 [
85 <Arg> StaticArg<Arg>,
86 <Tag> FieldArg<Tag>,
87 ]: ExtractStringCommandArg,
88 <Args> JoinArgs<Args>:
89 JoinExtractArgs,
90 }
91 }
92
93 cgp_preset! {
94 #[wrap_provider(UseDelegate)]
95 CommandUpdaterPreset {
96 <Args> WithArgs<Args>: ExtractArgs,
97 <Tag> FieldArgs<Tag>: ExtractFieldArgs,
98 }
99 }
100
101 cgp_preset! {
102 #[wrap_provider(UseInputDelegate)]
103 ToTokioAsyncReadHandlers {
104 <S> FuturesAsyncReadStream<S>:
105 FuturesToTokioAsyncRead,
106 <S> TokioAsyncReadStream<S>:
107 ReturnInput,
108 [
109 Vec<u8>,
110 String,
111 ]:
112 HandleBytesToTokioAsyncRead,
113 }
114 }
115
116 cgp_preset! {
117 #[wrap_provider(UseInputDelegate)]
118 ToFuturesStreamHandlers {
119 <S> FuturesAsyncReadStream<S>:
120 PipeHandlers<Product![
121 FuturesToTokioAsyncRead,
122 AsyncReadToStream,
123 ]>,
124 <S> TokioAsyncReadStream<S>:
125 AsyncReadToStream,
126 [
127 Vec<u8>,
128 String,
129 ]:
130 HandleBytesToStream,
131 }
132 }
133}