1use clap::Parser;
2use jacquard::CowStr;
3use jacquard::api::app_bsky::feed::post::Post;
4use jacquard::client::{Agent, AgentSessionExt, FileAuthStore};
5use jacquard::oauth::client::OAuthClient;
6use jacquard::oauth::loopback::LoopbackConfig;
7use jacquard::richtext::RichText;
8use jacquard::types::string::Datetime;
9
10#[derive(Parser, Debug)]
11#[command(author, version, about = "Create a post with automatic facet detection")]
12struct Args {
13 /// Handle (e.g., alice.bsky.social), DID, or PDS URL
14 input: CowStr<'static>,
15
16 /// Post text (can include @mentions, #hashtags, URLs, and [markdown](links))
17 #[arg(short, long)]
18 text: String,
19
20 /// Path to auth store file (will be created if missing)
21 #[arg(long, default_value = "/tmp/jacquard-oauth-session.json")]
22 store: String,
23}
24
25#[tokio::main]
26async fn main() -> miette::Result<()> {
27 let args = Args::parse();
28
29 let oauth = OAuthClient::with_default_config(FileAuthStore::new(&args.store));
30 let session = oauth
31 .login_with_local_server(args.input, Default::default(), LoopbackConfig::default())
32 .await?;
33
34 let agent: Agent<_> = Agent::from(session);
35
36 // Parse richtext with automatic facet detection
37 // This detects @mentions, #hashtags, URLs, and [markdown](links)
38 let richtext = RichText::parse(&args.text).build_async(&agent).await?;
39
40 println!("Detected {} facets:", richtext.facets.as_ref().map(|f| f.len()).unwrap_or(0));
41 if let Some(facets) = &richtext.facets {
42 for facet in facets {
43 let text_slice = &richtext.text[facet.index.byte_start as usize..facet.index.byte_end as usize];
44 println!(" - \"{}\" ({:?})", text_slice, facet.features);
45 }
46 }
47
48 // Create post with parsed facets
49 let post = Post {
50 text: richtext.text,
51 facets: richtext.facets,
52 created_at: Datetime::now(),
53 embed: None,
54 entities: None,
55 labels: None,
56 langs: None,
57 reply: None,
58 tags: None,
59 extra_data: Default::default(),
60 };
61
62 let output = agent.create_record(post, None).await?;
63 println!("✓ Created post: {}", output.uri);
64
65 Ok(())
66}