feat: add version command with JSON output support
This commit is contained in:
71
ollama
71
ollama
@@ -9,6 +9,7 @@ DEFAULT_MODEL="llama3:8b"
|
|||||||
CONTEXT_FILE="${OLLAMA_CONTEXT_FILE:-$HOME/.ollama/context.json}"
|
CONTEXT_FILE="${OLLAMA_CONTEXT_FILE:-$HOME/.ollama/context.json}"
|
||||||
PROFILE_DIR="${OLLAMA_PROFILE_DIR:-$HOME/.ollama/profiles}"
|
PROFILE_DIR="${OLLAMA_PROFILE_DIR:-$HOME/.ollama/profiles}"
|
||||||
OUTPUT_FORMAT="text" # Can be "text" or "json"
|
OUTPUT_FORMAT="text" # Can be "text" or "json"
|
||||||
|
SCRIPT_VERSION="1.0.0"
|
||||||
|
|
||||||
# Check for required dependencies
|
# Check for required dependencies
|
||||||
check_dependencies() {
|
check_dependencies() {
|
||||||
@@ -941,6 +942,7 @@ Commands:
|
|||||||
embed <text> [options] Generate embeddings for text (supports stdin)
|
embed <text> [options] Generate embeddings for text (supports stdin)
|
||||||
model <subcommand> Manage models
|
model <subcommand> Manage models
|
||||||
profile <subcommand> Manage profiles
|
profile <subcommand> Manage profiles
|
||||||
|
version Show script and Ollama server version
|
||||||
help [command] Show this help message or help for a specific command
|
help [command] Show this help message or help for a specific command
|
||||||
|
|
||||||
For detailed help on a command, run:
|
For detailed help on a command, run:
|
||||||
@@ -1078,6 +1080,69 @@ Examples:
|
|||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
help_version() {
|
||||||
|
cat << 'EOF'
|
||||||
|
Usage: ollama version [options]
|
||||||
|
|
||||||
|
Display the CLI script version and the Ollama server version.
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-o, --output FORMAT Output format: text (default) or json
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
ollama version
|
||||||
|
ollama version -o json
|
||||||
|
ollama version -o json | jq '.ollama_version'
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get version information
|
||||||
|
version() {
|
||||||
|
local output_format="$OUTPUT_FORMAT"
|
||||||
|
|
||||||
|
# Parse output format flag
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-o|--output)
|
||||||
|
output_format="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
local password
|
||||||
|
password=$(get_password)
|
||||||
|
|
||||||
|
# Get Ollama server version
|
||||||
|
local api_response
|
||||||
|
api_response=$(curl -s -u "$OLLAMA_USER:$password" \
|
||||||
|
-X GET "$OLLAMA_API_URL/version")
|
||||||
|
|
||||||
|
if ! echo "$api_response" | jq . &>/dev/null; then
|
||||||
|
echo "Error: Invalid response from API" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if echo "$api_response" | jq -e '.error' &>/dev/null; then
|
||||||
|
echo "Error: $(echo "$api_response" | jq -r '.error')" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local ollama_version
|
||||||
|
ollama_version=$(echo "$api_response" | jq -r '.version // "unknown"')
|
||||||
|
|
||||||
|
if [[ "$output_format" == "json" ]]; then
|
||||||
|
echo "$api_response" | jq --arg cli_version "$SCRIPT_VERSION" '{cli_version: $cli_version, ollama_version: .version}'
|
||||||
|
else
|
||||||
|
echo "ollama CLI version $SCRIPT_VERSION"
|
||||||
|
echo ""
|
||||||
|
echo "Ollama version $ollama_version"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
main() {
|
main() {
|
||||||
local command="${1:-help}"
|
local command="${1:-help}"
|
||||||
@@ -1098,6 +1163,9 @@ main() {
|
|||||||
profile)
|
profile)
|
||||||
profile "${@:2}"
|
profile "${@:2}"
|
||||||
;;
|
;;
|
||||||
|
version)
|
||||||
|
version "${@:2}"
|
||||||
|
;;
|
||||||
help|--help|-h)
|
help|--help|-h)
|
||||||
if [[ $# -gt 1 ]]; then
|
if [[ $# -gt 1 ]]; then
|
||||||
local help_topic="$2"
|
local help_topic="$2"
|
||||||
@@ -1117,6 +1185,9 @@ main() {
|
|||||||
model|models)
|
model|models)
|
||||||
help_model
|
help_model
|
||||||
;;
|
;;
|
||||||
|
version)
|
||||||
|
help_version
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Error: unknown command '$help_topic'" >&2
|
echo "Error: unknown command '$help_topic'" >&2
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
Reference in New Issue
Block a user