Function hyper_scripter::util::main_util::load_utils
source · pub async fn load_utils(script_repo: &mut ScriptRepo) -> ResultExamples found in repository?
src/util/init_repo.rs (line 71)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
pub async fn init_repo(args: RootArgs, need_journal: bool) -> Result<ScriptRepo> {
let RootArgs {
no_trace,
humble,
archaeology,
select,
toggle,
recent,
timeless,
..
} = args;
let conf = Config::get();
let recent = if timeless {
None
} else {
recent.or(conf.recent).map(|recent| RecentFilter {
recent,
archaeology,
})
};
// TODO: 測試 toggle 功能,以及名字不存在的錯誤
let tag_group = {
let mut toggle: HashSet<_> = toggle.into_iter().collect();
let mut tag_group = conf.get_tag_selector_group(&mut toggle);
if let Some(name) = toggle.into_iter().next() {
return Err(Error::TagSelectorNotFound(name));
}
for select in select.into_iter() {
tag_group.push(select);
}
tag_group
};
let (env, init) = init_env(need_journal).await?;
let mut repo = ScriptRepo::new(recent, env, &tag_group)
.await
.context("載入腳本倉庫失敗")?;
if no_trace {
repo.no_trace();
} else if humble {
repo.humble();
}
if init {
log::info!("初次使用,載入好用工具和預執行腳本");
main_util::load_utils(&mut repo).await?;
main_util::prepare_pre_run(None)?;
main_util::load_templates()?;
}
Ok(repo)
}