Skip to content

Commit acdef71

Browse files
authored
Merge pull request #35 from forkzero/feat/update-notice-visibility
Make update notice more visible with color and version diff
2 parents aeb569d + 0a9b04a commit acdef71

3 files changed

Lines changed: 48 additions & 12 deletions

File tree

install.sh

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
#!/bin/sh
22
# Lattice installer
33
# Usage: curl -fsSL https://forkzero.ai/lattice/install.sh | sh
4+
#
5+
# Environment variables:
6+
# INSTALL_DIR Override install location (default: ~/.local/bin)
7+
# VERSION Install a specific version (default: latest)
48

59
set -e
610

711
REPO="forkzero/lattice"
8-
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
12+
13+
# Default to ~/.local/bin (user-writable, no sudo needed)
14+
if [ -z "$INSTALL_DIR" ]; then
15+
if [ -w "/usr/local/bin" ]; then
16+
INSTALL_DIR="/usr/local/bin"
17+
else
18+
INSTALL_DIR="${HOME}/.local/bin"
19+
fi
20+
fi
921

1022
# Detect OS
1123
OS="$(uname -s)"
@@ -65,6 +77,9 @@ fi
6577
echo "Extracting..."
6678
tar -xzf "$ARCHIVE"
6779

80+
# Ensure install directory exists
81+
mkdir -p "$INSTALL_DIR"
82+
6883
# Install
6984
BINARY_DIR="lattice-${VERSION}-${TARGET}"
7085
if [ -w "$INSTALL_DIR" ]; then
@@ -74,6 +89,23 @@ else
7489
sudo mv "${BINARY_DIR}/lattice" "$INSTALL_DIR/"
7590
fi
7691

92+
# Check if install dir is in PATH
93+
case ":$PATH:" in
94+
*":${INSTALL_DIR}:"*) ;;
95+
*)
96+
echo ""
97+
echo "Add ${INSTALL_DIR} to your PATH:"
98+
SHELL_NAME="$(basename "$SHELL")"
99+
case "$SHELL_NAME" in
100+
zsh) echo " echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ~/.zshrc && source ~/.zshrc" ;;
101+
bash) echo " echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ~/.bashrc && source ~/.bashrc" ;;
102+
fish) echo " fish_add_path ${INSTALL_DIR}" ;;
103+
*) echo " export PATH=\"${INSTALL_DIR}:\$PATH\"" ;;
104+
esac
105+
echo ""
106+
;;
107+
esac
108+
77109
# Verify
78110
if command -v lattice > /dev/null 2>&1; then
79111
echo ""
@@ -82,8 +114,9 @@ if command -v lattice > /dev/null 2>&1; then
82114
echo "Get started:"
83115
echo " lattice init # Initialize a lattice"
84116
echo " lattice --help # Show all commands"
117+
echo " lattice help concepts # Learn the domain model"
85118
else
86119
echo ""
87120
echo "Installed to ${INSTALL_DIR}/lattice"
88-
echo "Add ${INSTALL_DIR} to your PATH if not already present."
121+
echo "Make sure ${INSTALL_DIR} is in your PATH."
89122
fi

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4445,7 +4445,9 @@ fn run_command(command: Commands) {
44454445
(
44464446
format!("Permission denied — cannot write to {}", exe),
44474447
if cfg!(unix) {
4448-
Some("Run with sudo: sudo lattice update")
4448+
Some(
4449+
"Reinstall to ~/.local/bin for sudo-free updates:\n INSTALL_DIR=~/.local/bin curl -fsSL https://forkzero.ai/lattice/install.sh | sh\nOr run: sudo lattice update",
4450+
)
44494451
} else {
44504452
None
44514453
},

src/update.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,16 @@ fn write_check_state(path: &std::path::Path, state: &UpdateCheckState) {
374374
.and_then(|json| std::fs::write(path, json).ok());
375375
}
376376

377-
fn print_update_notice(latest: &Version) {
377+
fn print_update_notice(current: &Version, latest: &Version) {
378+
eprintln!();
378379
eprintln!(
379-
"{}",
380-
format!(
381-
"A new version of lattice is available (v{}). Run 'lattice update' to install.",
382-
latest
383-
)
384-
.dimmed()
380+
" {} {} → {}",
381+
"Update available:".yellow().bold(),
382+
format!("v{}", current).dimmed(),
383+
format!("v{}", latest).green().bold()
385384
);
385+
eprintln!(" Run {} to install", "lattice update".cyan());
386+
eprintln!();
386387
}
387388

388389
/// Print a one-line update notice to stderr if a newer version is available.
@@ -420,7 +421,7 @@ pub fn maybe_notify_update(command_name: Option<&str>) {
420421
if let Ok(latest) = Version::parse(&state.latest_version)
421422
&& latest > current
422423
{
423-
print_update_notice(&latest);
424+
print_update_notice(&current, &latest);
424425
}
425426
return;
426427
}
@@ -449,7 +450,7 @@ pub fn maybe_notify_update(command_name: Option<&str>) {
449450
},
450451
);
451452
if latest > current {
452-
print_update_notice(&latest);
453+
print_update_notice(&current, &latest);
453454
}
454455
}
455456
Err(_) => {

0 commit comments

Comments
 (0)