Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## 19.2.0

* Added `completion install` command with completion scripts for zsh, bash, and fish
* Added automatic shell-completion install step to the `install.sh` standalone installer
* Updated Homebrew install and update flow to detect the installed formula and recommend the official `appwrite/appwrite/appwrite` tap when a different one is in use
* Fixed standalone update check to point at the `appwrite/sdk-for-cli` releases feed instead of the legacy `appwrite/appwrite-cli` repo

## 19.1.0

* Added `--where`, `--sort-asc`, `--sort-desc`, `--limit`, `--offset`, `--cursor-after`, and `--cursor-before` flags on list commands across services
Expand Down
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using

```sh
$ appwrite -v
19.1.0
19.2.0
```

### Install using prebuilt binaries
Expand All @@ -49,6 +49,27 @@ $ brew install appwrite/appwrite/appwrite

Homebrew pulls the formula from the [`appwrite/homebrew-appwrite`](https://github.com/appwrite/homebrew-appwrite) tap and downloads the native binary for your platform.

### Shell completion

Install completion for your current shell:

```bash
appwrite completion install
```

You can also generate or install completion scripts manually:

```bash
# zsh
appwrite completion install zsh
# bash
appwrite completion install bash
# fish
appwrite completion install fish
```

For zsh, ensure `~/.zfunc` is in your `fpath` and `compinit` is loaded from your shell config.

### Windows
Via Powershell
```powershell
Expand All @@ -62,7 +83,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc
Once the installation completes, you can verify your install using
```
$ appwrite -v
19.1.0
19.2.0
```

## Getting Started
Expand Down
19 changes: 16 additions & 3 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import {
syncVersionCheckCache,
} from './lib/utils.js';
import inquirerSearchList from 'inquirer-search-list';
import {
createCompletionCommand,
isCompletionCommand,
isCompletionInvocation,
} from './lib/completions.js';

import { client } from './lib/commands/generic.js';
import { login, logout, whoami, migrate, register } from './lib/commands/generic.js';
Expand Down Expand Up @@ -55,7 +60,6 @@ import { webhooks } from './lib/commands/services/webhooks.js';
const { version } = packageJson;
inquirer.registerPrompt('search-list', inquirerSearchList);
const VERSION_CHECK_TIMEOUT_MS = 5000;

function writeUpdateAvailableNotice(currentVersion: string, latestVersion: string, toStderr: boolean = false): void {
const stream = toStderr ? process.stderr : process.stdout;

Expand Down Expand Up @@ -126,7 +130,9 @@ if (process.argv.includes('-v') || process.argv.includes('--version')) {
})();
} else {
void (async () => {
await maybeShowUpdateNotice();
if (!isCompletionInvocation()) {
await maybeShowUpdateNotice();
}

program
.name('appwrite')
Expand All @@ -141,7 +147,13 @@ if (process.argv.includes('-v') || process.argv.includes('--version')) {
.option('-j, --json', 'Output filtered JSON without empty values')
.option('-R, --raw', 'Output full JSON response (secrets still redacted unless --show-secrets is set)')
.option('--show-secrets', 'Display sensitive values like secrets and tokens in output')
.hook('preAction', migrate)
.hook('preAction', async (_thisCommand, actionCommand) => {
if (isCompletionCommand(actionCommand)) {
return;
}

await migrate();
})
.option('-f,--force', 'Flag to confirm all warnings')
.option('-a,--all', 'Flag to push all resources')
.option('--id [id...]', 'Flag to pass a list of ids for a given action')
Expand Down Expand Up @@ -214,6 +226,7 @@ if (process.argv.includes('-v') || process.argv.includes('--version')) {
.addCommand(users)
.addCommand(vcs)
.addCommand(webhooks)
.addCommand(createCompletionCommand(program))
.addCommand(client)
.parse(process.argv);

Expand Down
4 changes: 2 additions & 2 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# You can use "View source" of this page to see the full script.

# REPO
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/19.1.0/appwrite-cli-win-x64.exe"
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/19.1.0/appwrite-cli-win-arm64.exe"
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/19.2.0/appwrite-cli-win-x64.exe"
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/19.2.0/appwrite-cli-win-arm64.exe"

$APPWRITE_BINARY_NAME = "appwrite.exe"

Expand Down
32 changes: 27 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ARCH=""
# Add some color to life
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color

greeting() {
Expand All @@ -55,7 +56,7 @@ EOF
}

getSystemInfo() {
echo "[1/4] Getting System Info ..."
echo "[1/5] Getting System Info ..."

ARCH=$(uname -m)
case $ARCH in
Expand Down Expand Up @@ -93,6 +94,10 @@ printSuccess() {
printf "${GREEN}✅ Done ... ${NC}\n\n"
}

printSkipped() {
printf "${YELLOW}ℹ️ $1 ${NC}\n"
}

verifyMacOSCodeSignature() {
if [ "$OS" != "darwin" ]; then
return
Expand All @@ -113,9 +118,9 @@ verifyMacOSCodeSignature() {
}

downloadBinary() {
echo "[2/4] Downloading executable for $OS ($ARCH) ..."
echo "[2/5] Downloading executable for $OS ($ARCH) ..."

GITHUB_LATEST_VERSION="19.1.0"
GITHUB_LATEST_VERSION="19.2.0"
GITHUB_FILE="appwrite-cli-${OS}-${ARCH}"
GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE"

Expand All @@ -130,7 +135,7 @@ downloadBinary() {
}

install() {
echo "[3/4] Installing ..."
echo "[3/5] Installing ..."

printf "${GREEN}🚧 Setting Permissions ${NC}\n"
chmod +x $APPWRITE_TEMP_NAME
Expand All @@ -151,6 +156,22 @@ install() {
printSuccess
}

installCompletions() {
echo "[4/5] Installing shell completions ..."

if $APPWRITE_EXECUTABLE_FILEPATH completion install; then
printSuccess
return
fi

printSkipped "Skipped shell completion installation. To install manually, run:"
echo " $APPWRITE_EXECUTABLE_NAME completion install"
echo " $APPWRITE_EXECUTABLE_NAME completion install zsh"
echo " $APPWRITE_EXECUTABLE_NAME completion install bash"
echo " $APPWRITE_EXECUTABLE_NAME completion install fish"
echo ""
}

cleanup() {
printf "${GREEN}🧹 Cleaning up mess ... ${NC}\n"
rm $APPWRITE_TEMP_NAME
Expand All @@ -163,7 +184,7 @@ cleanup() {
}

installCompleted() {
echo "[4/4] Wrapping up installation ... "
echo "[5/5] Wrapping up installation ... "
cleanup
echo "🚀 To get started with Appwrite CLI, please visit https://appwrite.io/docs/command-line"
echo "As first step, you can login to your Appwrite account using 'appwrite login'"
Expand All @@ -174,4 +195,5 @@ greeting
getSystemInfo
downloadBinary
install
installCompletions
installCompleted
82 changes: 68 additions & 14 deletions lib/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getLatestVersionForInstallation,
compareVersions,
getErrorMessage,
getInstalledHomebrewFormula,
} from "../utils.js";
import {
EXECUTABLE_NAME,
Expand Down Expand Up @@ -136,6 +137,31 @@ const execCommand = (
});
};

const getHomebrewFormulaForUpdate = (): string => {
return getInstalledHomebrewFormula() ?? HOMEBREW_FORMULA;
};

const getHomebrewFormulaForManualInstructions = (): string => {
if (process.platform === "win32") {
return HOMEBREW_FORMULA;
}

return getHomebrewFormulaForUpdate();
};

const showHomebrewTapRecommendation = (formulaName: string): void => {
if (formulaName === HOMEBREW_FORMULA) {
return;
}

warn(
`Detected ${chalk.bold(formulaName)} from Homebrew. For faster native binaries, we recommend using the official Appwrite tap.`,
);
hint(
`To use the official Appwrite tap, run: brew install ${HOMEBREW_FORMULA}`,
);
};

/**
* Update via npm
*/
Expand Down Expand Up @@ -163,9 +189,16 @@ const updateViaNpm = async (): Promise<void> => {
/**
* Update via Homebrew
*/
const updateViaHomebrew = async (): Promise<void> => {
const updateViaHomebrew = async (
formulaName: string = getHomebrewFormulaForUpdate(),
options: { showRecommendation?: boolean } = {},
): Promise<void> => {
try {
await execCommand("brew", ["upgrade", HOMEBREW_FORMULA]);
if (options.showRecommendation ?? true) {
showHomebrewTapRecommendation(formulaName);
}

await execCommand("brew", ["upgrade", formulaName]);
console.log("");
success("Updated to latest version via Homebrew!");
hint(`Run '${EXECUTABLE_NAME} --version' to verify the new version.`);
Expand All @@ -184,7 +217,7 @@ const updateViaHomebrew = async (): Promise<void> => {
} else {
console.log("");
error(`Failed to update via Homebrew: ${message}`);
hint(`Try running: brew upgrade ${HOMEBREW_FORMULA}`);
hint(`Try running: brew upgrade ${formulaName}`);
}
}
};
Expand All @@ -196,7 +229,7 @@ const updateViaStandaloneBinary = async (
latestVersion: string,
): Promise<void> => {
if (process.platform === "win32") {
showManualInstructions(latestVersion);
showManualInstructions(latestVersion, HOMEBREW_FORMULA);
return;
}

Expand Down Expand Up @@ -252,7 +285,10 @@ const updateViaStandaloneBinary = async (
/**
* Show manual update instructions
*/
const showManualInstructions = (latestVersion: string): void => {
const showManualInstructions = (
latestVersion: string,
homebrewFormula: string = getHomebrewFormulaForManualInstructions(),
): void => {
log("Manual update options:");
console.log("");

Expand All @@ -261,7 +297,13 @@ const showManualInstructions = (latestVersion: string): void => {
console.log("");

log(`${chalk.bold("Option 2: Homebrew")}`);
console.log(` brew upgrade ${HOMEBREW_FORMULA}`);
console.log(` brew upgrade ${homebrewFormula}`);
if (homebrewFormula !== HOMEBREW_FORMULA) {
console.log("");
hint(
`For faster native binaries from the official Appwrite tap, run: brew install ${HOMEBREW_FORMULA}`,
);
}
console.log("");

if (process.platform !== "win32") {
Expand Down Expand Up @@ -347,8 +389,14 @@ interface UpdateOptions {
const updateCli = async ({ manual }: UpdateOptions = {}): Promise<void> => {
try {
const installationMethod = detectInstallationMethod();
const latestVersion =
await getLatestVersionForInstallation(installationMethod);
const homebrewFormula =
installationMethod === "homebrew" ? getHomebrewFormulaForUpdate() : null;
const latestVersion = await getLatestVersionForInstallation(
installationMethod,
{
homebrewFormula: homebrewFormula ?? undefined,
},
);

const comparison = compareVersions(version, latestVersion);

Expand All @@ -365,22 +413,28 @@ const updateCli = async ({ manual }: UpdateOptions = {}): Promise<void> => {
return;
}

if (manual) {
showManualInstructions(latestVersion, homebrewFormula ?? undefined);
return;
}

if (homebrewFormula) {
showHomebrewTapRecommendation(homebrewFormula);
}

log(
`Updating from ${chalk.blue(version)} to ${chalk.green(latestVersion)}...`,
);
console.log("");

if (manual) {
showManualInstructions(latestVersion);
return;
}

switch (installationMethod) {
case "npm":
await updateViaNpm();
break;
case "homebrew":
await updateViaHomebrew();
await updateViaHomebrew(homebrewFormula ?? undefined, {
showRecommendation: false,
});
break;
case "standalone":
await updateViaStandaloneBinary(latestVersion);
Expand Down
Loading
Loading