mirror of
https://github.com/Tilo-K/pastebin-cli.git
synced 2026-01-10 17:01:01 +00:00
feat: improve list command
This commit is contained in:
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal 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
4
.idea/encodings.xml
generated
Normal 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>
|
||||||
5
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
5
.idea/inspectionProfiles/Project_Default.xml
generated
Normal 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
8
.idea/modules.xml
generated
Normal 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
11
.idea/pastebin-cli.iml
generated
Normal 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
6
.idea/vcs.xml
generated
Normal 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>
|
||||||
25
src/main.rs
25
src/main.rs
@@ -4,7 +4,6 @@ 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 +78,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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user