feat: improve list command

This commit is contained in:
2025-05-16 21:56:47 +02:00
parent 34e98b5702
commit 75b9b52e25
7 changed files with 62 additions and 5 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

4
.idea/encodings.xml generated Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -0,0 +1,5 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
</profile>
</component>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/pastebin-cli.iml" filepath="$PROJECT_DIR$/.idea/pastebin-cli.iml" />
</modules>
</component>
</project>

11
.idea/pastebin-cli.iml generated Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -4,7 +4,6 @@ use clap::{Parser, Subcommand};
use std::fs;
use std::path::PathBuf;
mod keys;
mod pastebin;
@@ -79,17 +78,33 @@ async fn list(max_results: Option<u16>) {
let line = "-".repeat(5);
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 {
let mut title = paste.paste_title;
if title == "" {
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 newdate = datetime.format("%Y-%m-%d %H:%M:%S");
let datetime = DateTime::from_timestamp(paste.paste_date.into(), 0).unwrap();
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
}