Skip to content

Commit

Permalink
More tembo-cli output polish (#483)
Browse files Browse the repository at this point in the history
Co-authored-by: Darren B <68653294+Devd0@users.noreply.github.com>
  • Loading branch information
DarrenBaldwin07 and DarrenBaldwin07 authored Jan 15, 2024
1 parent 00a9bab commit 538d01c
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 41 deletions.
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.

2 changes: 1 addition & 1 deletion tembo-cli/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 tembo-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
workspace = { members = ["temboclient", "tembodataclient"] }
[package]
name = "tembo-cli"
version = "0.14.0"
version = "0.14.1"
edition = "2021"
authors = ["Tembo.io"]
description = "The CLI for Tembo"
Expand Down
27 changes: 17 additions & 10 deletions tembo-cli/src/cmd/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ use crate::cli::sqlx_utils::SqlxUtils;
use crate::cli::tembo_config;
use crate::cli::tembo_config::InstanceSettings;
use crate::cli::tembo_config::OverlayInstanceSettings;
use crate::tui::instance_started;
use crate::tui;
use crate::{
cli::context::{get_current_context, Environment, Profile, Target},
tui::{clean_console, colors, white_confirmation},
tui::{clean_console, colors, instance_started, white_confirmation},
};
use tera::{Context, Tera};

Expand Down Expand Up @@ -116,7 +116,6 @@ fn execute_docker(verbose: bool, _merge_path: Option<String>) -> Result<(), anyh
&value.stack_type,
"local",
);
println!("Instance settings: {:?}", instance_settings);
}

Ok(())
Expand All @@ -141,14 +140,23 @@ pub fn execute_tembo_cloud(
if let Some(env_instance_id) = instance_id.clone() {
update_existing_instance(env_instance_id, value, &config, env.clone());
} else {
instance_id = create_new_instance(value, &config, env.clone());
let new_inst_req = create_new_instance(value, &config, env.clone());
match new_inst_req {
Ok(new_instance_id) => instance_id = Some(new_instance_id),
Err(error) => {
tui::error(&format!("Error creating instance: {}", error));
break;
}
}
}

println!();
let mut sp = spinoff::Spinner::new(
spinoff::spinners::Aesthetic,
"Waiting for instance to be up...",
"Waiting for instance to provision...",
colors::SPINNER_COLOR,
);

loop {
sleep(Duration::from_secs(10));

Expand Down Expand Up @@ -298,7 +306,7 @@ fn create_new_instance(
value: &InstanceSettings,
config: &Configuration,
env: Environment,
) -> Option<String> {
) -> Result<String, String> {
let instance = get_create_instance(value);

let v = Runtime::new().unwrap().block_on(create_instance(
Expand All @@ -314,14 +322,13 @@ fn create_new_instance(
result.instance_name.color(colors::sql_u()).bold()
));

return Some(result.instance_id);
return Ok(result.instance_id);
}
Err(error) => {
eprintln!("Error creating instance: {}", error);
Err(error.to_string())
}
};

None
}
}

