Skip to content

Commit

Permalink
implement create-remote for 0.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gschoeni committed Aug 21, 2024
1 parent aac09da commit ca172a4
Show file tree
Hide file tree
Showing 47 changed files with 659 additions and 369 deletions.
3 changes: 2 additions & 1 deletion src/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "oxen-cli"
version = "0.18.12"
version = "0.19.0"
edition = "2021"

[dependencies]
async-trait = "0.1.80"
bytesize = "1.1.0"
clap = { version = "4.2.7", features = ["cargo"] }
colored = "2.0.0"
dialoguer = "0.11.0"
dunce = "1"
env_logger = "0.11.3"
jwalk = "0.8.1"
Expand Down
3 changes: 3 additions & 0 deletions src/cli/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub use create_remote::CreateRemoteCmd;
pub mod db;
pub use db::DbCmd;

pub mod delete_remote;
pub use delete_remote::DeleteRemoteCmd;

pub mod df;
pub use df::DFCmd;

Expand Down
82 changes: 82 additions & 0 deletions src/cli/src/cmd/delete_remote.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
use async_trait::async_trait;
use clap::{Arg, Command};

use dialoguer::Confirm;
use liboxen::api;
use liboxen::constants::DEFAULT_HOST;
use liboxen::error::OxenError;

use crate::cmd::RunCmd;
pub const NAME: &str = "delete-remote";
pub struct DeleteRemoteCmd;

#[async_trait]
impl RunCmd for DeleteRemoteCmd {
fn name(&self) -> &str {
NAME
}

fn args(&self) -> Command {
// Setups the CLI args for the command
Command::new(NAME)
.about("Deletes a remote repository with the name on the host. Default behavior is to delete a remote on the hub.oxen.ai remote.")
.arg(
Arg::new("name")
.long("name")
.short('n')
.help("The namespace/name of the remote repository you want to create. For example: 'ox/my_repo'")
.required(true)
.action(clap::ArgAction::Set),
)
.arg(
Arg::new("host")
.long("host")
.help("The host you want to create the remote repository on. For example: 'hub.oxen.ai'")
.action(clap::ArgAction::Set),
)
}

async fn run(&self, args: &clap::ArgMatches) -> Result<(), OxenError> {
// Parse Args
let Some(namespace_name) = args.get_one::<String>("name") else {
return Err(OxenError::basic_str(
"Must supply a namespace/name for the remote repository.",
));
};
// Default the host to the oxen.ai hub
let host = args
.get_one::<String>("host")
.map(String::from)
.unwrap_or(DEFAULT_HOST.to_string());

let Some(remote_repo) =
api::client::repositories::get_by_name_and_host(namespace_name, host).await?
else {
return Err(OxenError::basic_str(format!(
"Remote repository not found: {namespace_name}"
)));
};

// Confirm the user wants to delete the remote repository
match Confirm::new()
.with_prompt(format!(
"Are you sure you want to delete the remote repository: {namespace_name}?"
))
.interact()
{
Ok(true) => {
api::client::repositories::delete(&remote_repo).await?;
}
Ok(false) => {
return Ok(());
}
Err(e) => {
return Err(OxenError::basic_str(format!(
"Error confirming deletion: {e}"
)));
}
}

Ok(())
}
}
4 changes: 2 additions & 2 deletions src/cli/src/cmd/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use liboxen::error::OxenError;
use liboxen::model::LocalRepository;
use std::env;

use liboxen::command;
use liboxen::repositories;

