-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbluesky.rs
More file actions
65 lines (58 loc) · 1.95 KB
/
Copy pathbluesky.rs
File metadata and controls
65 lines (58 loc) · 1.95 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
// This example demonstrates how to use Hypershell to stream data from a
// WebSocket and process it with CLI tools.
//
// The Hypershell program is defined as a `Program` type. It performs the
// following steps:
//
// 1. A `StreamingExec` handler is used to run `nix-shell` to provision
// the `websocat` utility. `websocat` then connects to the Bluesky
// WebSocket feed at `wss://jetstream1.us-west.bsky.network/subscribe`.
//
// 2. The streaming output from `websocat` is piped to a second `StreamingExec`
// handler, which runs `grep`. The `grep` command filters the stream
// for lines containing a `keyword`.
//
// 3. The `keyword` is a dynamic argument provided by the `keyword` field
// of the `MyApp` context, using `FieldArg<"keyword">`.
//
// 4. The final filtered output is piped to `StreamToStdout` to be printed
// on the console.
//
// The `MyApp` struct defines the context for the program, providing the
// `keyword` for `grep`. It inherits from `HypershellPreset` to get the
// necessary components for running CLI commands.
//
// The `main` function initializes the `MyApp` context with a keyword and
// runs the program.
#![recursion_limit = "256"]
use hypershell::prelude::*;
use hypershell::presets::HypershellPreset;
pub type Program = hypershell! {
StreamingExec<
StaticArg<"nix-shell">,
WithStaticArgs [
"-p",
"websocat",
"--run",
"websocat -nU wss://jetstream1.us-west.bsky.network/subscribe",
],
>
| StreamingExec<
StaticArg<"grep">,
WithArgs [ FieldArg<"keyword"> ],
>
| StreamToStdout
};
#[cgp_inherit(HypershellPreset)]
#[derive(HasField)]
pub struct MyApp {
pub keyword: String,
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let app = MyApp {
keyword: "love".to_owned(),
};
app.handle(PhantomData::<Program>, Vec::new()).await?;
Ok(())
}