如何通过Composer更新Windows上的WP-CLI?

时间:2015-12-10 作者:syntax53

我在四月份使用composer在我的Windows机箱上安装了wp cli。我相信以下命令:composer create-project wp-cli/wp-cli --no-dev 如上的备用安装方法中所述here.

从那以后,我使用了“composer update --no-dev“要更新,但刚刚意识到它只是更新依赖项,而不是wp cli包本身。如果我运行”wp cli version“它报告了WP-CLI 0.18.0版本,而v0.20.4是最新发布的版本。

我似乎找不到任何方法来更新wp cli。我想我每次都可以安装一个新的副本,但这似乎很愚蠢。不管怎样,我做了测试,如果我发布了“composer create-project wp-cli/wp-cli --no-dev“在新目录中,它下载最新版本。我也尝试了”wp cli update“但它会报告”错误:您只能自我更新PHARs。“”

2 个回复
SO网友:Daniel Bachhuber

您需要删除composer.lock 运行前composer update. composer.lock 将Composer项目锁定到特定哈希。

SO网友:syntax53

显然,仅使用composer是不可能的。对于安装WP-CLI的推荐方式来说,这似乎有点愚蠢,因为以后没有直接的更新方法。我最终安装了GIT,然后重新安装(例如。git clone https://github.com/wp-cli/wp-cli.git d:\\wp-cli) wp cli的。之后,发布了composer update --no-dev 安装依赖项。现在在将来更新wp cli I rungit pull origin 来自d:\\wp cli,后跟composer update --no-dev.

如果这是错误的,请告诉我!:)

编辑--

因此,我意识到上面的命令正在更新为主分支中的最新提交。我找不到任何自动更新到最新分支的方法,所以我编写了以下批处理文件。它从wp cli repo查询所有标记,遍历它们以找到最新的标记(因为它们是按alpha排序的),然后克隆或重置(如果本地repo已经存在)到该标记。然后通过composer更新依赖项。

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET WPCLI_INSTALL_DRIVE=D:
SET WPCLI_INSTALL_DIR=WP-CLI
SET LATEST_WPCLI_MAJOR=-1
SET LATEST_WPCLI_MINOR=0
SET LATEST_WPCLI_REV=0
echo.
echo COMMIT_ID - TAG_NAME ^=^> VERSION_DETECTION [*] (* ^= Marked as latest)
for /f "tokens=1*" %%A in (\'git ls-remote --tags https://github.com/wp-cli/wp-cli.git\') do (
    SET "TAG_LINE=%%A"
    IF NOT "%%B"=="" (
        SET "TAG_LINE=!TAG_LINE! - %%B"
        for /f "tokens=2 delims=v" %%C in ("%%B") do (
            echo "%%C"|find /i ".">nul
            IF NOT ERRORLEVEL 1 (
                for /f "tokens=1-3 delims=." %%D in ("%%C") do (
                    SET "TAG_LINE=!TAG_LINE! ^=^> v%%D.%%E.%%F"
                    SET LATEST_WPCLI_FOUND=0

                    IF /I %%D GTR !LATEST_WPCLI_MAJOR! (
                        SET LATEST_WPCLI_FOUND=1
                    ) ELSE (
                        IF /I %%D GEQ !LATEST_WPCLI_MAJOR! (
                            IF /I %%E GTR !LATEST_WPCLI_MINOR! (
                                SET LATEST_WPCLI_FOUND=1
                            ) ELSE (
                                IF /I %%E GEQ !LATEST_WPCLI_MINOR! (
                                    IF /I %%F GTR !LATEST_WPCLI_REV! (
                                        SET LATEST_WPCLI_FOUND=1
                                    )
                                )
                            )
                        )
                    )

                    IF "!LATEST_WPCLI_FOUND!"=="1" (
                        SET "TAG_LINE=!TAG_LINE! *"
                        SET LATEST_WPCLI_MAJOR=%%D
                        SET LATEST_WPCLI_MINOR=%%E
                        SET LATEST_WPCLI_REV=%%F
                    )
                )
            )
        )
    )
    echo !TAG_LINE!
)

echo.
echo.

IF NOT "%LATEST_WPCLI_MAJOR%"=="-1" (
    echo Latest detected tag: v%LATEST_WPCLI_MAJOR%.%LATEST_WPCLI_MINOR%.%LATEST_WPCLI_REV%
    echo.
    IF EXIST "%WPCLI_INSTALL_DRIVE%\\%WPCLI_INSTALL_DIR%\\bin\\wp.bat" (
        echo Current WP-CLI Version:
        call "%WPCLI_INSTALL_DRIVE%\\%WPCLI_INSTALL_DIR%\\bin\\wp.bat" cli version
    ) ELSE (
        echo Current "%WPCLI_INSTALL_DRIVE%\\%WPCLI_INSTALL_DIR%\\bin\\wp.bat" not found to display current version.
    )
    echo.
    choice /m "Continue installing/updating?"
    IF ERRORLEVEL 2 exit /b 0

    IF EXIST "%WPCLI_INSTALL_DRIVE%\\%WPCLI_INSTALL_DIR%\\.gitignore" (
        CHDIR /D "%WPCLI_INSTALL_DRIVE%\\%WPCLI_INSTALL_DIR%"
        git reset --hard "v%LATEST_WPCLI_MAJOR%.%LATEST_WPCLI_MINOR%.%LATEST_WPCLI_REV%"
    ) ELSE (
        git clone --branch "v%LATEST_WPCLI_MAJOR%.%LATEST_WPCLI_MINOR%.%LATEST_WPCLI_REV%" https://github.com/wp-cli/wp-cli.git %WPCLI_INSTALL_DRIVE%\\%WPCLI_INSTALL_DIR%
        CHDIR /D "%WPCLI_INSTALL_DRIVE%\\%WPCLI_INSTALL_DIR%"
    )
    IF EXIST "composer.json" call composer update --no-dev
) ELSE (
    echo Latest version not found.
)
pause