Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions crates/ov_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,18 @@ async fn main() {
}
}

/// Resolve a relative local path to absolute. Pass through URLs and raw content unchanged.
fn resolve_path(s: String) -> String {
let p = std::path::Path::new(&s);
if p.exists() {
std::fs::canonicalize(p)
.map(|abs| abs.to_string_lossy().into_owned())
.unwrap_or(s)
} else {
s
}
}

async fn handle_add_resource(
mut path: String,
to: Option<String>,
Expand Down Expand Up @@ -509,7 +521,7 @@ async fn handle_add_resource(

let client = ctx.get_client();
commands::resources::add_resource(
&client, &path, to, reason, instruction, wait, timeout, ctx.output_format, ctx.compact
&client, &resolve_path(path), to, reason, instruction, wait, timeout, ctx.output_format, ctx.compact
).await
}

Expand All @@ -521,7 +533,7 @@ async fn handle_add_skill(
) -> Result<()> {
let client = ctx.get_client();
commands::resources::add_skill(
&client, &data, wait, timeout, ctx.output_format, ctx.compact
&client, &resolve_path(data), wait, timeout, ctx.output_format, ctx.compact
).await
}

Expand Down Expand Up @@ -556,7 +568,7 @@ async fn handle_unlink(

async fn handle_export(uri: String, to: String, ctx: CliContext) -> Result<()> {
let client = ctx.get_client();
commands::pack::export(&client, &uri, &to, ctx.output_format, ctx.compact
commands::pack::export(&client, &uri, &resolve_path(to), ctx.output_format, ctx.compact
).await
}

Expand All @@ -569,7 +581,7 @@ async fn handle_import(
) -> Result<()> {
let client = ctx.get_client();
commands::pack::import(
&client, &file_path, &target_uri, force, no_vectorize, ctx.output_format, ctx.compact
&client, &resolve_path(file_path), &target_uri, force, no_vectorize, ctx.output_format, ctx.compact
).await
}

Expand Down
8 changes: 6 additions & 2 deletions openviking_cli/cli/commands/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
"""Import/export pack commands."""

from pathlib import Path

import typer

from openviking_cli.cli.errors import run
Expand All @@ -17,7 +19,8 @@ def export_command(
to: str = typer.Argument(..., help="Output .ovpack file path"),
) -> None:
"""Export context as .ovpack."""
run(ctx, lambda client: {"file": client.export_ovpack(uri, to)})
abs_to = str(Path(to).resolve())
run(ctx, lambda client: {"file": client.export_ovpack(uri, abs_to)})

@app.command("import")
def import_command(
Expand All @@ -32,11 +35,12 @@ def import_command(
),
) -> None:
"""Import .ovpack into target URI."""
abs_file_path = str(Path(file_path).resolve())
run(
ctx,
lambda client: {
"uri": client.import_ovpack(
file_path=file_path,
file_path=abs_file_path,
target=target_uri,
force=force,
vectorize=not no_vectorize,
Expand Down
12 changes: 10 additions & 2 deletions openviking_cli/cli/commands/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
from openviking_cli.cli.errors import run


def _resolve_path(value: str) -> str:
"""Resolve a relative local path to absolute. Pass through URLs and raw content."""
p = Path(value)
if p.exists():
return str(p.resolve())
return value


def register(app: typer.Typer) -> None:
"""Register resource commands."""

Expand Down Expand Up @@ -79,7 +87,7 @@ def add_resource_command(
run(
ctx,
lambda client: client.add_resource(
path=final_path,
path=_resolve_path(final_path),
target=to,
reason=reason,
instruction=instruction,
Expand All @@ -99,7 +107,7 @@ def add_skill_command(
run(
ctx,
lambda client: client.add_skill(
data=data,
data=_resolve_path(data),
wait=wait,
timeout=timeout,
),
Expand Down
Loading