Skip to content

Commit cbe8245

Browse files
committed
Improve styling for help message
Filter full path in object names in the UI Fix a bug that put bucket stats take up entire columns
1 parent 51dc4ba commit cbe8245

File tree

4 files changed

+53
-15
lines changed

4 files changed

+53
-15
lines changed

src/squire/constant.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::env;
22

33
/// Struct to store the cargo information gathered at compile time using the `env!` macro.
4+
#[allow(dead_code)]
45
#[derive(Debug, Clone)]
56
pub struct MetaData {
67
pub crate_name: String,

src/squire/parser.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,22 @@ pub fn arguments(
2727
while i < args.len() {
2828
match args[i].as_str() {
2929
"-h" | "--help" => {
30-
let helper = "lists3 takes the following arguments\n\n\
31-
--bucket/-b: Bucket name for which listing has to be created\tMANDATORY!!\n\
32-
--region/-r: Region name where the bucket is present\t\tFallback: Default Region\n\
33-
--filter/-f: S3 prefix to filter (eg: '[\"github/\"]')\tFallback: []\n\
34-
--ignore/-i: Objects to be ignored (eg: '[\"github/.DS_Store\"]')\tFallback: []\n\
35-
--object/-o: Object name to upload in s3 (eg: list.html)\tFallback: list\n\
36-
--proxy/-p: Proxy server's path (eg: https://example.com/proxy)\tFallback: https://jarvis.vigneshrao.com/proxy\n\
37-
--style/-s: Styling for the UI (eg: vanilla)\tFallback: bootstrap\n\
38-
--version/-v/-V: Get the package version.\n".to_string();
39-
println!("Usage: {} [OPTIONS]\n\n{}", args[0], helper);
30+
let options: Vec<_> = vec![
31+
("--bucket | -b", "Bucket name for which listing has to be created"),
32+
("--region | -r", "Region name where the bucket is present"),
33+
("--filter | -f", "S3 prefix to filter (eg: '[\"github/\"]')"),
34+
("--ignore | -i", "Objects to be ignored (eg: '[\"github/.DS_Store\"]')"),
35+
("--object | -o", "Object name to upload in s3 (eg: list.html)"),
36+
("--proxy | -p", "Proxy server's path (eg: https://example.com/proxy)"),
37+
("--style | -s", "Styling for the UI (eg: vanilla)"),
38+
("--version | -v", "Get the package version.")
39+
].iter().cloned().collect();
40+
let longest_key = options.iter().map(|(k, _)| k.len()).max().unwrap_or(0);
41+
let pretext = "\n* ";
42+
let choices: String = options.iter().map(|(k, v)| {
43+
format!("{}{} {}→ {}", pretext, k, "·".repeat(longest_key - k.len() + 8), v)
44+
}).collect::<Vec<_>>().join("");
45+
println!("Usage: {} [OPTIONS]\n\nlists3 takes the following arguments\n{}", args[0], choices);
4046
exit(0)
4147
}
4248
"-V" | "-v" | "--version" => {

src/templates/list_bootstrap.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn get_content() -> String {
2525
position: absolute;
2626
top: 3%;
2727
right: 1px;
28-
bottom: 3%;
28+
bottom: 97%;
2929
display: inline-flex;
3030
}
3131
@@ -174,6 +174,22 @@ pub fn get_content() -> String {
174174
}
175175
</script>
176176
<script>
177+
// Mask the full path in 'Object Name' column to improve readability
178+
// This functionality is available only for objects filtered with `--filter` flag
179+
function maskPath(objectName, folderNames) {
180+
let stripped = objectName;
181+
for (let folder of folderNames) {
182+
if (objectName.startsWith(folder)) {
183+
stripped = objectName.slice(folder.length);
184+
break;
185+
}
186+
}
187+
if (stripped.startsWith('/')) {
188+
stripped = stripped.slice(1);
189+
}
190+
return stripped;
191+
}
192+
177193
function renderTable(bucketName, regionName, folderNames, ignoreObjects, proxyServer) {
178194
let pretext = document.getElementById('pretext');
179195
pretext.innerHTML = "Amazon S3 Bucket list v2";
@@ -194,7 +210,7 @@ pub fn get_content() -> String {
194210
rowData.forEach(function (cellData, i) {
195211
const td = jQuery('<td>');
196212
if (i === 0) {
197-
td.html(`<a href="${cellData}">${cellData}</a>`);
213+
td.html(`<a href="${cellData}">${maskPath(cellData, folderNames)}</a>`);
198214
} else if (i === 1) {
199215
td.text(sizeConverter(cellData));
200216
} else {

src/templates/list_vanilla.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn get_content() -> String {
1818
position: absolute;
1919
top: 3%;
2020
right: 1px;
21-
bottom: 3%;
21+
bottom: 97%;
2222
display: inline-flex;
2323
}
2424
@@ -152,6 +152,22 @@ pub fn get_content() -> String {
152152
return filteredFiles;
153153
}
154154
155+
// Mask the full path in 'Object Name' column to improve readability
156+
// This functionality is available only for objects filtered with `--filter` flag
157+
function maskPath(objectName, folderNames) {
158+
let stripped = objectName;
159+
for (let folder of folderNames) {
160+
if (objectName.startsWith(folder)) {
161+
stripped = objectName.slice(folder.length);
162+
break;
163+
}
164+
}
165+
if (stripped.startsWith('/')) {
166+
stripped = stripped.slice(1);
167+
}
168+
return stripped;
169+
}
170+
155171
function handleList(folderNames, ignoreObjects) {
156172
if (http.readyState === 4) { // Finished loading the response
157173
let response = http.responseXML;
@@ -189,7 +205,7 @@ pub fn get_content() -> String {
189205
let storageCell = document.createElement('td');
190206
storageCell.innerHTML = storage;
191207
let nameCell = document.createElement('td');
192-
nameCell.innerHTML = "<a href=\"" + name + "\">" + name + "</a>";
208+
nameCell.innerHTML = "<a href=\"" + name + "\">" + maskPath(name, folderNames) + "</a>";
193209
row.appendChild(sizeCell);
194210
row.appendChild(lastmodCell);
195211
row.appendChild(storageCell);
@@ -297,7 +313,6 @@ pub fn get_content() -> String {
297313
window.location.href = "?sort=storage&sortdir=" + getNextSortDir('storage');
298314
}
299315
300-
301316
</script>
302317
<style>
303318
table {

0 commit comments

Comments
 (0)