use std::path::PathBuf;
use tokmd_settings::Profile;
use crate::cli;
use crate::config::ResolvedConfig;
use super::parse::{parse_children_mode, parse_table_format};
pub fn resolve_lang(
cli_args: &cli::CliLangArgs,
profile: Option<&Profile>,
) -> tokmd_types::LangArgs {
tokmd_types::LangArgs {
paths: cli_args
.paths
.clone()
.unwrap_or_else(|| vec![PathBuf::from(".")]),
format: cli_args
.format
.map(Into::into)
.or_else(|| parse_table_format(profile.and_then(|p| p.format.as_deref())))
.unwrap_or(tokmd_types::TableFormat::Md),
top: cli_args
.top
.or_else(|| profile.and_then(|p| p.top))
.unwrap_or(0),
files: cli_args.files || profile.and_then(|p| p.files).unwrap_or(false),
children: cli_args
.children
.map(Into::into)
.or_else(|| parse_children_mode(profile.and_then(|p| p.children.as_deref())))
.unwrap_or(tokmd_types::ChildrenMode::Collapse),
}
}
pub fn resolve_lang_with_config(
cli_args: &cli::CliLangArgs,
resolved: &ResolvedConfig,
) -> tokmd_types::LangArgs {
tokmd_types::LangArgs {
paths: cli_args
.paths
.clone()
.unwrap_or_else(|| vec![PathBuf::from(".")]),
format: cli_args
.format
.map(Into::into)
.or_else(|| parse_table_format(resolved.format()))
.unwrap_or(tokmd_types::TableFormat::Md),
top: cli_args.top.or(resolved.top()).unwrap_or(0),
files: cli_args.files || resolved.files().unwrap_or(false),
children: cli_args
.children
.map(Into::into)
.or_else(|| parse_children_mode(resolved.children()))
.unwrap_or(tokmd_types::ChildrenMode::Collapse),
}
}