use std::path::PathBuf;
use tokmd_settings::Profile;
use crate::cli;
use crate::config::ResolvedConfig;
use super::parse::{parse_child_include_mode, parse_export_format, parse_redact_mode};
pub fn resolve_export(
cli_args: &cli::CliExportArgs,
profile: Option<&Profile>,
) -> tokmd_types::ExportArgs {
tokmd_types::ExportArgs {
paths: cli_args
.paths
.clone()
.unwrap_or_else(|| vec![PathBuf::from(".")]),
format: cli_args
.format
.map(Into::into)
.or_else(|| parse_export_format(profile.and_then(|p| p.format.as_deref())))
.unwrap_or(tokmd_types::ExportFormat::Jsonl),
output: cli_args.output.clone(),
module_roots: cli_args
.module_roots
.clone()
.or_else(|| profile.and_then(|p| p.module_roots.clone()))
.unwrap_or_else(|| vec!["crates".into(), "packages".into()]),
module_depth: cli_args
.module_depth
.or_else(|| profile.and_then(|p| p.module_depth))
.unwrap_or(2),
children: cli_args
.children
.map(Into::into)
.or_else(|| parse_child_include_mode(profile.and_then(|p| p.children.as_deref())))
.unwrap_or(tokmd_types::ChildIncludeMode::Separate),
min_code: cli_args
.min_code
.or(profile.and_then(|p| p.min_code))
.unwrap_or(0),
max_rows: cli_args
.max_rows
.or(profile.and_then(|p| p.max_rows))
.unwrap_or(0),
redact: cli_args
.redact
.map(Into::into)
.or(profile.and_then(|p| p.redact))
.unwrap_or(tokmd_types::RedactMode::None),
meta: cli_args
.meta
.or(profile.and_then(|p| p.meta))
.unwrap_or(true),
strip_prefix: cli_args.strip_prefix.clone(),
}
}
pub fn resolve_export_with_config(
cli_args: &cli::CliExportArgs,
resolved: &ResolvedConfig,
) -> tokmd_types::ExportArgs {
tokmd_types::ExportArgs {
paths: cli_args
.paths
.clone()
.unwrap_or_else(|| vec![PathBuf::from(".")]),
format: cli_args
.format
.map(Into::into)
.or_else(|| parse_export_format(resolved.format()))
.or_else(|| parse_export_format(resolved.toml.and_then(|t| t.export.format.as_deref())))
.unwrap_or(tokmd_types::ExportFormat::Jsonl),
output: cli_args.output.clone(),
module_roots: cli_args
.module_roots
.clone()
.or(resolved.module_roots())
.unwrap_or_else(|| vec!["crates".into(), "packages".into()]),
module_depth: cli_args
.module_depth
.or(resolved.module_depth())
.unwrap_or(2),
children: cli_args
.children
.map(Into::into)
.or_else(|| parse_child_include_mode(resolved.children()))
.or_else(|| {
parse_child_include_mode(resolved.toml.and_then(|t| t.export.children.as_deref()))
})
.unwrap_or(tokmd_types::ChildIncludeMode::Separate),
min_code: cli_args.min_code.or(resolved.min_code()).unwrap_or(0),
max_rows: cli_args.max_rows.or(resolved.max_rows()).unwrap_or(0),
redact: cli_args
.redact
.map(Into::into)
.or_else(|| parse_redact_mode(resolved.redact()))
.unwrap_or(tokmd_types::RedactMode::None),
meta: cli_args.meta.or(resolved.meta()).unwrap_or(true),
strip_prefix: cli_args.strip_prefix.clone(),
}
}