feat(task): add task template with help table and command sourcing
- Introduce `task.template` file with structured help table for all available commands - Implement dynamic command sourcing from `$HOME/taskfile.build/bin` directory - Add support for searching help entries with optional argument in `help` function - Include comprehensive listing of file, environment, LLM, Git, Pass, KeePass, and Docker commands - Maintain consistent code style and formatting across the template file
This commit is contained in:
2 files changed
+86
No files matched your search
@@ -19,6 +19,7 @@ create-symlink-files() {
|
||||
fi
|
||||
|
||||
# Create the symlink
|
||||
echo "Link $source_file to $target_file."
|
||||
ln -sf "$source_file" "$target_file"
|
||||
fi
|
||||
done
|
||||
|
||||
Executable
+85
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
help-table() {
|
||||
local cmd_width=24
|
||||
local opt_width=18
|
||||
local desc_width=50
|
||||
local column="| %-${cmd_width}s | %-${opt_width}s | %-${desc_width}s |\n"
|
||||
|
||||
printf "$column" "Command" "Option" "Description"
|
||||
echo "|$(printf '%*s' $((cmd_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((opt_width + 2)) '' | tr ' ' '-')|$(printf '%*s' $((desc_width + 2)) '' | tr ' ' '-')|"
|
||||
# Task
|
||||
printf "$column" 'init-config-dir' '' 'Setup task file config dir.'
|
||||
printf "$column" 'template-dotenv' '' 'Generate .env from .env.template.'
|
||||
printf "$column" 'open-with-os' '' 'Open file or url with default application.'
|
||||
printf "$column" 'open-url-with-delay' '[url][delay]' 'Open url after n seconds.'
|
||||
# Files
|
||||
printf "$column" 'ensure-directory' '[path]' 'Ensure directory path exists.'
|
||||
printf "$column" 'create-symlink' '[source][target]' 'Remove existing file/directory and create symlink.'
|
||||
printf "$column" 'create-symlink-files' '[source][target]' 'Create symlink for files in source pattern.'
|
||||
# Python
|
||||
printf "$column" 'activate-venv' '' 'Activate or initialize Python virtual env.'
|
||||
# Environment
|
||||
printf "$column" 'create-odoo-env' '[env]' 'Create env file for Odoo instance.'
|
||||
printf "$column" 'create-nextcloud-env' '[env]' 'Create env file for Nextcloud Instance.'
|
||||
printf "$column" 'list-env' '' 'List env files.'
|
||||
printf "$column" 'show-env' '[env]' 'Output content of the env file.'
|
||||
printf "$column" 'copy-env' '[env][env]' 'Copy env file.'
|
||||
printf "$column" 'edit-env' '[env]' 'Open env file in default editor.'
|
||||
printf "$column" 'load-env' '[env]' 'Load and export env file.'
|
||||
printf "$column" 'rename-env' '[env][env]' 'Rename env file.'
|
||||
printf "$column" 'remove-env' '[env]' 'Remove environment config.'
|
||||
printf "$column" 'backup-env-files' '[path]' 'Archive and copy env files to target location.'
|
||||
printf "$column" 'restore-env-files' '[path]' 'Extract and copy env files from backup file.'
|
||||
# LLM
|
||||
printf "$column" 'commit-with-llm' '' 'Commit with llm generated commit message.'
|
||||
printf "$column" 'update-with-llm' '[glob][prompt]' 'Feed files matching glob to LLM and apply changes.'
|
||||
# Logging
|
||||
printf "$column" 'log-warning' '' 'Colored output for warnings.'
|
||||
# Git
|
||||
printf "$column" 'update-submodule' '' 'Update git submodules.'
|
||||
# Pass
|
||||
printf "$column" 'save-dotenv-to-pass' '' 'Store content of .env in pass entry.'
|
||||
printf "$column" 'load-dotenv-from-pass' '' 'Restore content to .env from pass entry.'
|
||||
# KeePass
|
||||
printf "$column" 'save-pass-to-keepass' '[pass][entry]' 'Store password to KeePass entry.'
|
||||
printf "$column" 'get-pass-from-keepass' '[entry]' 'Get password from KeePass entry.'
|
||||
printf "$column" 'save-dotenv-to-keepass' '' 'Store content of .env in KeePass entry.'
|
||||
printf "$column" 'load-dotenv-from-keepass' '' 'Restore content to .env from KeePass entry.'
|
||||
# Docker
|
||||
printf "$column" 'login-docker' '[user][token]' 'Run Docker login and create docker config.'
|
||||
printf "$column" 'build-image' '[output]' 'Build Docker image with buildx.'
|
||||
}
|
||||
|
||||
help() {
|
||||
echo
|
||||
if [[ -n "$1" ]]; then
|
||||
help-table | grep -i "$1" | column -t -s'|'
|
||||
else
|
||||
echo "task <command> [options]"
|
||||
echo
|
||||
echo "commands:"
|
||||
echo
|
||||
help-table
|
||||
fi
|
||||
echo
|
||||
}
|
||||
|
||||
if [[ -d "$HOME/taskfile.build/bin" ]]; then
|
||||
for file in "$HOME/taskfile.build/bin/"*; do
|
||||
if [[ -f "$file" ]]; then
|
||||
source "$file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if declare -f "$1" > /dev/null; then
|
||||
"$1" "${@:2}"
|
||||
else
|
||||
case "$1" in
|
||||
*)
|
||||
echo "Unknown command: $1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
Reference in new issue
Block a user