Skip to content

Commit

Permalink
Initial remotes support
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiimk committed Nov 10, 2020
1 parent c13e2ca commit ebbc514
Show file tree
Hide file tree
Showing 27 changed files with 1,534 additions and 318 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.34.0] - 2020-11-09
### Added
- Initial version of `remote` management
- Initial version of `push` / `pull` commands working with `remote`
- Local file system `remote` backend implementation

## [0.33.0] - 2020-11-01
### Changed
- Upgraded the Spark engine to Spark 3.0
Expand Down
86 changes: 52 additions & 34 deletions 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 kamu-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kamu-cli"
version = "0.33.0"
version = "0.34.0"
description = "Decentralized data management tool"
authors = ["Sergii Mikhtoniuk <mikhtoniuk@gmail.com>"]
license = "MPL-2.0"
Expand Down
30 changes: 28 additions & 2 deletions kamu-cli/src/cli_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,35 @@ pub fn cli(binary_name: &'static str, version: &'static str) -> App<'static, 'st
Arg::with_name("set-watermark")
.long("set-watermark")
.takes_value(true)
.value_name("T")
.value_name("TIME")
.help("Injects a manual watermark into the dataset to signify that \
no data is expected to arrive with event time that precedes it")
no data is expected to arrive with event time that precedes it"),
Arg::with_name("remote")
.long("remote")
.takes_value(true)
.value_name("REMOTE")
.help("Specifies which remote to pull data from"),
]),
SubCommand::with_name("push")
.about("Push local data into the remote repository")
.args(&[
// Arg::with_name("all")
// .short("a")
// .long("all")
// .help("Push all datasets in the workspace"),
// Arg::with_name("recursive")
// .short("r")
// .long("recursive")
// .help("Also push all transitive dependencies of specified datasets"),
Arg::with_name("dataset")
.multiple(true)
.index(1)
.help("Dataset ID(s)"),
Arg::with_name("remote")
.long("remote")
.takes_value(true)
.value_name("REMOTE")
.help("Specifies which remote to push data into"),
]),
SubCommand::with_name("reset")
.about("Revert the dataset back to the specified state")
Expand Down
29 changes: 28 additions & 1 deletion kamu-cli/src/commands/complete_command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{Command, Error};
use kamu::domain::*;

use chrono::prelude::*;
use glob;
use std::cell::RefCell;
use std::fs;
Expand Down Expand Up @@ -31,6 +32,10 @@ impl CompleteCommand {
}
}

fn complete_timestamp(&self) {
println!("{}", Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true));
}

fn complete_dataset(&self, prefix: &str) {
if let Some(repo) = self.metadata_repo.as_ref() {
for dataset_id in repo.borrow().get_all_datasets() {
Expand Down Expand Up @@ -109,14 +114,33 @@ impl Command for CompleteCommand {
for s in last_cmd.subcommands.iter() {
if s.p.meta.name == *arg {
last_cmd = &s.p;
continue;
}
}
}

let empty = "".to_owned();
let prev = args.get(self.current - 1).unwrap_or(&empty);
let to_complete = args.get(self.current).unwrap_or(&empty);

// Complete option values
if prev.starts_with("--") {
for opt in last_cmd.opts.iter() {
let full_name = format!("--{}", opt.s.long.unwrap());
if full_name == *prev {
if let Some(val_names) = &opt.v.val_names {
for (_, name) in val_names.iter() {
match *name {
"REMOTE" => self.complete_remote(to_complete),
"TIME" => self.complete_timestamp(),
_ => (),
}
}
return Ok(());
}
}
}
}

// Complete commands
for s in last_cmd.subcommands.iter() {
if !s.p.is_set(clap::AppSettings::Hidden) && s.p.meta.name.starts_with(to_complete) {
Expand All @@ -136,6 +160,9 @@ impl Command for CompleteCommand {

// Complete flags and options
if to_complete.starts_with("-") {
if "--help".starts_with(to_complete) {
println!("--help");
}
for flg in last_cmd.flags.iter() {
let full_name = if flg.s.long.is_some() {
format!("--{}", flg.s.long.unwrap())
Expand Down
6 changes: 6 additions & 0 deletions kamu-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub use pull_command::*;
mod pull_images_command;
pub use pull_images_command::*;

mod push_command;
pub use push_command::*;

mod remote_add_command;
pub use remote_add_command::*;

Expand All @@ -54,6 +57,9 @@ pub use sql_server_command::*;
mod sql_shell_command;
pub use sql_shell_command::*;

mod sync_from_command;
pub use sync_from_command::*;

pub trait Command {
fn needs_workspace(&self) -> bool {
true
Expand Down
Loading

0 comments on commit ebbc514

Please sign in to comment.