Skip to content

Commit 8b28f80

Browse files
committed
chore: Added script to unintall npm.
1 parent 7cf3655 commit 8b28f80

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,31 @@ If you already have the [prerequisites](#prerequisites) on your machine, install
3535
npm install -g @patternfly/patternfly-cli
3636
```
3737

38+
## Uninstall
39+
40+
### Uninstall script (macOS and Linux)
41+
42+
You can pipe the repository uninstall script into `bash`. It removes the globally installed `@patternfly/patternfly-cli` package with npm. It does **not** remove Node.js, nvm, Corepack, or GitHub CLI.
43+
44+
```sh
45+
curl -fsSL https://raw.githubusercontent.com/patternfly/patternfly-cli/main/scripts/uninstall.sh | bash
46+
```
47+
48+
Swap `main` for another branch or tag if you need a specific revision. To save the script and inspect it before running:
49+
50+
```sh
51+
curl -fsSL https://raw.githubusercontent.com/patternfly/patternfly-cli/main/scripts/uninstall.sh -o uninstall-patternfly-cli.sh
52+
bash uninstall-patternfly-cli.sh
53+
```
54+
55+
### npm
56+
57+
If you installed with npm globally, you can remove the package with:
58+
59+
```sh
60+
npm uninstall -g @patternfly/patternfly-cli
61+
```
62+
3863
## Prerequisites
3964

4065
If you use the [install script](#install-script-macos-and-linux) on macOS or Linux, it covers the items below (you may still need administrator access for system packages). Otherwise, install the following yourself before using the CLI:

scripts/uninstall.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
# Remove the globally installed @patternfly/patternfly-cli package from npm.
3+
# Does not remove Node.js, nvm, Corepack, or GitHub CLI.
4+
5+
# Set script to stop on most failures.
6+
set -euo pipefail
7+
8+
error() {
9+
printf '\n[%s] ERROR: %s\n\n' "$(date -u +'%Y-%m-%dT%H:%M:%SZ')" "$*" >&2
10+
exit 1
11+
}
12+
13+
info() {
14+
printf '[uninstall] %s\n' "$*"
15+
}
16+
17+
warn() {
18+
printf '[uninstall] WARNING: %s\n' "$*" >&2
19+
}
20+
21+
require_cmd() {
22+
command -v "$1" >/dev/null 2>&1
23+
}
24+
25+
ensure_nvm_loaded() {
26+
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
27+
if [ -s "$NVM_DIR/nvm.sh" ]; then
28+
# shellcheck source=/dev/null
29+
. "$NVM_DIR/nvm.sh"
30+
return 0
31+
fi
32+
return 1
33+
}
34+
35+
ensure_node_for_npm() {
36+
if require_cmd node && require_cmd npm; then
37+
return 0
38+
fi
39+
if ensure_nvm_loaded; then
40+
nvm use default >/dev/null 2>&1 || true
41+
fi
42+
if require_cmd node && require_cmd npm; then
43+
return 0
44+
fi
45+
error "Node.js and npm are required to uninstall the package. Install Node or load nvm (see install script), then try again."
46+
}
47+
48+
uninstall_patternfly_cli() {
49+
info "Removing @patternfly/patternfly-cli from global npm packages."
50+
npm uninstall -g @patternfly/patternfly-cli || error "npm failed to uninstall @patternfly/patternfly-cli. Check permissions and which Node/npm you are using ($(command -v npm 2>/dev/null || echo 'npm not found'))."
51+
}
52+
53+
main() {
54+
info "Uninstalling PatternFly CLI (global npm package only)."
55+
ensure_node_for_npm
56+
uninstall_patternfly_cli
57+
58+
if require_cmd patternfly-cli; then
59+
warn "patternfly-cli is still on PATH at $(command -v patternfly-cli). You may have another global install under a different Node version or runtime."
60+
fi
61+
62+
printf '\n'
63+
printf 'SUCCESS: @patternfly/patternfly-cli has been removed from this npm global prefix.\n'
64+
printf '\n'
65+
}
66+
67+
main "$@"

0 commit comments

Comments
 (0)