Skip to content

Commit 268ab6e

Browse files
authored
feat: refactor cli (#607)
CLI refactor - Closes #413 - Closes #549 as OBE
1 parent 0ea1c8f commit 268ab6e

File tree

22 files changed

+660
-1263
lines changed

22 files changed

+660
-1263
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -43,68 +43,33 @@ jobs:
4343
run: cargo install cargo-all-features
4444
- name: Check
4545
run: cargo check-all-features
46-
test-api:
47-
name: Test stac-api
46+
test:
47+
name: Test
4848
runs-on: ubuntu-latest
49+
env:
50+
DUCKDB_LIB_DIR: /opt/duckdb
51+
DUCKDB_INCLUDE_DIR: /opt/duckdb
52+
LD_LIBRARY_PATH: /opt/duckdb
4953
steps:
5054
- uses: actions/checkout@v4
5155
- uses: Swatinem/rust-cache@v2
52-
- name: Test
53-
run: cargo test -p stac-api --all-features
54-
test-cli:
55-
name: Test stac-cli
56-
runs-on: ubuntu-latest
57-
defaults:
58-
run:
59-
working-directory: crates/cli
60-
steps:
61-
- uses: actions/checkout@v4
62-
- uses: Swatinem/rust-cache@v2
63-
- name: Test
64-
run: cargo test -p stac-cli
65-
test-cli-python:
66-
name: Test stacrs-cli (python)
67-
runs-on: ubuntu-latest
68-
defaults:
69-
run:
70-
working-directory: crates/cli
71-
steps:
72-
- uses: actions/checkout@v4
73-
- uses: Swatinem/rust-cache@v2
74-
- uses: actions/setup-python@v5
75-
with:
76-
python-version: 3.x
7756
- uses: astral-sh/setup-uv@v5
78-
with:
79-
enable-cache: true
80-
- name: Install
81-
run: uv sync
82-
- name: Smoke test
83-
run: uv run stacrs --version
84-
test-duckdb:
85-
name: Test stac-duckdb
86-
runs-on: ubuntu-latest
87-
steps:
88-
- uses: actions/checkout@v4
89-
- uses: Swatinem/rust-cache@v2
9057
- name: Get DuckDB
9158
run: |
9259
wget https://github.com/duckdb/duckdb/releases/download/v1.1.3/libduckdb-linux-amd64.zip
9360
unzip libduckdb-linux-amd64.zip -d /opt/duckdb
61+
- name: Fmt
62+
run: cargo fmt
63+
- name: Clippy
64+
run: cargo clippy --workspace --all-features
65+
- name: Build # need to build first to get the executable for CLI tests
66+
run: cargo build --all-features
9467
- name: Test
95-
run: cargo test -p stac-duckdb
96-
env:
97-
DUCKDB_LIB_DIR: /opt/duckdb
98-
DUCKDB_INCLUDE_DIR: /opt/duckdb
99-
LD_LIBRARY_PATH: /opt/duckdb
100-
test-extensions:
101-
name: Test stac-extensions
102-
runs-on: ubuntu-latest
103-
steps:
104-
- uses: actions/checkout@v4
105-
- uses: Swatinem/rust-cache@v2
106-
- name: Test
107-
run: cargo test -p stac-extensions
68+
run: cargo test --all-features
69+
- name: Validate stac-server
70+
run: uv run --group stac-api-validator scripts/validate-stac-server
71+
- name: Validate stac-geoparquet
72+
run: uv run --group stac-geoparquet scripts/validate-stac-geoparquet
10873
test-pgstac:
10974
name: Test pgstac
11075
runs-on: ubuntu-latest
@@ -113,6 +78,10 @@ jobs:
11378
pgstac_version:
11479
- v0.8.6
11580
- v0.9.1
81+
env:
82+
DUCKDB_LIB_DIR: /opt/duckdb
83+
DUCKDB_INCLUDE_DIR: /opt/duckdb
84+
LD_LIBRARY_PATH: /opt/duckdb
11685
services:
11786
pgstac:
11887
image: ghcr.io/stac-utils/pgstac:${{ matrix.pgstac_version }}
@@ -128,46 +97,15 @@ jobs:
12897
steps:
12998
- uses: actions/checkout@v4
13099
- uses: Swatinem/rust-cache@v2
131-
- uses: actions/setup-python@v5
132-
with:
133-
python-version: "3.10"
134100
- uses: astral-sh/setup-uv@v5
135-
with:
136-
enable-cache: true
101+
- name: Get DuckDB
102+
run: |
103+
wget https://github.com/duckdb/duckdb/releases/download/v1.1.3/libduckdb-linux-amd64.zip
104+
unzip libduckdb-linux-amd64.zip -d /opt/duckdb
137105
- name: Test
138106
run: cargo test -p pgstac --all-features
139-
- name: Install Python dependencies
140-
run: uv sync --group stac-api-validator
141-
- name: Validate
142-
run: uv run scripts/validate-stac-server --pgstac
143-
test-server:
144-
name: Test stac-server
145-
runs-on: ubuntu-latest
146-
steps:
147-
- uses: actions/checkout@v4
148-
- uses: Swatinem/rust-cache@v2
149-
- uses: actions/setup-python@v5
150-
with:
151-
python-version: "3.x"
152-
- uses: astral-sh/setup-uv@v5
153-
with:
154-
enable-cache: true
155-
- name: Test
156-
run: cargo test -p stac-server --all-features
157-
- name: Install Python dependencies
158-
run: uv sync --group stac-api-validator
159107
- name: Validate
160-
run: uv run scripts/validate-stac-server
161-
lint:
162-
name: Lint
163-
runs-on: ubuntu-latest
164-
steps:
165-
- uses: actions/checkout@v4
166-
- uses: Swatinem/rust-cache@v2
167-
- name: Fmt
168-
run: cargo fmt
169-
- name: Clippy
170-
run: cargo clippy --workspace --all-features
108+
run: uv run --group stac-api-validator scripts/validate-stac-server --pgstac
171109
check-nightly:
172110
name: Check (nightly)
173111
runs-on: ubuntu-latest
@@ -195,19 +133,3 @@ jobs:
195133
- uses: DavidAnson/markdownlint-cli2-action@v19
196134
- name: Doc
197135
run: cargo doc --workspace --all-features
198-
validate-stac-geoparquet:
199-
name: Validate stac-geoparquet
200-
runs-on: ubuntu-latest
201-
steps:
202-
- uses: actions/checkout@v4
203-
- uses: Swatinem/rust-cache@v2
204-
- uses: actions/setup-python@v5
205-
with:
206-
python-version: "3.x"
207-
- uses: astral-sh/setup-uv@v5
208-
with:
209-
enable-cache: true
210-
- name: Install Python dependencies
211-
run: uv sync --group stac-geoparquet
212-
- name: Validate
213-
run: uv run scripts/validate-stac-geoparquet

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ default-members = [
1515
"crates/cli",
1616
"crates/core",
1717
"crates/derive",
18+
"crates/duckdb",
1819
"crates/extensions",
20+
"crates/server",
1921
]
2022

2123
[workspace.package]
@@ -28,6 +30,7 @@ categories = ["science", "data-structures"]
2830
rust-version = "1.82"
2931

3032
[workspace.dependencies]
33+
anyhow = "1.0"
3134
arrow = "53.1.0"
3235
arrow-array = "53.1.0"
3336
arrow-cast = "53.1.0"

crates/api/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
### Added
1010

1111
- kwargs to Python search build ([#591](https://github.com/stac-utils/stac-rs/pull/591))
12+
- `client::search` function ([#607](https://github.com/stac-utils/stac-rs/pull/607))
1213

1314
## [0.7.0] - 2025-01-02
1415

crates/api/src/client.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,40 @@ use tokio::{
1717

1818
const DEFAULT_CHANNEL_BUFFER: usize = 4;
1919

20+
/// Searches a STAC API.
21+
pub async fn search(
22+
href: &str,
23+
mut search: Search,
24+
max_items: Option<usize>,
25+
) -> Result<ItemCollection> {
26+
let client = Client::new(href)?;
27+
if search.limit.is_none() {
28+
if let Some(max_items) = max_items {
29+
search.limit = Some(max_items.try_into()?);
30+
}
31+
}
32+
let stream = client.search(search).await.unwrap();
33+
let mut items = if let Some(max_items) = max_items {
34+
if max_items == 0 {
35+
return Ok(ItemCollection::default());
36+
}
37+
Vec::with_capacity(max_items)
38+
} else {
39+
Vec::new()
40+
};
41+
pin_mut!(stream);
42+
while let Some(item) = stream.next().await {
43+
let item = item?;
44+
items.push(item);
45+
if let Some(max_items) = max_items {
46+
if items.len() >= max_items {
47+
break;
48+
}
49+
}
50+
}
51+
ItemCollection::new(items)
52+
}
53+
2054
/// A client for interacting with STAC APIs.
2155
#[derive(Clone, Debug)]
2256
pub struct Client {

crates/cli/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- Pretty big code refactor and a lot of options ([#607](https://github.com/stac-utils/stac-rs/pull/607))
12+
913
## [0.4.1] - 2024-10-22
1014

1115
### Changed

crates/cli/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ rust-version.workspace = true
1313

1414
[features]
1515
default = ["pgstac"]
16-
duckdb = ["dep:stac-duckdb"]
1716
pgstac = ["stac-server/pgstac", "dep:tokio-postgres"]
1817
python = ["dep:pyo3", "pgstac"]
1918

2019
[dependencies]
20+
anyhow.workspace = true
2121
axum.workspace = true
2222
clap = { workspace = true, features = ["derive"] }
2323
object_store.workspace = true
@@ -32,7 +32,7 @@ stac = { workspace = true, features = [
3232
"validate",
3333
] }
3434
stac-api = { workspace = true, features = ["client"] }
35-
stac-duckdb = { workspace = true, optional = true }
35+
stac-duckdb.workspace = true
3636
stac-server = { workspace = true, features = ["axum"] }
3737
thiserror.workspace = true
3838
tokio = { workspace = true, features = [
@@ -49,7 +49,7 @@ url.workspace = true
4949

5050
[dev-dependencies]
5151
assert_cmd.workspace = true
52-
tokio-test.workspace = true
52+
rstest.workspace = true
5353

5454
[lib]
5555
crate-type = ["lib", "cdylib"]

0 commit comments

Comments
 (0)