Skip to content

Commit

Permalink
Merge lib cli into run command PR
Browse files Browse the repository at this point in the history
  • Loading branch information
haixuanTao committed Nov 11, 2024
1 parent 7c5ed1e commit 84e2291
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions binaries/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use dora_message::{
};
#[cfg(feature = "tracing")]
use dora_tracing::set_up_tracing;
use dora_tracing::set_up_tracing_opts;
use dora_tracing::{set_up_tracing_opts, FileLogging};
use duration_str::parse;
use eyre::{bail, Context};
use formatting::FormatDataflowError;
Expand All @@ -29,6 +29,7 @@ use std::{
};
use tabwriter::TabWriter;
use tokio::runtime::Builder;
use tracing::level_filters::LevelFilter;
use uuid::Uuid;

mod attach;
Expand All @@ -45,7 +46,7 @@ const LISTEN_WILDCARD: IpAddr = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0));

#[derive(Debug, clap::Parser)]
#[clap(version)]
pub struct Args {
struct Args {
#[clap(subcommand)]
command: Command,
}
Expand Down Expand Up @@ -90,6 +91,15 @@ enum Command {
#[clap(hide = true, long)]
internal_create_with_path_dependencies: bool,
},
/// Run a dataflow locally.
///
/// Directly runs the given dataflow without connecting to a dora
/// coordinator or daemon. The dataflow is executed on the local machine.
Run {
/// Path to the dataflow descriptor file
#[clap(value_name = "PATH")]
dataflow: String,
},
/// Spawn coordinator and daemon in local mode (with default config)
Up {
/// Use a custom configuration
Expand Down Expand Up @@ -255,7 +265,7 @@ enum Lang {
Cxx,
}

pub fn lib_main(args: Args) {
fn lib_main(args: Args) {

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / Bench (macos-latest)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / Bench (ubuntu-latest)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / Examples (ubuntu-22.04)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / CLI Test (macos-latest)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / cross-check (ubuntu-20.04, i686-unknown-linux-gnu)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / cross-check (ubuntu-20.04, armv7-unknown-linux-musleabihf)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / cross-check (ubuntu-20.04, x86_64-unknown-linux-gnu)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / cross-check (ubuntu-20.04, aarch64-unknown-linux-gnu)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / CLI Test (ubuntu-latest)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / cross-check (ubuntu-20.04, aarch64-unknown-linux-musl)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / Bench (windows-latest)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / Examples (macos-latest)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (macos-latest)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / CLI Test (windows-latest)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / ROS2 Bridge Examples

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / cross-check (macos-12, aarch64-apple-darwin)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / cross-check (macos-12, x86_64-apple-darwin)

function `lib_main` is never used

Check warning on line 268 in binaries/cli/src/lib.rs

View workflow job for this annotation

GitHub Actions / Examples (windows-latest)

function `lib_main` is never used
if let Err(err) = run(args) {
eprintln!("\n\n{}", "[ERROR]".bold().red());
eprintln!("{err:#}");
Expand All @@ -274,15 +284,29 @@ fn run(args: Args) -> eyre::Result<()> {
.as_ref()
.map(|id| format!("{name}-{id}"))
.unwrap_or(name.to_string());
set_up_tracing_opts(name, !quiet, Some(&filename))
let stdout = (!quiet).then_some(LevelFilter::WARN);
let file = Some(FileLogging {
file_name: filename,
filter: LevelFilter::INFO,
});
set_up_tracing_opts(name, stdout, file)
.context("failed to set up tracing subscriber")?;
}
Command::Runtime => {
// Do not set the runtime in the cli.
}
Command::Coordinator { quiet, .. } => {
let name = "dora-coordinator";
set_up_tracing_opts(name, !quiet, Some(name))
let stdout = (!quiet).then_some(LevelFilter::WARN);
let file = Some(FileLogging {
file_name: name.to_owned(),
filter: LevelFilter::INFO,
});
set_up_tracing_opts(name, stdout, file)
.context("failed to set up tracing subscriber")?;
}
Command::Run { .. } => {
set_up_tracing_opts("run", Some(LevelFilter::INFO), None)
.context("failed to set up tracing subscriber")?;
}
_ => {
Expand Down Expand Up @@ -328,6 +352,15 @@ fn run(args: Args) -> eyre::Result<()> {
args,
internal_create_with_path_dependencies,
} => template::create(args, internal_create_with_path_dependencies)?,
Command::Run { dataflow } => {
let dataflow_path = resolve_dataflow(dataflow).context("could not resolve dataflow")?;
let rt = Builder::new_multi_thread()
.enable_all()
.build()
.context("tokio runtime failed")?;
let result = rt.block_on(Daemon::run_dataflow(&dataflow_path))?;
handle_dataflow_result(result, None)?
}
Command::Up { config } => {
up::up(config.as_deref())?;
}
Expand Down

0 comments on commit 84e2291

Please sign in to comment.