55 lines
1.7 KiB
Plaintext
55 lines
1.7 KiB
Plaintext
#!/usr/bin/env nu
|
|
|
|
# Add module-level docstrings to all .nu files
|
|
#
|
|
# Scans all .nu files and adds module-level docstrings to those missing them
|
|
|
|
use std log
|
|
|
|
def main [--dry-run = false --verbose = false] {
|
|
log info "Starting module docstring addition..."
|
|
|
|
let nu_files = (find /Users/Akasha/project-provisioning/provisioning -name "*.nu" -type f | lines)
|
|
let mut files_processed = 0
|
|
let mut files_updated = 0
|
|
let mut files_skipped = 0
|
|
|
|
for file in $nu_files {
|
|
let content = open $file
|
|
let has_module_doc = ($content =~ '(?m)^# [A-Z].*\n#')
|
|
|
|
if not $has_module_doc and ($content | str starts-with "#!/usr/bin/env nu") {
|
|
# File has shebang but no module docstring
|
|
if $verbose {
|
|
log info $"Adding docstring to: ($file)"
|
|
}
|
|
|
|
if not $dry_run {
|
|
# Extract module name from filename
|
|
let filename = ($file | path basename | str replace '.nu' '')
|
|
let module_name = ($filename | str replace '-' '_' | str capitalize)
|
|
|
|
# Add module docstring after shebang
|
|
let lines = $content | lines
|
|
let new_content = (
|
|
($lines | first 1 | str join "\n") + "\n\n# " + $module_name + "\n" +
|
|
($lines | skip 1 | str join "\n")
|
|
)
|
|
|
|
$new_content | save --force $file
|
|
$files_updated += 1
|
|
} else {
|
|
$files_updated += 1
|
|
}
|
|
} else {
|
|
$files_skipped += 1
|
|
}
|
|
|
|
$files_processed += 1
|
|
}
|
|
|
|
log info $"Processing complete. Processed: ($files_processed), Updated: ($files_updated), Skipped: ($files_skipped)"
|
|
}
|
|
|
|
main
|