Skip to content

Commit

Permalink
stdout and stderr working with spinner, extra tests and better lib st…
Browse files Browse the repository at this point in the history
…ructure
  • Loading branch information
tiptenbrink committed Apr 30, 2024
1 parent 445fb47 commit 361eec6
Show file tree
Hide file tree
Showing 13 changed files with 333 additions and 117 deletions.
125 changes: 123 additions & 2 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ description="Simple deployment tool for deploying small applications and loading
repository="https://github.com/tiptenbrink/tidploy"
readme="README.md"


[dependencies]
base64 = "=0.21.7"
clap = { version = "=4.4.16", features = ["derive"] }
Expand All @@ -23,4 +24,6 @@ tracing = "=0.1.40"
tracing-subscriber = "=0.3.18"
tracing-error = "=0.2.0"
directories = "=5.0.1"
color-eyre = "=0.6.3"
color-eyre = "=0.6.3"
test-log = { version="=0.2.15", default-features = false, features = ["trace"] }
duct = "=0.13.7"
7 changes: 7 additions & 0 deletions examples/run/example_input.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Read a single line of input from stdin
read -r line

# Print the input line to stdout
echo "You entered: $line"
15 changes: 15 additions & 0 deletions examples/run/example_spinner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
spin[0]="-"
spin[1]="\\"
spin[2]="|"
spin[3]="/"

j=0
while [ $j -lt 3 ]; do
for i in "${spin[@]}"
do
echo -ne "\b$i"
sleep 0.1
done
j=$((j+1))
done
11 changes: 11 additions & 0 deletions examples/run/example_stderr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
echoerr() { echo "$@" 1>&2; }
echo hello1
echo hello2
sleep 2
echo hello3
sleep 1
echoerr hello world2
echoerr hello world3
sleep 1
echoerr hello world1
15 changes: 10 additions & 5 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::path::{Path, PathBuf};
use std::process::ExitCode;

use crate::archives::{extract_archive, make_archive};
use crate::errors::{ProcessError, RepoError};
Expand Down Expand Up @@ -236,7 +237,7 @@ fn prepare_command(
Ok(Some(state))
}

pub(crate) fn run_cli() -> Result<(), Report> {
pub fn run_cli() -> Result<ExitCode, Report> {
// We get our CLI arguments using the clap crate. This allows us to state all our arguments using
// a set of structs, indicating the structure of our commands
// Note that it uses the Cargo.toml description as the main help command description
Expand All @@ -260,14 +261,14 @@ pub(crate) fn run_cli() -> Result<(), Report> {

secret_command(&state, key).map_err(ErrorRepr::Auth)?;

Ok(())
Ok(ExitCode::SUCCESS)
}
Commands::Download { repo_only } => {
let state = create_state_create(cli_state.clone(), None, None, false)
.map_err(ErrorRepr::Load)?;
download_command(cli_state, state.repo, repo_only)?;

Ok(())
Ok(ExitCode::SUCCESS)
}
Commands::Deploy {
executable,
Expand Down Expand Up @@ -314,14 +315,18 @@ pub(crate) fn run_cli() -> Result<(), Report> {
run_entrypoint(state.deploy_dir(), &state.exe_name, state.envs)
.map_err(ErrorRepr::Exe)?;

Ok(())
Ok(ExitCode::SUCCESS)
}
Commands::Run {
executable,
variables,
archive,
} => {
run_command(cli_state, executable, variables, archive)
let out = run_command(cli_state, executable, variables, archive)?;
// If [process::ExitCode::from_raw] gets stabilized this can be simplified
let code = u8::try_from(out.exit.code().unwrap_or(0))?;

Ok(ExitCode::from(code))
}
}
}
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mod next;
mod archives;
mod config;
mod errors;
mod filesystem;
mod git;
mod process;
mod secret;
mod secret_store;
mod state;

pub mod commands;

pub use next::api::*;
16 changes: 4 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
mod archives;
mod commands;
mod config;
mod errors;
mod filesystem;
mod git;
mod next;
mod process;
mod secret;
mod secret_store;
mod state;
use std::process::ExitCode;

use tidploy::commands;

use color_eyre::eyre::Report;
use tracing_error::ErrorLayer;
Expand All @@ -25,7 +17,7 @@ fn install_tracing() {
.init();
}

fn main() -> Result<(), Report> {
fn main() -> Result<ExitCode, Report> {
install_tracing();
color_eyre::install()?;

Expand Down
Loading

0 comments on commit 361eec6

Please sign in to comment.