Skip to content

Commit

Permalink
allow the specification of alt-text on images when using CLI.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterGrace committed Nov 14, 2024
1 parent 161493a commit 91c33b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions bsky-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub struct CreatePostArgs {
/// Images to embed
#[arg(short, long)]
pub(crate) images: Vec<PathBuf>,
/// Alt-Text for images
#[arg(short, long)]
pub(crate) alt_text: Vec<String>,
}

#[derive(Debug, Clone)]
Expand Down
19 changes: 13 additions & 6 deletions bsky-cli/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl Runner {
}
Command::CreatePost(args) => {
let mut images = Vec::new();
for image in &args.images {
for (idx,image) in args.images.iter().enumerate() {
if let Ok(mut file) = File::open(image).await {
let mut buf = Vec::new();
file.read_to_end(&mut buf).await.expect("read image file");
Expand All @@ -387,13 +387,20 @@ impl Runner {
.upload_blob(buf)
.await
.expect("upload blob");
images.push(
api::app::bsky::embed::images::ImageData {
alt: image
let alt= match args.alt_text.get(idx) {
Some(text) => text.to_owned(),
None => {
image
.file_name()
.map(OsStr::to_string_lossy)
.map(|s| s.to_string_lossy().into_owned())
.unwrap_or_default()
.into(),

}

};
images.push(
api::app::bsky::embed::images::ImageData {
alt,
aspect_ratio: None,
image: output.data.blob,
}
Expand Down

0 comments on commit 91c33b2

Please sign in to comment.