-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhttp_checksum_cli.rs
More file actions
68 lines (63 loc) · 1.84 KB
/
http_checksum_cli.rs
File metadata and controls
68 lines (63 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// This example demonstrates how to create a streaming pipeline using only
// external CLI commands.
//
// The Hypershell program is defined as a `Program` type. It is equivalent to
// the following shell command:
//
// curl $url | sha256sum | cut -d ' ' -f 1
//
// The pipeline consists of the following steps:
//
// 1. A `StreamingExec` handler runs `curl` to fetch the content from a URL.
// The URL is provided dynamically from the `url` field of the `MyApp`
// context.
//
// 2. The output of `curl` is streamed to a second `StreamingExec` handler,
// which runs `sha256sum` to compute the SHA256 checksum of the stream.
//
// 3. The output of `sha256sum` (e.g., "checksum filename") is streamed to a
// third `StreamingExec` handler, which runs `cut` to extract only the
// checksum part.
//
// 4. The final result is piped to `StreamToStdout` to be printed to the
// console.
//
// The `MyApp` context provides the `url` field required by the `curl` command.
//
// The `main` function initializes `MyApp` with a URL and executes the program.
use hypershell::prelude::*;
pub type Program = hypershell! {
StreamingExec<
StaticArg<"curl">,
WithArgs [
FieldArg<"url">,
],
>
| StreamingExec<
StaticArg<"sha256sum">,
WithStaticArgs [],
>
| StreamingExec<
StaticArg<"cut">,
WithStaticArgs [
"-d",
" ",
"-f",
"1",
],
>
| StreamToStdout
};
#[cgp_inherit(HypershellPreset)]
#[derive(HasField)]
pub struct MyApp {
pub url: String,
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let app = MyApp {
url: "https://nixos.org/manual/nixpkgs/unstable/".to_owned(),
};
app.handle(PhantomData::<Program>, Vec::new()).await?;
Ok(())
}