Contents of .config/mise/config.toml
```toml
[settings]
quiet = true
env_shell_expand = true
lockfile = true
[tools]
"aqua:nushell/nushell" = "latest"
[tasks.work]
usage = '''
arg "" help="Target environment"
arg "" help="Target environment"
arg "" help="Target environment"
'''
run = '''
#!/usr/bin/env nu
let template_dir = ".config/template"
let config_dir = ".config"
# let out_dir = $"(pwd)"
let out_dir = $"(pwd)/works"
def not_main [subject: string, shortcode: string, number?: int] {
let subject_lower = ($subject | str downcase)
let shortcode_lower = ($shortcode | str downcase)
validate-input $subject $shortcode $number
let temp_dir = $"/tmp/nure-work-(random chars -l 8)"
let final_dir = $"($out_dir)/($subject_lower)/($shortcode_lower)($number)"
let subject_dir = $"($out_dir)/($subject_lower)"
# TODO?: replace with git clone
cp -r ($config_dir)/template $temp_dir
generate-doc-toml $shortcode_lower $subject_lower $temp_dir $number
check-mkdir $out_dir
if ($final_dir | path exists) {
error make -u {msg: $"Directory ($final_dir) already exists"}
}
check-mkdir $subject_dir; cp -r $temp_dir $final_dir; rm -rf $temp_dir
print $"=> Created new work: ($final_dir)"
}
def check-mkdir [path: string] { if not ($path | path exists) { mkdir $path } }
def validate-input [subject: string, shortcode: string, number?: int] {
if not ($config_dir | path exists) {
error make -u {msg: $"($config_dir) not found"}
}
let defaults_yaml = $"($config_dir)/defaults.yaml"
let subjects_yaml = $"($config_dir)/subjects.yaml"
if not ($defaults_yaml | path exists) {
error make -u {msg: $"defaults.yaml not found in ($config_dir)"}
}
if not ($subjects_yaml | path exists) {
error make -u {msg: $"subjects.yaml not found in ($config_dir)"}
}
if ($number != nothing and $number < 1 ) {
error make -u {msg: "Work number should be greater than 0"}
}
let subject_lower = ($subject | str downcase)
let subjects = (open $subjects_yaml | columns)
if $subject_lower not-in $subjects {
error make -u {
msg: $"Subject '($subject)' not found in configuration"
help: $"Available subjects: ($subjects | str join ', ')"
}
}
}
def generate-doc-toml [shortcode: string, subject: string, target_dir: string, number?: int] {
let defaults = (open $"($config_dir)/defaults.yaml")
let subjects = (open $"($config_dir)/subjects.yaml")
let subject_data = ($subjects | get $subject)
let work_type = ($defaults | get work_types | try { get $shortcode } catch { $shortcode })
{
university: ($defaults | get university)
subject: ($subject_data | get name), type: $work_type, number: $number
mentors: ($subject_data | get mentors), authors: [($defaults | get default_author)]
} | compact --empty | to toml | save $"($target_dir)/src/doc.toml" --force
}
not_main {{usage.subject}} {{usage.type}} {{usage.number}}
'''
```
`template/` is this empty template without `doc.toml`
Nushell script does two things:
- Creates a new work from a template: `works/smp/lb1`
- Auto-fills `doc.toml` with data from `defaults.yaml` and mentor data from `subjects.yaml`
### Patching the package
A patch to add new subjects:
```diff
diff --git a/src/config/universities.yaml b/src/config/universities.yaml
index 8855a07..1aefc96 100644
--- a/src/config/universities.yaml
+++ b/src/config/universities.yaml
@@ -60,7 +60,6 @@
ПЕСЕ: Психологія екстремальних стосунків та ефективної адаптації
ПНП: Програмування на платформі .NЕТ
ПП: Проектний практикум
- ПРОГ: Програмування
ПарП: Параллельне програмування
СА: Системний аналіз
СМП: Скриптові мови програмування
@@ -76,3 +75,10 @@
ФІЛ: Філософія
ФВС: Фізичне виховання та спорт
ХТ: Хмарні технології
+ АКС: Архітектура комп'ютерних систем
+ ІКС: Інформаційно-комунікаційні системи
+ МБ: Мережна безпека
+ МКр: Мережна криміналістика
+ ОКЗІ: Основи криптографічного захисту інформації
+ Прог: Програмування
+ ТІК: Теорія інформації та кодування
```
To apply it, add the following command to the end of `fetch_nure_package` task:
```sh
git -C {{vars.nure_package_path}} apply --check --apply --quiet $MISE_PROJECT_ROOT/custom-subjects.patch || exit 0
```