diff options
| author | ja <[email protected]> | 2025-12-23 14:47:32 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-23 13:47:32 -0600 |
| commit | 10eed6ee7eea3cbc266e1fdfee880aa4722691d1 (patch) | |
| tree | e27c47d3efd42abbd87f161172f3bf11abdbd785 /install | |
| parent | 59b87f60f72e547d35a16a37bb93ea3719eaa67b (diff) | |
| download | opencode-10eed6ee7eea3cbc266e1fdfee880aa4722691d1.tar.gz opencode-10eed6ee7eea3cbc266e1fdfee880aa4722691d1.zip | |
feat(install): add standard CLI flags (--help, --version, --no-modify-path) (#5885)
Diffstat (limited to 'install')
| -rwxr-xr-x | install | 114 |
1 files changed, 79 insertions, 35 deletions
@@ -7,7 +7,51 @@ RED='\033[0;31m' ORANGE='\033[38;5;214m' NC='\033[0m' # No Color +usage() { + cat <<EOF +OpenCode Installer + +Usage: install.sh [options] + +Options: + -h, --help Display this help message + -v, --version <version> Install a specific version (e.g., 1.0.180) + --no-modify-path Don't modify shell config files (.zshrc, .bashrc, etc.) + +Examples: + curl -fsSL https://opencode.ai/install | bash + curl -fsSL https://opencode.ai/install | bash -s -- --version 1.0.180 +EOF +} + requested_version=${VERSION:-} +no_modify_path=false + +while [[ $# -gt 0 ]]; do + case "$1" in + -h|--help) + usage + exit 0 + ;; + -v|--version) + if [[ -n "${2:-}" ]]; then + requested_version="$2" + shift 2 + else + echo -e "${RED}Error: --version requires a version argument${NC}" + exit 1 + fi + ;; + --no-modify-path) + no_modify_path=true + shift + ;; + *) + echo -e "${ORANGE}Warning: Unknown option '$1'${NC}" >&2 + shift + ;; + esac +done raw_os=$(uname -s) os=$(echo "$raw_os" | tr '[:upper:]' '[:lower:]') @@ -304,42 +348,42 @@ case $current_shell in ;; esac -config_file="" -for file in $config_files; do - if [[ -f $file ]]; then - config_file=$file - break +if [[ "$no_modify_path" != "true" ]]; then + config_file="" + for file in $config_files; do + if [[ -f $file ]]; then + config_file=$file + break + fi + done + + if [[ -z $config_file ]]; then + print_message warning "No config file found for $current_shell. You may need to manually add to PATH:" + print_message info " export PATH=$INSTALL_DIR:\$PATH" + elif [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then + case $current_shell in + fish) + add_to_path "$config_file" "fish_add_path $INSTALL_DIR" + ;; + zsh) + add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" + ;; + bash) + add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" + ;; + ash) + add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" + ;; + sh) + add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" + ;; + *) + export PATH=$INSTALL_DIR:$PATH + print_message warning "Manually add the directory to $config_file (or similar):" + print_message info " export PATH=$INSTALL_DIR:\$PATH" + ;; + esac fi -done - -if [[ -z $config_file ]]; then - print_message error "No config file found for $current_shell. Checked files: ${config_files[@]}" - exit 1 -fi - -if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then - case $current_shell in - fish) - add_to_path "$config_file" "fish_add_path $INSTALL_DIR" - ;; - zsh) - add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" - ;; - bash) - add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" - ;; - ash) - add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" - ;; - sh) - add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH" - ;; - *) - export PATH=$INSTALL_DIR:$PATH - print_message warning "Manually add the directory to $config_file (or similar):" - print_message info " export PATH=$INSTALL_DIR:\$PATH" - ;; - esac fi if [ -n "${GITHUB_ACTIONS-}" ] && [ "${GITHUB_ACTIONS}" == "true" ]; then |
