Skip to content

Commit

Permalink
Merge branch 'main' into scan-async-iter
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice authored Oct 23, 2024
2 parents dc2c4f3 + c230c8a commit 024091e
Show file tree
Hide file tree
Showing 36 changed files with 1,149 additions and 323 deletions.
3 changes: 3 additions & 0 deletions .devcontainer/post_create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ opam install -y dune ounit2 ocamlformat

# Setup for Cpp binding
sudo apt install -y ninja-build

# Setup for D binding
sudo apt install -y dmd dub
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ integrations export-ignore

bindings/c export-ignore
bindings/cpp export-ignore
bindings/d export-ignore
bindings/dotnet export-ignore
bindings/go export-ignore
bindings/haskell export-ignore
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/ci_bindings_d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 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.

name: Bindings D CI

on:
push:
branches:
- main
tags:
- "*"
pull_request:
branches:
- main
paths:
- "core/**"
- "bindings/c/**"
- "bindings/d/**"
- ".github/workflows/ci_bindings_d.yml"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test:
strategy:
matrix:
# dmd: base (self-hosting) compiler (frontend & backend)
# ldc2/ldmd2: (dmd-frontend + LLVM backend) - recommended for MacOS ARM64
dlang: ["ldc-latest", "dmd-latest"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dlang-community/setup-dlang@v2
with:
compiler: ${{ matrix.dlang }}

- name: Setup Rust toolchain
uses: ./.github/actions/setup

- name: Build D binding
working-directory: bindings/d
run: dub build

- name: Check diff
run: git diff --exit-code

- name: Check
working-directory: bindings/d
run: dub lint

- name: Run tests
working-directory: bindings/d
run: dub test && cd test && dub
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ extend-exclude = [
# Generated pnpm locks.
"website/pnpm-lock.yaml",
"CHANGELOG.md",
# dscanner config
"bindings/d/dscanner.ini",
]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ OpenDAL offers a unified data access layer, empowering users to seamlessly and e
| [Rust Core] | [![Rust Core Image]][Rust Core Link] | [![Docs Release]][Rust Core Release Docs] [![Docs Dev]][Rust Core Dev Docs] |
| [C Binding] | - | [![Docs Dev]][C Binding Dev Docs] |
| [Cpp Binding] | - | [![Docs Dev]][Cpp Binding Dev Docs] |
| [D Binding] | - | - |
| [Dotnet Binding] | - | - |
| [Go Binding] | [![Go Binding Image]][Go Binding Link] | [![Docs Release]][Go Release Docs] |
| [Haskell Binding] | - | - |
Expand All @@ -38,6 +39,7 @@ OpenDAL offers a unified data access layer, empowering users to seamlessly and e
[C Binding Dev Docs]: https://opendal.apache.org/docs/c/
[Cpp Binding]: bindings/cpp/README.md
[Cpp Binding Dev Docs]: https://opendal.apache.org/docs/cpp/
[D Binding]: bindings/d/README.md
[Dotnet Binding]: bindings/dotnet/README.md
[Go Binding]: bindings/go/README.md
[Go Binding Image]: https://badge.fury.io/go/github.com%2Fapache%2Fopendal%2Fbindings%2Fgo.svg
Expand Down
15 changes: 14 additions & 1 deletion bin/oli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/oli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ services-sled = ["opendal/services-sled"]

[dependencies]
anyhow = "1"
clap = { version = "4", features = ["cargo", "string"] }
clap = { version = "4", features = ["cargo", "string", "derive", "deprecated"] }
dirs = "5.0.1"
futures = "0.3"
opendal = { version = "0.50.0", path = "../../core", features = [
Expand Down
51 changes: 18 additions & 33 deletions bin/oli/src/bin/oli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,13 @@ use std::path::PathBuf;

use anyhow::anyhow;
use anyhow::Result;
use clap::value_parser;
use clap::Arg;
use clap::Command;
use dirs::config_dir;
use oli::commands::OliSubcommand;

fn new_cmd(name: &'static str) -> Result<Command> {
let d = config_dir().ok_or_else(|| anyhow!("unknown config dir"))?;
let default_config_path = d.join("oli/config.toml").as_os_str().to_owned();

Ok(Command::new(name)
.version(env!("CARGO_PKG_VERSION"))
.arg(
Arg::new("config")
.long("config")
.help("Path to the config file")
.global(true)
.default_value(default_config_path)
.value_parser(value_parser!(PathBuf))
.required(false),
)
.subcommand_required(true)
.arg_required_else_help(true))
#[derive(Debug, clap::Parser)]
#[command(about, version)]
pub struct Oli {
#[command(subcommand)]
subcommand: OliSubcommand,
}

#[tokio::main]
Expand All @@ -66,28 +51,28 @@ async fn main() -> Result<()> {
.and_then(OsStr::to_str)
{
Some("oli") => {
let cmd = oli::commands::cli::cli(new_cmd("oli")?);
oli::commands::cli::main(&cmd.get_matches()).await?;
let cmd: Oli = clap::Parser::parse();
cmd.subcommand.run().await?;
}
Some("ocat") => {
let cmd = oli::commands::cat::cli(new_cmd("ocat")?);
oli::commands::cat::main(&cmd.get_matches()).await?;
let cmd: oli::commands::cat::CatCmd = clap::Parser::parse();
cmd.run().await?;
}
Some("ocp") => {
let cmd = oli::commands::cp::cli(new_cmd("ocp")?);
oli::commands::cp::main(&cmd.get_matches()).await?;
let cmd: oli::commands::cp::CopyCmd = clap::Parser::parse();
cmd.run().await?;
}
Some("ols") => {
let cmd = oli::commands::ls::cli(new_cmd("ols")?);
oli::commands::ls::main(&cmd.get_matches()).await?;
let cmd: oli::commands::ls::LsCmd = clap::Parser::parse();
cmd.run().await?;
}
Some("orm") => {
let cmd = oli::commands::rm::cli(new_cmd("orm")?);
oli::commands::rm::main(&cmd.get_matches()).await?;
let cmd: oli::commands::rm::RmCmd = clap::Parser::parse();
cmd.run().await?;
}
Some("ostat") => {
let cmd = oli::commands::stat::cli(new_cmd("ostat")?);
oli::commands::stat::main(&cmd.get_matches()).await?;
let cmd: oli::commands::stat::StatCmd = clap::Parser::parse();
cmd.run().await?;
}
Some(v) => {
println!("{v} is not supported")
Expand Down
53 changes: 26 additions & 27 deletions bin/oli/src/commands/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,38 @@
// specific language governing permissions and limitations
// under the License.

use std::path::PathBuf;

use anyhow::anyhow;
use anyhow::Result;
use clap::Arg;
use clap::ArgMatches;
use clap::Command;
use futures::io;

use crate::config::Config;
use crate::params::config::ConfigParams;

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)?;
#[derive(Debug, clap::Parser)]
#[command(
name = "cat",
about = "Display object content",
disable_version_flag = true
)]
pub struct CatCmd {
#[command(flatten)]
pub config_params: ConfigParams,
#[arg()]
pub target: String,
}

let target = args
.get_one::<String>("target")
.ok_or_else(|| anyhow!("missing target"))?;
let (op, path) = cfg.parse_location(target)?;
impl CatCmd {
pub async fn run(&self) -> Result<()> {
let cfg = Config::load(&self.config_params.config)?;

let reader = op.reader(&path).await?;
let meta = op.stat(&path).await?;
let mut buf_reader = reader
.into_futures_async_read(0..meta.content_length())
.await?;
let mut stdout = io::AllowStdIo::new(std::io::stdout());
io::copy_buf(&mut buf_reader, &mut stdout).await?;
Ok(())
}
let (op, path) = cfg.parse_location(&self.target)?;

pub fn cli(cmd: Command) -> Command {
cmd.about("display object content")
.arg(Arg::new("target").required(true))
let reader = op.reader(&path).await?;
let meta = op.stat(&path).await?;
let mut buf_reader = reader
.into_futures_async_read(0..meta.content_length())
.await?;
let mut stdout = io::AllowStdIo::new(std::io::stdout());
io::copy_buf(&mut buf_reader, &mut stdout).await?;
Ok(())
}
}
47 changes: 0 additions & 47 deletions bin/oli/src/commands/cli.rs

This file was deleted.

Loading

0 comments on commit 024091e

Please sign in to comment.