use crate::helpers::{
check_remote_version, check_remote_version_blocking, check_repo_migration_needed,
Expand Down Expand Up @@ -76,7 +76,7 @@ impl RunCmd for PushCmd {
check_remote_version_blocking(host.clone()).await?;
check_remote_version(host).await?;

command::push_remote_branch(&repository, remote, branch).await?;
repositories::push::push_remote_branch(&repository, remote, branch).await?;
Ok(())
}
}
Expand Down
1 change: 1 addition & 0 deletions src/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async fn main() -> ExitCode {
Box::new(cmd::ConfigCmd),
Box::new(cmd::CreateRemoteCmd),
Box::new(cmd::DbCmd),
Box::new(cmd::DeleteRemoteCmd),
Box::new(cmd::DFCmd),
Box::new(cmd::DiffCmd),
Box::new(cmd::DownloadCmd),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "liboxen"
version = "0.18.12"
version = "0.19.0"
edition = "2021"
license-file = "LICENSE"
description = "Oxen is a fast, unstructured data version control, to help version datasets, written in Rust."
Expand Down
20 changes: 12 additions & 8 deletions src/lib/src/api/client/branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,19 @@ mod tests {
let remote_repo = test::create_remote_repo(&repo).await?;

// Push it
command::push(&repo).await?;
repositories::push(&repo).await?;

// Create new branch
let new_branch_name = "my-branch";
repositories::branches::create_checkout(&repo, new_branch_name)?;

// Push new branch
command::push_remote_branch(&repo, constants::DEFAULT_REMOTE_NAME, new_branch_name)
.await?;
repositories::push::push_remote_branch(
&repo,
constants::DEFAULT_REMOTE_NAME,
new_branch_name,
)
.await?;

// Delete the branch
api::client::branches::delete(&remote_repo, new_branch_name).await?;
Expand All @@ -517,15 +521,15 @@ mod tests {
let remote_repo = test::create_remote_repo(&repo).await?;

// Push main branch first
if command::push_remote_branch(&repo, constants::DEFAULT_REMOTE_NAME, "main")
if repositories::push::push_remote_branch(&repo, constants::DEFAULT_REMOTE_NAME, "main")
.await
.is_err()
{
panic!("Pushing main branch should work");
}

// Then try to push branch that doesn't exist
if command::push_remote_branch(
if repositories::push::push_remote_branch(
&repo,
constants::DEFAULT_REMOTE_NAME,
"branch-does-not-exist",
Expand Down Expand Up @@ -650,7 +654,7 @@ mod tests {
let remote_repo = test::create_remote_repo(&repo).await?;

// Push it
command::push(&repo).await?;
repositories::push(&repo).await?;
let remote_main = api::client::branches::get_by_name(&remote_repo, DEFAULT_BRANCH_NAME)
.await?
.unwrap();
Expand All @@ -668,7 +672,7 @@ mod tests {
test::write_txt_file_to_path(&labels_path, "I am the labels file")?;
repositories::add(&repo, labels_path)?;
repositories::commit(&repo, "adding labels file")?;
command::push(&repo).await?;
repositories::push(&repo).await?;

// Get main again, latest should have moved
let remote_main = api::client::branches::get_by_name(&remote_repo, DEFAULT_BRANCH_NAME)
Expand Down Expand Up @@ -696,7 +700,7 @@ mod tests {
let remote_repo = test::create_remote_repo(&repo).await?;

// Push it
command::push(&repo).await?;
repositories::push(&repo).await?;
let remote_main = api::client::branches::get_by_name(&remote_repo, DEFAULT_BRANCH_NAME)
.await?
.unwrap();
Expand Down
10 changes: 5 additions & 5 deletions src/lib/src/api/client/commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ mod tests {
let remote_repo = test::create_remote_repo(&local_repo).await?;

// Push it
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

let is_synced = api::client::commits::commit_is_synced(&remote_repo, &commit.id)
.await?
Expand Down Expand Up @@ -1354,7 +1354,7 @@ mod tests {
let remote_repo = test::create_remote_repo(&local_repo).await?;

// Push it
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// List the remote commits
let remote_commits =
Expand Down Expand Up @@ -1399,7 +1399,7 @@ mod tests {
let _commit_1_file_2 = repositories::commit(&local_repo, "Adding file_2")?;

// Push it
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// List the remote commits
let remote_commits = api::client::commits::list_commits_for_path(
Expand Down Expand Up @@ -1465,7 +1465,7 @@ mod tests {
let commit_1_file_2 = repositories::commit(&local_repo, "Adding file_2")?;

// Push it
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// List the remote commits
let remote_commits = api::client::commits::list_commits_for_path(
Expand Down Expand Up @@ -1612,7 +1612,7 @@ mod tests {
constants::DEFAULT_REMOTE_NAME,
&remote_repo.remote.url,
)?;
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// Should now be synced
let latest_synced =
Expand Down
6 changes: 3 additions & 3 deletions src/lib/src/api/client/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mod tests {
constants::DEFAULT_REMOTE_NAME,
&remote_repo.remote.url,
)?;
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

let compare_id = "abcdefgh";

Expand Down Expand Up @@ -276,7 +276,7 @@ mod tests {
constants::DEFAULT_REMOTE_NAME,
&remote_repo.remote.url,
)?;
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

let compare_id = "abcdefgh";

Expand Down Expand Up @@ -353,7 +353,7 @@ mod tests {
test::write_txt_file_to_path(local_repo.path.join(left_path), csv1)?;
repositories::add(&local_repo, &local_repo.path)?;
repositories::commit(&local_repo, "committing files")?;
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// Now get the derived df
let derived_df =
Expand Down
18 changes: 9 additions & 9 deletions src/lib/src/api/client/data_frames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ mod tests {
let remote_repo = test::create_remote_repo(&local_repo).await?;

// Push the repo
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// Get the df
let mut opts = DFOpts::empty();
Expand Down Expand Up @@ -252,7 +252,7 @@ mod tests {
let remote_repo = test::create_remote_repo(&local_repo).await?;

// Push the repo
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// Get the df
let mut opts = DFOpts::empty();
Expand Down Expand Up @@ -300,7 +300,7 @@ mod tests {
let remote_repo = test::create_remote_repo(&local_repo).await?;

// Push the repo
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// Get the df
let mut opts = DFOpts::empty();
Expand Down Expand Up @@ -354,7 +354,7 @@ mod tests {
let remote_repo = test::create_remote_repo(&local_repo).await?;

// Push the repo
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// Index the df on the remote repo
api::client::data_frames::index(
Expand Down Expand Up @@ -457,7 +457,7 @@ mod tests {
assert!(result.is_err());

// Push the repo
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// Create a new branch
let branch_name = "new_branch";
Expand Down Expand Up @@ -497,7 +497,7 @@ mod tests {
assert!(result.is_err());

// Push the repo
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// List the one schema
let opts = DFOpts::empty();
Expand Down Expand Up @@ -552,7 +552,7 @@ mod tests {
let remote_repo = test::create_remote_repo(&local_repo).await?;

// Push the repo
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// Get the df
let mut opts = DFOpts::empty();
Expand Down Expand Up @@ -619,7 +619,7 @@ mod tests {
let remote_repo = test::create_remote_repo(&local_repo).await?;

// Push the repo
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// Get the df
let mut opts = DFOpts::empty();
Expand Down Expand Up @@ -682,7 +682,7 @@ mod tests {
let remote_repo = test::create_remote_repo(&local_repo).await?;

// Push the repo
command::push(&local_repo).await?;
repositories::push(&local_repo).await?;

// Get the df
let mut opts = DFOpts::empty();
Expand Down
Loading

0 comments on commit ca172a4

Please sign in to comment.