Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tem 2596: Prettify tembo-cli ouput #464

Merged
merged 16 commits into from
Jan 4, 2024
Merged
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
12 changes: 6 additions & 6 deletions .github/workflows/cargo-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Cargo lint and test

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
find_directories:
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2023-11-18
toolchain: stable
components: rustfmt, clippy
- name: Install minimal stable with clippy and rustfmt
uses: actions-rs/toolchain@v1
Expand All @@ -62,9 +62,9 @@ jobs:
run: |
set -xe
cd ${{ matrix.path }}
cargo +nightly-2023-11-18 --version
cargo +nightly-2023-11-18 fmt --all --check
cargo +nightly-2023-11-18 clippy
cargo --version
cargo fmt --all --check
cargo clippy

test:
name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion conductor/Cargo.lock

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

127 changes: 86 additions & 41 deletions tembo-cli/Cargo.lock

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

6 changes: 5 additions & 1 deletion tembo-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.91"
serde_yaml = "0.9.17"
home = "0.5.5"
spinners = "4.1.0"
semver = "1.0.18"
mockall = "0.11.4"
toml = "0.7.6"
Expand Down Expand Up @@ -55,6 +54,11 @@ tokio = { version = "1.26.0", features = [
controller = "0.26.1"
sqlx = { version = "0.7.3", features = ["runtime-tokio-native-tls", "postgres", "chrono", "json"] }
base64 = "0.21.5"
colorful = "0.2.2"
cli-table = "0.4.7"
tiny-gradient = "0.1.0"
urlencoding = "2.1.3"
spinoff = "0.8.0"

[dev-dependencies]
assert_cmd = "2.0.8"
Expand Down
2 changes: 1 addition & 1 deletion tembo-cli/examples/single-instance/tembo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Default settings for instances
[defaults]
environment = "dev"
instance_name = "test-via-cli-35"
instance_name = "your-instance-name"
cpu = "1"
memory = "2Gi"
storage = "10Gi"
Expand Down
48 changes: 35 additions & 13 deletions tembo-cli/src/cli/docker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::tui::{colors, white_confirmation};
use anyhow::Error;
use anyhow::{bail, Context};
use colorful::{Color, Colorful};
use simplelog::*;
use spinners::{Spinner, Spinners};
use spinoff::{spinners, Spinner};
use std::io::{BufRead, BufReader};
use std::process::Output;
use std::process::{Command as ShellCommand, Stdio};
Expand Down Expand Up @@ -45,31 +47,37 @@ impl Docker {
pub fn build_run(instance_name: String, verbose: bool) -> Result<i32, anyhow::Error> {
let mut sp = if !verbose {
Some(Spinner::new(
Spinners::Line,
"Running Docker Build & Run".into(),
spinners::Dots,
"Running Docker Build & Run",
spinoff::Color::White,
))
} else {
None
};

let mut show_message = |message: &str, new_spinner: bool| {
if let Some(mut spinner) = sp.take() {
spinner.stop_with_message(message.to_string());
spinner.stop_with_message(&format!(
"{} {}",
"✓".color(colors::indicator_good()).bold(),
message.color(Color::White).bold()
));
if new_spinner {
sp = Some(Spinner::new(
Spinners::Line,
"Building and running container".into(),
spinners::Dots,
"Building and running container",
spinoff::Color::White,
));
}
} else {
println!("{}", message);
white_confirmation(message);
}
};

let container_list = Self::container_list_filtered(&instance_name)?;

if container_list.contains(&instance_name) {
show_message("- Existing container found, removing", true);
show_message("Existing container found, removing", true);
Docker::stop_remove(&instance_name)?;
}

Expand All @@ -81,7 +89,7 @@ impl Docker {
);
run_command(&command, verbose)?;

show_message("- Docker Build & Run completed", false);
show_message("Docker Build & Run completed", false);

Ok(port)
}
Expand Down Expand Up @@ -119,26 +127,40 @@ impl Docker {

// stop & remove container for given name
pub fn stop_remove(name: &str) -> Result<(), anyhow::Error> {
let mut sp = Spinner::new(Spinners::Line, "Stopping & Removing instance".into());
let mut sp = Spinner::new(
spinners::Dots,
"Stopping & Removing instance",
spinoff::Color::White,
);

if !Self::container_list_filtered(name).unwrap().contains(name) {
sp.stop_with_message(format!("- Tembo instance {} doesn't exist", name));
sp.stop_with_message(&format!(
"{} {}",
"➜".bold(),
colors::gradient_rainbow(&format!("- Tembo instance {} doesn't exist", name))
));
} else {
let mut command: String = String::from("docker rm --force ");
command.push_str(name);

let output = match ShellCommand::new("sh").arg("-c").arg(&command).output() {
Ok(output) => output,
Err(_) => {
sp.stop_with_message(format!(
sp.stop_with_message(&format!(
"- Tembo instance {} failed to stop & remove",
&name
));
bail!("There was an issue stopping the instance")
}
};

sp.stop_with_message(format!("- Tembo instance {} stopped & removed", &name));
sp.stop_with_message(&format!(
"{} {}",
"✓".color(colors::indicator_good()).bold(),
format!("Tembo instance {} stopped & removed", &name)
.color(Color::White)
.bold()
));

let stderr = String::from_utf8(output.stderr).unwrap();

Expand Down
Loading
Loading