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/25 09:57:01 UTC
[incubator-opendal] branch main updated: feat(oli): implement `oli cat` (#1759)
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 0069c92a feat(oli): implement `oli cat` (#1759)
0069c92a is described below
commit 0069c92af7f6a4380653caa01276776031ef03e9
Author: Jian Zeng <an...@gmail.com>
AuthorDate: Sat Mar 25 17:56:57 2023 +0800
feat(oli): implement `oli cat` (#1759)
* feat(oli): implement `oli cat`
Signed-off-by: Jian Zeng <an...@gmail.com>
* refactor: switch to tokio::io::copy
Signed-off-by: Jian Zeng <an...@gmail.com>
---------
Signed-off-by: Jian Zeng <an...@gmail.com>
---
bin/oli/Cargo.toml | 2 +-
bin/oli/src/bin/oli.rs | 4 ++++
bin/oli/src/commands/{cli.rs => cat.rs} | 33 +++++++++++++++++++++------------
bin/oli/src/commands/cli.rs | 2 ++
bin/oli/src/commands/mod.rs | 1 +
5 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/bin/oli/Cargo.toml b/bin/oli/Cargo.toml
index 6cc20ce7..012d05e1 100644
--- a/bin/oli/Cargo.toml
+++ b/bin/oli/Cargo.toml
@@ -56,7 +56,7 @@ futures = "0.3"
log = "0.4"
opendal = { version = "0.30", path = "../../core" }
serde = { version = "1", features = ["derive"] }
-tokio = { version = "1.26", features = ["fs", "macros", "rt-multi-thread"] }
+tokio = { version = "1.26", features = ["fs", "macros", "rt-multi-thread", "io-std"] }
toml = "0.7.3"
url = "2.3.1"
diff --git a/bin/oli/src/bin/oli.rs b/bin/oli/src/bin/oli.rs
index b3d58a8e..2e5a2f9d 100644
--- a/bin/oli/src/bin/oli.rs
+++ b/bin/oli/src/bin/oli.rs
@@ -65,6 +65,10 @@ async fn main() -> Result<()> {
let cmd = oli::commands::cli::cli(new_cmd("oli")?);
oli::commands::cli::main(&cmd.get_matches()).await?;
}
+ Some("ocat") => {
+ let cmd = oli::commands::cat::cli(new_cmd("ocat")?);
+ oli::commands::cat::main(&cmd.get_matches()).await?;
+ }
Some("ocp") => {
let cmd = oli::commands::cp::cli(new_cmd("ocp")?);
oli::commands::cp::main(&cmd.get_matches()).await?;
diff --git a/bin/oli/src/commands/cli.rs b/bin/oli/src/commands/cat.rs
similarity index 58%
copy from bin/oli/src/commands/cli.rs
copy to bin/oli/src/commands/cat.rs
index b29ee92b..6111a05d 100644
--- a/bin/oli/src/commands/cli.rs
+++ b/bin/oli/src/commands/cat.rs
@@ -15,24 +15,33 @@
// specific language governing permissions and limitations
// under the License.
-use anyhow::anyhow;
-use anyhow::Result;
-use clap::ArgMatches;
-use clap::Command;
+use std::path::PathBuf;
+
+use anyhow::{anyhow, Result};
+use clap::{Arg, ArgMatches, Command};
+use tokio::io;
+
+use crate::config::Config;
pub async fn main(args: &ArgMatches) -> Result<()> {
- match args.subcommand() {
- Some(("cp", sub_args)) => super::cp::main(sub_args).await?,
- Some(("ls", sub_args)) => super::ls::main(sub_args).await?,
- _ => return Err(anyhow!("not handled")),
- }
+ 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 mut reader = op.reader(path).await?;
+ let mut stdout = io::stdout();
+ io::copy(&mut reader, &mut stdout).await?;
Ok(())
}
pub fn cli(cmd: Command) -> Command {
cmd.version("0.10.0")
- .about("OpenDAL Command Line Interface")
- .subcommand(super::cp::cli(Command::new("cp")))
- .subcommand(super::ls::cli(Command::new("ls")))
+ .about("display object content")
+ .arg(Arg::new("target").required(true))
}
diff --git a/bin/oli/src/commands/cli.rs b/bin/oli/src/commands/cli.rs
index b29ee92b..d176583a 100644
--- a/bin/oli/src/commands/cli.rs
+++ b/bin/oli/src/commands/cli.rs
@@ -22,6 +22,7 @@ use clap::Command;
pub async fn main(args: &ArgMatches) -> Result<()> {
match args.subcommand() {
+ Some(("cat", sub_args)) => super::cat::main(sub_args).await?,
Some(("cp", sub_args)) => super::cp::main(sub_args).await?,
Some(("ls", sub_args)) => super::ls::main(sub_args).await?,
_ => return Err(anyhow!("not handled")),
@@ -33,6 +34,7 @@ pub async fn main(args: &ArgMatches) -> Result<()> {
pub fn cli(cmd: Command) -> Command {
cmd.version("0.10.0")
.about("OpenDAL Command Line Interface")
+ .subcommand(super::cat::cli(Command::new("cat")))
.subcommand(super::cp::cli(Command::new("cp")))
.subcommand(super::ls::cli(Command::new("ls")))
}
diff --git a/bin/oli/src/commands/mod.rs b/bin/oli/src/commands/mod.rs
index 1520c8fb..0347b404 100644
--- a/bin/oli/src/commands/mod.rs
+++ b/bin/oli/src/commands/mod.rs
@@ -33,6 +33,7 @@
//! }
//! ```
+pub mod cat;
pub mod cli;
pub mod cp;
pub mod ls;