-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(host): Re-export default CLIs (#992)
- Loading branch information
Showing
15 changed files
with
115 additions
and
98 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//! Main entrypoint for the host binary. | ||
#![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)] | ||
#![deny(unused_must_use, rust_2018_idioms)] | ||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] | ||
|
||
use anyhow::Result; | ||
use clap::{ArgAction, Parser, Subcommand}; | ||
use kona_host::{ | ||
cli::{cli_styles, init_tracing_subscriber}, | ||
DetachedHostOrchestrator, | ||
}; | ||
use serde::Serialize; | ||
use tracing::info; | ||
|
||
const ABOUT: &str = " | ||
kona-host is a CLI application that runs the Kona pre-image server and client program. The host | ||
can run in two modes: server mode and native mode. In server mode, the host runs the pre-image | ||
server and waits for the client program in the parent process to request pre-images. In native | ||
mode, the host runs the client program in a separate thread with the pre-image server in the | ||
primary thread. | ||
"; | ||
|
||
/// The host binary CLI application arguments. | ||
#[derive(Parser, Serialize, Clone, Debug)] | ||
#[command(about = ABOUT, version, styles = cli_styles())] | ||
pub struct HostCli { | ||
/// Verbosity level (0-2) | ||
#[arg(long, short, action = ArgAction::Count)] | ||
pub v: u8, | ||
/// Host mode | ||
#[clap(subcommand)] | ||
pub mode: HostMode, | ||
} | ||
|
||
/// Operation modes for the host binary. | ||
#[derive(Subcommand, Serialize, Clone, Debug)] | ||
#[allow(clippy::large_enum_variant)] | ||
pub enum HostMode { | ||
/// Run the host in single-chain mode. | ||
#[cfg(feature = "single")] | ||
Single(kona_host::single::SingleChainHostCli), | ||
/// Run the host in super-chain (interop) mode. | ||
#[cfg(feature = "interop")] | ||
Super(kona_host::interop::InteropHostCli), | ||
} | ||
|
||
#[tokio::main(flavor = "multi_thread")] | ||
async fn main() -> Result<()> { | ||
let cfg = HostCli::parse(); | ||
init_tracing_subscriber(cfg.v)?; | ||
|
||
match cfg.mode { | ||
#[cfg(feature = "single")] | ||
HostMode::Single(cfg) => { | ||
cfg.run().await?; | ||
} | ||
#[cfg(feature = "interop")] | ||
HostMode::Super(cfg) => { | ||
cfg.run().await?; | ||
} | ||
} | ||
|
||
info!("Exiting host program."); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
//! Parser functions for CLI arguments. | ||
use alloy_primitives::{hex, Bytes, B256}; | ||
use std::str::FromStr; | ||
|
||
/// Parse a string slice into [B256]. | ||
pub(crate) fn parse_b256(s: &str) -> Result<B256, String> { | ||
pub fn parse_b256(s: &str) -> Result<B256, String> { | ||
B256::from_str(s).map_err(|_| format!("Invalid B256 value: {}", s)) | ||
} | ||
|
||
/// Parse a string slice into [Bytes]. | ||
pub(crate) fn parse_bytes(s: &str) -> Result<Bytes, String> { | ||
pub fn parse_bytes(s: &str) -> Result<Bytes, String> { | ||
hex::decode(s).map_err(|e| format!("Invalid hex string: {}", e)).map(Bytes::from) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters