//! Core library for generating `bdlx` POSIX shell scripts.
//!
//! This crate contains the script-generation logic used by the `bdlx` CLI.
//!
//! Use [`bundle::script::write_bundle`] to generate self-extracting scripts and
//! [`embed::write_embed`] to generate scripts that reproduce bytes on stdout.
//!
//! # Generate a bundle script
//!
//! ```no_run
//! use bdlx_core::{
//!     ArchiveSource, BundleSpec, CleanupPolicy, InnerCommand,
//!     bundle::script::write_bundle,
//! };
//!
//! # fn main() -> bdlx_core::Result<()> {
//! let mut archive = std::fs::File::open("app.tar")
//!     .map_err(|error| bdlx_core::Error::io("failed to open app.tar", error))?;
//!
//! let spec = BundleSpec {
//!     cleanup: CleanupPolicy::Success,
//!     shared: false,
//!     archives: vec![ArchiveSource::reader("app.tar", &mut archive)],
//!     env: vec![],
//!     command: InnerCommand {
//!         program: "./app".into(),
//!         args: vec!["--serve".into()],
//!     },
//! };
//!
//! let mut script = Vec::new();
//! write_bundle(spec, &mut script)?;
//! # Ok(())
//! # }
//! ```
//!
//! The bytes in `script` are a POSIX `sh` program. Writing them to a file gives
//! you a runnable self-extracting bundle.
//!
//! # Generate an embed script
//!
//! ```
//! use bdlx_core::{EmbedSpec, embed::write_embed};
//!
//! # fn main() -> bdlx_core::Result<()> {
//! let spec = EmbedSpec { inputs: vec![] };
//! let mut input = "hello\n".as_bytes();
//! let mut script = Vec::new();
//!
//! write_embed(&spec, &mut input, &mut script)?;
//! # Ok(())
//! # }
//! ```

#![warn(missing_docs)]

/// Bundle parsing and self-extracting script generation.
pub mod bundle;
/// Public command and script-generation data structures.
pub mod command;
/// Embed script generation.
pub mod embed;
/// Error and result types.
pub mod error;

mod esc;
mod hash;
mod shell;

pub use command::{
    ArchiveSource, BundleSpec, CleanupPolicy, EmbedSpec, EnvAssignment, InnerCommand, InputSource,
    RuntimeFlag,
};
pub use error::{Error, Result};

/// Returns the version string embedded into generated scripts.
pub fn version() -> &'static str {
    env!("CARGO_PKG_VERSION")
}
