Skip to content

Commit

Permalink
ll: list objects with details
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Yang committed Sep 7, 2019
1 parent 04c5bac commit bbb160d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "s3rs"
version = "0.2.5"
version = "0.2.6"
authors = ["Antonio Yang <[email protected]>"]
description = "A s3 cli client with multi configs with diffent provider"
keywords = ["S3", "Amazon", "ceph", "AWS"]
Expand Down Expand Up @@ -35,7 +35,7 @@ serde_json = "1.0"
regex = "0.2"
quick-xml = "0.12"
colored = "1.6"
s3handler = "0.2.6"
s3handler = "0.3.0"

# Patch for s3handler
# [patch.crates-io]
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ current status:
| ls | list all buckets | O | O |
| ls _bucket_ | list objects in the bucket | O | O |
| ls s3://_bucket_ | list objects in the bucket | O | O |
| ll s3://_bucket_ | list objects detail in the bucket | O | O |
| mb _bucket_ | create bucket | O | O |
| rb _bucket_ | delete bucket | O | O |
| put <file> s3://_bucket_/_object_ | upload the file | O | O |
Expand All @@ -40,6 +41,7 @@ current status:
| HIGH LEVEL COMMAND | INTEGRATE FUNCTIONS | CEPH | AWS |
|--------------------|------------------------------------------------------------------------------------------|------|-----|
| la | list all objects | O | O |
| ll | list all objects details | O | O |
| info s3://_bucket_ | acl(ceph, aws), location(ceph, aws), versioning(ceph, aws), uploads(ceph), version(ceph) | O | O |

| CEPH OPS API (use system keys) | CEPH ONLY FUNCTION |
Expand All @@ -65,7 +67,7 @@ current status:

# Download excutable binary
Download the link as follow and unzip
- https://github.com/yanganto/s3rs/releases/download/v0.2.4/s3rs-v0.2.4-linux.zip
- https://github.com/yanganto/s3rs/releases/download/v0.2.6/s3rs-v0.2.6-linux.zip

# Install via Crate.io
Install rust tools rustup and cargo
Expand Down
56 changes: 50 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ fn read_parse<T>(tty: &mut File, prompt: &str, min: T, max: T) -> io::Result<T>
where
T: FromStr + Ord,
{
tty.write_all(prompt.as_bytes());
let _ = tty.write_all(prompt.as_bytes());
let mut reader = io::BufReader::new(tty);
let mut result = String::new();
reader.read_line(&mut result);
let _ = reader.read_line(&mut result);
match result.replace("\n", "").parse::<T>() {
Ok(x) => {
if x >= min && x <= max {
Expand Down Expand Up @@ -218,7 +218,7 @@ fn main() {
command = match OpenOptions::new().read(true).write(true).open("/dev/tty") {
Ok(mut tty) => {
tty.flush().expect("Could not open tty");
tty.write_all(
let _ = tty.write_all(
format!("{} {} {} ", "s3rs".green(), login_user.cyan(), ">".green()).as_bytes(),
);
let reader = BufReader::new(&tty);
Expand All @@ -233,9 +233,46 @@ fn main() {

debug!("===== do command: {} =====", command);
if command.starts_with("la") {
print_if_error(handler.la());
match handler.la() {
Err(e) => println!("{}", e),
Ok(v) => {
for o in v {
debug!("{:?}", o);
println!("{}", String::from(o));
}
}
};
} else if command.starts_with("ls") {
print_if_error(handler.ls(command.split_whitespace().nth(1)));
match handler.ls(command.split_whitespace().nth(1)) {
Err(e) => println!("{}", e),
Ok(v) => {
for o in v {
debug!("{:?}", o);
println!("{}", String::from(o));
}
}
};
} else if command.starts_with("ll") {
let r = match command.split_whitespace().nth(1) {
Some(b) => handler.ls(Some(b)),
None => handler.la(),
};
match r {
Err(e) => println!("{}", e),
Ok(v) => {
println!("STORAGE CLASS\tMODIFIED TIME\t\t\tETAG\t\t\t\t\tKEY",);
for o in v {
debug!("{:?}", o);
println!(
"{}\t{}\t{}\t{}",
o.storage_class.clone().unwrap(),
o.mtime.clone().unwrap(),
o.etag.clone().unwrap(),
String::from(o)
);
}
}
};
} else if command.starts_with("put") {
match handler.put(
command.split_whitespace().nth(1).unwrap_or(""),
Expand Down Expand Up @@ -406,6 +443,12 @@ USAGE:
{1} {2}
list all objects of the bucket
{39}
list all object detail
{39} {2}
list all objects detail of the bucket
{3} {2}
create bucket
Expand Down Expand Up @@ -518,7 +561,8 @@ USAGE:
"Ctrl + d".bold(),
"list".bold(),
"usage".bold(),
"info".bold() //38
"info".bold(),
"ll".bold() //39
);
} else {
println!(
Expand Down

0 comments on commit bbb160d

Please sign in to comment.