#!/bin/bash # tin - Modern CLI set -euo pipefail # Get script directory and tinsnip root SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TINSNIP_ROOT="$(dirname "$SCRIPT_DIR")" # Source shared functions source "$TINSNIP_ROOT/lib/core.sh" # CLI version and info TIN_VERSION="1.0.0" TIN_NAME="tin" # Global CLI functions show_version() { echo "$TIN_NAME version $TIN_VERSION" echo "tinsnip Infrastructure Platform CLI" } show_global_help() { cat << EOF tin - tinsnip Infrastructure Platform CLI USAGE: tin [options] COMMANDS: sheet Create or register sheet machine Create service machine environment service Deploy service to machine nas Manage NAS server registrations key Manage SSH keys for NAS access status Show tinsnip status help Show this help message version Show version information EXAMPLES: tin sheet infrastructure # Register infrastructure sheet tin machine gazette prod # Create gazette-prod machine (auto-discover NAS) tin service gazette-prod lldap # Deploy lldap to gazette-prod tin nas add infrastructure DS412plus # Register NAS server for sheet tin key generate DS412plus # Generate SSH key for NAS server tin status # Show tinsnip status GETTING STARTED: 1. Set up tinsnip's topsheet: TIN_SHEET=topsheet tin machine station prod 2. Register your first sheet: tin sheet infrastructure 3. Create a service machine: tin machine gateway prod 4. Deploy a service: tin service gateway-prod lldap For more information on a specific command, use: tin --help EOF } # Command routing route_command() { local cmd="${1:-}" shift || true case "$cmd" in # Core commands sheet) # Route to new cmd/ structure local subcmd="${1:-create}" case "$subcmd" in --help|-h|help) exec "$TINSNIP_ROOT/cmd/sheet/create.sh" "--help" ;; create|"") exec "$TINSNIP_ROOT/cmd/sheet/create.sh" "${@:2}" ;; list) exec "$TINSNIP_ROOT/cmd/sheet/list.sh" "${@:2}" ;; show) exec "$TINSNIP_ROOT/cmd/sheet/show.sh" "${@:2}" ;; rm|remove) exec "$TINSNIP_ROOT/cmd/sheet/rm.sh" "${@:2}" ;; *) # Default behavior: treat first arg as sheet name for create exec "$TINSNIP_ROOT/cmd/sheet/create.sh" "$@" ;; esac ;; machine) # Route to new cmd/ structure local subcmd="${1:-create}" case "$subcmd" in --help|-h|help) exec "$TINSNIP_ROOT/cmd/machine/create.sh" "--help" ;; create|"") exec "$TINSNIP_ROOT/cmd/machine/create.sh" "${@:2}" ;; list) exec "$TINSNIP_ROOT/cmd/machine/list.sh" "${@:2}" ;; status) exec "$TINSNIP_ROOT/cmd/machine/status.sh" "${@:2}" ;; rm|remove) exec "$TINSNIP_ROOT/cmd/machine/rm.sh" "${@:2}" ;; *) # Default behavior: treat first two args as service environment for create exec "$TINSNIP_ROOT/cmd/machine/create.sh" "$@" ;; esac ;; service) # Route to new cmd/ structure local subcmd="${1:-deploy}" case "$subcmd" in --help|-h|help) exec "$TINSNIP_ROOT/cmd/service/deploy.sh" "--help" ;; deploy|"") exec "$TINSNIP_ROOT/cmd/service/deploy.sh" "${@:2}" ;; list) exec "$TINSNIP_ROOT/cmd/service/list.sh" "${@:2}" ;; status) exec "$TINSNIP_ROOT/cmd/service/status.sh" "${@:2}" ;; logs) exec "$TINSNIP_ROOT/cmd/service/logs.sh" "${@:2}" ;; stop) exec "$TINSNIP_ROOT/cmd/service/stop.sh" "${@:2}" ;; rm|remove) exec "$TINSNIP_ROOT/cmd/service/rm.sh" "${@:2}" ;; *) # Default behavior: treat args as service-env and catalog-service for deploy exec "$TINSNIP_ROOT/cmd/service/deploy.sh" "$@" ;; esac ;; # Management commands nas) # Route to new cmd/ structure local subcmd="${1:-list}" case "$subcmd" in --help|-h|help) exec "$TINSNIP_ROOT/cmd/nas/list.sh" "--help" ;; list|"") exec "$TINSNIP_ROOT/cmd/nas/list.sh" "${@:2}" ;; show) exec "$TINSNIP_ROOT/cmd/nas/show.sh" "${@:2}" ;; add) exec "$TINSNIP_ROOT/cmd/nas/add.sh" "${@:2}" ;; discover) exec "$TINSNIP_ROOT/cmd/nas/discover.sh" "${@:2}" ;; *) echo "Error: Unknown nas command '$subcmd'" >&2 echo "Available: list, show, add, discover" >&2 exit 1 ;; esac ;; key) # Already migrated - uses new cmd/ structure local subcmd="${1:-generate}" case "$subcmd" in --help|-h|help) exec "$TINSNIP_ROOT/cmd/key/help.sh" ;; generate|"") exec "$TINSNIP_ROOT/cmd/key/generate.sh" "${@:2}" ;; install) exec "$TINSNIP_ROOT/cmd/key/install.sh" "${@:2}" ;; list) exec "$TINSNIP_ROOT/cmd/key/list.sh" "${@:2}" ;; status) exec "$TINSNIP_ROOT/cmd/key/status.sh" "${@:2}" ;; remove) exec "$TINSNIP_ROOT/cmd/key/remove.sh" "${@:2}" ;; test) exec "$TINSNIP_ROOT/cmd/key/test.sh" "${@:2}" ;; show) exec "$TINSNIP_ROOT/cmd/key/show.sh" "${@:2}" ;; help) exec "$TINSNIP_ROOT/cmd/key/help.sh" ;; *) echo "Error: Unknown key command '$subcmd'" >&2 echo "Available: generate, install, list, status, remove, test, show, help" >&2 exit 1 ;; esac ;; # Info commands status) # Route to new cmd/ structure exec "$TINSNIP_ROOT/cmd/status/show.sh" "$@" ;; version|--version|-V) show_version ;; help|--help|-h) show_global_help ;; # Legacy compatibility setup) warn_with_prefix "tin" "Legacy 'setup' command. Use 'tin machine' instead" exec "$TINSNIP_ROOT/machine/setup.sh" "$@" ;; # Unknown command "") echo "Error: No command specified" >&2 echo "Use 'tin help' for usage information" >&2 exit 1 ;; *) echo "Error: Unknown command '$cmd'" >&2 echo "Use 'tin help' for available commands" >&2 exit 1 ;; esac } # Main entry point main() { # Handle global flags first case "${1:-}" in --version|-V) show_version exit 0 ;; --help|-h) show_global_help exit 0 ;; esac # Route to appropriate subcommand route_command "$@" } main "$@"