fn get_create_instance(instance_settings: &InstanceSettings) -> CreateInstance {
Expand Down
11 changes: 9 additions & 2 deletions tembo-cli/src/cmd/context/list.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use crate::cli::context::list_context;
use crate::tui::{colors::sql_u, indent, label};
use crate::tui::{colors::sql_u, indent, label_with_value};
use cli_table::{Cell, CellStruct, Style, Table};
use colorful::Colorful;

pub fn execute() -> Result<(), anyhow::Error> {
let context = list_context()?;

let mut rows: Vec<Vec<CellStruct>> = vec![];
let current_context_profile = context
.environment
.iter()
.find(|e| e.set.is_some())
.unwrap()
.name
.clone();
for e in context.environment {
let mut org_id = String::from(" ");
let mut profile = String::from(" ");
Expand Down Expand Up @@ -49,7 +56,7 @@ pub fn execute() -> Result<(), anyhow::Error> {
.display()
.expect("Error: could not parse `tembo context list` table contents!");

label("Your current Tembo context:");
label_with_value("Your current Tembo context:", &current_context_profile);
println!("{}", indent(1));
println!("{}", table_display);

Expand Down
10 changes: 6 additions & 4 deletions tembo-cli/src/cmd/context/set.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::cli::context::{tembo_context_file_path, Context};
use crate::tui::colors;
use crate::tui::{colors, error};
use clap::Args;
use colorful::Colorful;
use std::fs::{self, File};
Expand All @@ -19,14 +19,16 @@ pub fn execute(args: &ContextSetArgs) -> Result<(), anyhow::Error> {
let contents = match fs::read_to_string(&filename) {
Ok(c) => c,
Err(e) => {
panic!("Couldn't read context file {}: {}", filename, e);
error(&format!("Couldn't read context file {}: {}", filename, e));
return Err(e.into());
}
};

let mut data: Context = match toml::from_str(&contents) {
Ok(d) => d,
Err(e) => {
panic!("Unable to load data. Error: `{}`", e);
error(&format!("Unable to load data. Error: `{}`", e));
return Err(e.into());
}
};

Expand All @@ -41,7 +43,7 @@ pub fn execute(args: &ContextSetArgs) -> Result<(), anyhow::Error> {
}

if let Err(e) = write_config_to_file(&data, &tembo_context_file_path()) {
eprintln!("Error: {}", e);
error(&format!("Error: {}", e));
}

println!(
Expand Down
4 changes: 2 additions & 2 deletions tembo-cli/src/cmd/delete.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cli::context::{get_current_context, Environment, Target};
use crate::cli::docker::Docker;

use crate::tui;
use crate::tui::confirmation;
use clap::Args;
use core::result::Result::Ok;
Expand Down Expand Up @@ -53,7 +53,7 @@ fn execute_tembo_cloud(env: Environment) -> Result<(), anyhow::Error> {
"Instance delete started for Instance Id: {}",
result.instance_id
)),
Err(error) => eprintln!("Error deleting instance: {}", error),
Err(error) => tui::error(&format!("Error deleting instance: {}", error)),
};
}
}
Expand Down
45 changes: 27 additions & 18 deletions tembo-cli/src/cmd/validate.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cli::context::{tembo_context_file_path, tembo_credentials_file_path};
use crate::cli::file_utils::FileUtils;
use crate::cli::tembo_config::InstanceSettings;
use crate::tui::white_confirmation;
use crate::tui::{error, info, white_confirmation};
use anyhow::Error;
use anyhow::Ok;
use clap::Args;
Expand All @@ -15,14 +15,14 @@ pub fn execute(verbose: bool) -> Result<(), anyhow::Error> {
let mut has_error = false;

if !Path::new(&tembo_context_file_path()).exists() {
println!(
error(&format!(
"No {} file exists. Run tembo init first!",
tembo_context_file_path()
);
));
has_error = true
}
if verbose {
println!("- Context file exists");
info("Context file exists");
}

if !Path::new(&tembo_credentials_file_path()).exists() {
Expand All @@ -33,11 +33,11 @@ pub fn execute(verbose: bool) -> Result<(), anyhow::Error> {
has_error = true
}
if verbose {
println!("- Credentials file exists");
info("Credentials file exists");
}

if !Path::new(&"tembo.toml").exists() {
println!("No Tembo file (tembo.toml) exists in this directory!");
error("No Tembo file (tembo.toml) exists in this directory!");
has_error = true
} else {
let mut file_path = FileUtils::get_current_working_dir();
Expand All @@ -50,13 +50,13 @@ pub fn execute(verbose: bool) -> Result<(), anyhow::Error> {
match validate_config(config, verbose) {
std::result::Result::Ok(_) => (),
std::result::Result::Err(e) => {
println!("Error validating config: {}", e);
error(&format!("Error validating config: {}", e));
has_error = true;
}
}
}
if verbose {
println!("- Tembo file exists");
info("Tembo file exists");
}

if has_error {
Expand Down Expand Up @@ -104,7 +104,10 @@ fn validate_environment(env: &str, section: &str, verbose: bool) -> Result<(), a
match temboclient::models::Environment::from_str(env) {
std::result::Result::Ok(_) => {
if verbose {
println!("- Environment '{}' in section '{}' is valid", env, section);
white_confirmation(&format!(
"Environment '{}' in section '{}' is valid",
env, section
));
}
Ok(())
}
Expand All @@ -119,7 +122,7 @@ fn validate_cpu(cpu: &str, section: &str, verbose: bool) -> Result<(), anyhow::E
match temboclient::models::Cpu::from_str(cpu) {
std::result::Result::Ok(_) => {
if verbose {
println!("- Cpu '{}' in section '{}' is valid", cpu, section);
info(&format!("Cpu '{}' in section '{}' is valid", cpu, section));
}
Ok(())
}
Expand All @@ -134,7 +137,10 @@ fn validate_memory(memory: &str, section: &str, verbose: bool) -> Result<(), any
match temboclient::models::Memory::from_str(memory) {
std::result::Result::Ok(_) => {
if verbose {
println!("- Memory '{}' in section '{}' is valid", memory, section);
info(&format!(
"Memory '{}' in section '{}' is valid",
memory, section
));
}
Ok(())
}
Expand All @@ -149,7 +155,10 @@ fn validate_storage(storage: &str, section: &str, verbose: bool) -> Result<(), a
match temboclient::models::Storage::from_str(storage) {
std::result::Result::Ok(_) => {
if verbose {
println!("- Storage '{}' in section '{}' is valid", storage, section);
info(&format!(
"- Storage '{}' in section '{}' is valid",
storage, section
));
}
Ok(())
}
Expand All @@ -165,10 +174,10 @@ fn validate_replicas(replicas: &str, section: &str, verbose: bool) -> Result<(),
std::result::Result::Ok(value) => {
if value == 1 || value == 2 {
if verbose {
println!(
"- Replicas '{}' in section '{}' is valid",
info(&format!(
"Replicas '{}' in section '{}' is valid",
replicas, section
);
));
}
Ok(())
} else {
Expand All @@ -193,10 +202,10 @@ fn validate_stack_type(
match temboclient::models::StackType::from_str(stack_types) {
std::result::Result::Ok(_) => {
if verbose {
println!(
"- Stack types '{}' in section '{}' is valid",
info(&format!(
"Stack types '{}' in section '{}' is valid",
stack_types, section
);
));
}
Ok(())
}
Expand Down
Loading

0 comments on commit 538d01c

Please sign in to comment.