Co-authored-by: Tilo <Tilo-K@users.noreply.github.com>
Co-authored-by: Tilo-K <tiloklarenbeek@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
Tilo
2025-05-16 22:11:32 +02:00
committed by GitHub
parent f5b49e2b86
commit 50e663f88d
3 changed files with 485 additions and 182 deletions

612
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "pastebin-cli" name = "pastebin-cli"
version = "0.1.7" version = "0.1.8"
edition = "2021" edition = "2021"
description = "A simple CLI for pastebin.com" description = "A simple CLI for pastebin.com"
authors = ["Tilo K"] authors = ["Tilo K"]
@@ -17,15 +17,15 @@ eula = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
anyhow = "1.0.75" anyhow = "1.0.98"
chrono = "0.4.31" chrono = "0.4.41"
clap = { version = "4.4.6", features = ["derive"] } clap = { version = "4.5.38", features = ["derive"] }
home = "0.5.5" home = "0.5.11"
quick-xml = { version = "0.31.0", features = ["serde", "serialize"] } quick-xml = { version = "0.37.5", features = ["serde", "serialize"] }
reqwest = { version = "0.11.22", features = ["json"] } reqwest = { version = "0.12.15", features = ["json"] }
rpassword = "7.2.0" rpassword = "7.4.0"
serde = { version = "1.0.189", features = ["serde_derive", "derive"] } serde = { version = "1.0.219", features = ["serde_derive", "derive"] }
tokio = { version = "1.33.0", features = ["full"] } tokio = { version = "1.45.0", features = ["full"] }
# The profile that 'cargo dist' will build with # The profile that 'cargo dist' will build with
[profile.dist] [profile.dist]
@@ -41,7 +41,12 @@ ci = "github"
# The installers to generate for each app # The installers to generate for each app
installers = ["shell", "powershell", "npm", "homebrew", "msi"] installers = ["shell", "powershell", "npm", "homebrew", "msi"]
# Target platforms to build apps for (Rust target-triple syntax) # Target platforms to build apps for (Rust target-triple syntax)
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-pc-windows-msvc"] targets = [
"aarch64-apple-darwin",
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
]
# The archive format to use for windows builds (defaults .zip) # The archive format to use for windows builds (defaults .zip)
windows-archive = ".tar.gz" windows-archive = ".tar.gz"
# The archive format to use for non-windows builds (defaults .tar.xz) # The archive format to use for non-windows builds (defaults .tar.xz)

View File

@@ -1,10 +1,8 @@
use chrono::prelude::*;
use chrono::DateTime; use chrono::DateTime;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
mod keys; mod keys;
mod pastebin; mod pastebin;
@@ -79,17 +77,33 @@ async fn list(max_results: Option<u16>) {
let line = "-".repeat(5); let line = "-".repeat(5);
println!("{}Top {} pastes{}", line, max_results.unwrap_or(10), line); println!("{}Top {} pastes{}", line, max_results.unwrap_or(10), line);
let mut max_length = 8;
let max = resp.iter().map(|paste| paste.paste_title.len()).max();
if max.is_some() {
if max.unwrap() > max_length {
max_length = max.unwrap();
}
}
for paste in resp { for paste in resp {
let mut title = paste.paste_title; let mut title = paste.paste_title;
if title == "" { if title == "" {
title = "Untitled".to_owned(); title = "Untitled".to_owned();
} }
let naive = NaiveDateTime::from_timestamp_opt(paste.paste_date.into(), 0).unwrap(); title = pad_string(&title, max_length);
let datetime: DateTime<Utc> = DateTime::from_utc(naive, Utc); let datetime = DateTime::from_timestamp(paste.paste_date.into(), 0).unwrap();
let newdate = datetime.format("%Y-%m-%d %H:%M:%S"); let formatted_date = datetime.format("%Y-%m-%d %H:%M:%S");
println!("{}\t{}\t{}", title, newdate, paste.paste_url); println!("{}\t{}\t{}", title, formatted_date, paste.paste_url);
} }
} }
fn pad_string(s: &str, length: usize) -> String {
let mut s = s.to_owned();
while s.len() < length {
s.push(' ');
}
s
}