You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/03/27 16:07:57 UTC

[incubator-opendal] branch main updated: feat(oli): implement `oli stat` (#1778)

This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 0fc67b6e feat(oli): implement `oli stat` (#1778)
0fc67b6e is described below

commit 0fc67b6e798124a1844ab0ad13731f7c1d047c6f
Author: Jian Zeng <an...@gmail.com>
AuthorDate: Tue Mar 28 00:07:51 2023 +0800

    feat(oli): implement `oli stat` (#1778)
    
    * feat(oli): implement `oli stat`
    
    Signed-off-by: Jian Zeng <an...@gmail.com>
    
    * chore: fix typo
    
    Signed-off-by: Jian Zeng <an...@gmail.com>
    
    * style: reword message
    
    Signed-off-by: Jian Zeng <an...@gmail.com>
    
    ---------
    
    Signed-off-by: Jian Zeng <an...@gmail.com>
---
 bin/oli/src/bin/oli.rs       |  4 +++
 bin/oli/src/commands/cli.rs  |  2 ++
 bin/oli/src/commands/mod.rs  |  1 +
 bin/oli/src/commands/stat.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+)

diff --git a/bin/oli/src/bin/oli.rs b/bin/oli/src/bin/oli.rs
index 32861b4e..09c4895f 100644
--- a/bin/oli/src/bin/oli.rs
+++ b/bin/oli/src/bin/oli.rs
@@ -81,6 +81,10 @@ async fn main() -> Result<()> {
             let cmd = oli::commands::rm::cli(new_cmd("orm")?);
             oli::commands::rm::main(&cmd.get_matches()).await?;
         }
+        Some("ostat") => {
+            let cmd = oli::commands::stat::cli(new_cmd("ostat")?);
+            oli::commands::stat::main(&cmd.get_matches()).await?;
+        }
         Some(v) => {
             println!("{v} is not supported")
         }
diff --git a/bin/oli/src/commands/cli.rs b/bin/oli/src/commands/cli.rs
index 7a531309..0eb2da48 100644
--- a/bin/oli/src/commands/cli.rs
+++ b/bin/oli/src/commands/cli.rs
@@ -26,6 +26,7 @@ pub async fn main(args: &ArgMatches) -> Result<()> {
         Some(("cp", sub_args)) => super::cp::main(sub_args).await?,
         Some(("ls", sub_args)) => super::ls::main(sub_args).await?,
         Some(("rm", sub_args)) => super::rm::main(sub_args).await?,
+        Some(("stat", sub_args)) => super::stat::main(sub_args).await?,
         _ => return Err(anyhow!("not handled")),
     }
 
@@ -39,4 +40,5 @@ pub fn cli(cmd: Command) -> Command {
         .subcommand(super::cp::cli(Command::new("cp")))
         .subcommand(super::ls::cli(Command::new("ls")))
         .subcommand(super::rm::cli(Command::new("rm")))
+        .subcommand(super::stat::cli(Command::new("stat")))
 }
diff --git a/bin/oli/src/commands/mod.rs b/bin/oli/src/commands/mod.rs
index 2e97d48d..749af022 100644
--- a/bin/oli/src/commands/mod.rs
+++ b/bin/oli/src/commands/mod.rs
@@ -38,3 +38,4 @@ pub mod cli;
 pub mod cp;
 pub mod ls;
 pub mod rm;
+pub mod stat;
diff --git a/bin/oli/src/commands/stat.rs b/bin/oli/src/commands/stat.rs
new file mode 100644
index 00000000..09ed32e8
--- /dev/null
+++ b/bin/oli/src/commands/stat.rs
@@ -0,0 +1,59 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::path::PathBuf;
+
+use anyhow::{anyhow, Result};
+use clap::{Arg, ArgMatches, Command};
+
+use crate::config::Config;
+
+pub async fn main(args: &ArgMatches) -> Result<()> {
+    let config_path = args
+        .get_one::<PathBuf>("config")
+        .ok_or_else(|| anyhow!("missing config path"))?;
+    let cfg = Config::load(config_path)?;
+
+    let target = args
+        .get_one::<String>("target")
+        .ok_or_else(|| anyhow!("missing target"))?;
+    let (op, path) = cfg.parse_location(target)?;
+
+    let meta = op.stat(&path).await?;
+    println!("path: {path}");
+    let size = meta.content_length();
+    println!("size: {size}");
+    if let Some(etag) = meta.etag() {
+        println!("etag: {etag}");
+    }
+    let file_type = meta.mode();
+    println!("type: {file_type}");
+    if let Some(content_type) = meta.content_type() {
+        println!("content-type: {content_type}");
+    }
+    if let Some(last_modified) = meta.last_modified() {
+        println!("last-modified: {last_modified}");
+    }
+
+    Ok(())
+}
+
+pub fn cli(cmd: Command) -> Command {
+    cmd.version("0.10.0")
+        .about("show object metadata")
+        .arg(Arg::new("target").required(true))
+}