Skip to content

Commit f4a4d62

Browse files
authored
Merge pull request #10 from udx/development
Improve install flow and CLI lifecycle
2 parents 09a29b7 + 37a29d0 commit f4a4d62

File tree

6 files changed

+244
-84
lines changed

6 files changed

+244
-84
lines changed

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ It scans a repository for the workflow contracts that reduce drift across engine
88

99
The goal is to make repos easier to work on the same way every time. As a repo gets closer to a 12-factor operating model, humans and agents need less tribal knowledge to build, test, run, deploy, and improve it.
1010

11+
## Install
12+
13+
```bash
14+
curl -fsSL https://raw.githubusercontent.com/udx/dev.kit/main/bin/scripts/install.sh | bash
15+
dev.kit
16+
```
17+
18+
This installs `dev.kit` into `~/.udx/dev.kit` and adds `dev.kit` to `~/.local/bin/dev.kit`. If `~/.local/bin` is not already on `PATH`, the installer prints the exact command to export it manually.
19+
1120
## Commands
1221

1322
`dev.kit`
@@ -21,6 +30,14 @@ The goal is to make repos easier to work on the same way every time. As a repo g
2130
- Exposes the repo model for agents and automation.
2231
- Returns detected archetypes, factor statuses, entrypoints, and guidance so agents can work from grounded repo reality instead of guessing.
2332

33+
## Examples
34+
35+
```bash
36+
dev.kit
37+
dev.kit --json
38+
dev.kit bridge --json
39+
```
40+
2441
![compliance audit](assets/compliance-audit.svg)
2542

2643
![dev.kit bridge](assets/dev-kit-bridge.svg)
@@ -37,28 +54,14 @@ The value is operational clarity:
3754
- let teammates and agents operate with less ambiguity
3855
- standardize how work moves from local changes to CI and deployment
3956

40-
## Install
41-
42-
```bash
43-
bash bin/scripts/install.sh
44-
source "$HOME/.udx/dev.kit/bin/env/dev-kit.sh"
45-
dev.kit
46-
```
47-
48-
## Examples
49-
50-
```bash
51-
dev.kit
52-
dev.kit --json
53-
dev.kit bridge --json
54-
```
55-
5657
## Uninstall
5758

5859
```bash
59-
"$HOME/.udx/dev.kit/bin/scripts/uninstall.sh"
60+
dev.kit uninstall
6061
```
6162

63+
Removes the local install from `~/.udx/dev.kit` and the `~/.local/bin/dev.kit` symlink.
64+
6265
Further docs:
6366

6467
- [Workflow](/Users/jonyfq/git/udx/dev.kit/docs/workflow.md)

bin/dev-kit

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,57 +60,56 @@ EOF
6060

6161
command_usage() {
6262
local command_name="$1"
63-
cat <<EOF
64-
Usage: dev.kit ${command_name} [--json]
65-
66-
Options:
67-
--json Output machine-readable JSON
68-
EOF
63+
echo "Usage: dev.kit ${command_name} [options]"
64+
echo
65+
echo "Options:"
66+
case "$command_name" in
67+
audit|bridge|status)
68+
echo " --json Output machine-readable JSON"
69+
;;
70+
uninstall)
71+
echo " --yes Remove dev.kit without a confirmation prompt"
72+
;;
73+
esac
6974
}
7075

7176
command="${1:-audit}"
7277
format="text"
78+
command_args=()
79+
80+
if [ "$#" -gt 0 ]; then
81+
shift
82+
fi
7383

74-
if [ "${2:-}" = "--json" ] || [ "${1:-}" = "--json" ]; then
84+
while [ "$#" -gt 0 ]; do
85+
case "$1" in
86+
--json)
87+
format="json"
88+
;;
89+
*)
90+
command_args+=("$1")
91+
;;
92+
esac
93+
shift
94+
done
95+
96+
if [ "$command" = "--json" ]; then
97+
command="audit"
7598
format="json"
7699
fi
77100

78101
case "$command" in
79-
status)
80-
if [ "${2:-}" = "-h" ] || [ "${2:-}" = "--help" ]; then
81-
command_usage "status"
82-
exit 0
83-
fi
84-
dev_kit_cmd_status "$format"
85-
;;
86-
bridge)
87-
if [ "${2:-}" = "-h" ] || [ "${2:-}" = "--help" ]; then
88-
command_usage "bridge"
89-
exit 0
90-
fi
91-
dev_kit_cmd_bridge "$format"
92-
;;
93-
audit)
94-
if [ "${2:-}" = "-h" ] || [ "${2:-}" = "--help" ]; then
95-
command_usage "audit"
96-
exit 0
97-
fi
98-
dev_kit_cmd_audit "$format"
99-
;;
100-
--json)
101-
dev_kit_cmd_audit "json"
102-
;;
103102
help|-h|--help)
104103
usage
105104
;;
106105
*)
107106
fn="dev_kit_cmd_${command//-/_}"
108107
if command -v "$fn" >/dev/null 2>&1; then
109-
if [ "${2:-}" = "-h" ] || [ "${2:-}" = "--help" ]; then
108+
if [ "${command_args[0]:-}" = "-h" ] || [ "${command_args[0]:-}" = "--help" ]; then
110109
command_usage "$command"
111110
exit 0
112111
fi
113-
"$fn" "$format"
112+
"$fn" "$format" "${command_args[@]}"
114113
exit 0
115114
fi
116115
echo "Unknown command: $command" >&2

bin/scripts/install.sh

Lines changed: 122 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,133 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
5-
# shellcheck disable=SC1091
6-
. "$REPO_DIR/lib/modules/bootstrap.sh"
7-
dev_kit_bootstrap
4+
DEV_KIT_BIN_DIR="${DEV_KIT_BIN_DIR:-$HOME/.local/bin}"
5+
DEV_KIT_HOME="${DEV_KIT_HOME:-$HOME/.udx/dev.kit}"
6+
DEV_KIT_INSTALL_REPO="${DEV_KIT_INSTALL_REPO:-udx/dev.kit}"
7+
DEV_KIT_INSTALL_REF="${DEV_KIT_INSTALL_REF:-main}"
8+
DEV_KIT_INSTALL_ARCHIVE_URL="${DEV_KIT_INSTALL_ARCHIVE_URL:-https://codeload.github.com/${DEV_KIT_INSTALL_REPO}/tar.gz/refs/heads/${DEV_KIT_INSTALL_REF}}"
89

9-
TARGET="${DEV_KIT_BIN_DIR}/dev.kit"
10+
dev_kit_install_usage() {
11+
cat <<'EOF'
12+
Usage: bash install.sh
1013
11-
if [ "$#" -gt 0 ]; then
12-
echo "This installer does not modify shell profiles." >&2
13-
echo "Usage: bash bin/scripts/install.sh" >&2
14+
This installer does not modify shell profiles.
15+
EOF
16+
}
17+
18+
dev_kit_install_repo_dir() {
19+
local script_dir=""
20+
local repo_dir=""
21+
22+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23+
repo_dir="$(cd "${script_dir}/../.." 2>/dev/null && pwd || true)"
24+
25+
if [ -n "$repo_dir" ] && [ -f "$repo_dir/bin/dev-kit" ] && [ -d "$repo_dir/lib" ] && [ -d "$repo_dir/src" ]; then
26+
printf '%s\n' "$repo_dir"
27+
return 0
28+
fi
29+
30+
return 1
31+
}
32+
33+
dev_kit_install_download() {
34+
local url="$1"
35+
local archive_file="$2"
36+
37+
if command -v curl >/dev/null 2>&1; then
38+
curl -fsSL "$url" -o "$archive_file"
39+
return 0
40+
fi
41+
42+
if command -v wget >/dev/null 2>&1; then
43+
wget -qO "$archive_file" "$url"
44+
return 0
45+
fi
46+
47+
echo "curl or wget is required to install dev.kit" >&2
1448
exit 1
15-
fi
49+
}
50+
51+
dev_kit_install_extract_root() {
52+
local archive_file="$1"
53+
local extract_dir="$2"
54+
55+
tar -xzf "$archive_file" -C "$extract_dir"
56+
find "$extract_dir" -mindepth 1 -maxdepth 1 -type d | head -n 1
57+
}
58+
59+
dev_kit_install_source_dir() {
60+
local repo_dir=""
61+
local tmp_dir=""
62+
local archive_file=""
63+
local source_dir=""
64+
65+
if repo_dir="$(dev_kit_install_repo_dir)"; then
66+
printf '%s\n' "$repo_dir"
67+
return 0
68+
fi
69+
70+
tmp_dir="$(mktemp -d "${TMPDIR:-/tmp}/dev-kit-install.XXXXXX")"
71+
archive_file="${tmp_dir}/dev-kit.tar.gz"
72+
73+
dev_kit_install_download "$DEV_KIT_INSTALL_ARCHIVE_URL" "$archive_file"
74+
source_dir="$(dev_kit_install_extract_root "$archive_file" "$tmp_dir")"
75+
76+
if [ ! -f "$source_dir/bin/dev-kit" ] || [ ! -d "$source_dir/lib" ] || [ ! -d "$source_dir/src" ]; then
77+
echo "Downloaded archive does not contain a valid dev.kit source tree" >&2
78+
exit 1
79+
fi
80+
81+
printf '%s\n' "$source_dir"
82+
}
83+
84+
dev_kit_install_copy_tree() {
85+
local src="$1"
86+
local dst="$2"
87+
mkdir -p "$dst"
88+
cp -R "$src/." "$dst/"
89+
}
90+
91+
dev_kit_install_path_contains_bin_dir() {
92+
case ":$PATH:" in
93+
*":${DEV_KIT_BIN_DIR}:"*) return 0 ;;
94+
*) return 1 ;;
95+
esac
96+
}
97+
98+
main() {
99+
local source_dir=""
100+
local target=""
101+
102+
if [ "$#" -gt 0 ]; then
103+
dev_kit_install_usage >&2
104+
exit 1
105+
fi
106+
107+
source_dir="$(dev_kit_install_source_dir)"
108+
target="${DEV_KIT_BIN_DIR}/dev.kit"
16109

17-
mkdir -p "$DEV_KIT_HOME" "$DEV_KIT_BIN_DIR"
18-
rm -rf "$DEV_KIT_HOME/bin" "$DEV_KIT_HOME/lib" "$DEV_KIT_HOME/src" "$DEV_KIT_HOME/config" "$DEV_KIT_HOME/source" "$DEV_KIT_HOME/state"
110+
mkdir -p "$DEV_KIT_HOME" "$DEV_KIT_BIN_DIR"
111+
rm -rf "$DEV_KIT_HOME/bin" "$DEV_KIT_HOME/lib" "$DEV_KIT_HOME/src" "$DEV_KIT_HOME/config" "$DEV_KIT_HOME/source" "$DEV_KIT_HOME/state"
19112

20-
dev_kit_copy_tree "$REPO_DIR/bin" "$DEV_KIT_HOME/bin"
21-
dev_kit_copy_tree "$REPO_DIR/lib" "$DEV_KIT_HOME/lib"
22-
dev_kit_copy_tree "$REPO_DIR/src" "$DEV_KIT_HOME/src"
113+
dev_kit_install_copy_tree "$source_dir/bin" "$DEV_KIT_HOME/bin"
114+
dev_kit_install_copy_tree "$source_dir/lib" "$DEV_KIT_HOME/lib"
115+
dev_kit_install_copy_tree "$source_dir/src" "$DEV_KIT_HOME/src"
23116

24-
find "$DEV_KIT_HOME/bin" -type f -exec chmod +x {} \;
117+
find "$DEV_KIT_HOME/bin" -type f -exec chmod +x {} \;
118+
ln -sfn "$DEV_KIT_HOME/bin/dev-kit" "$target"
25119

26-
ln -sfn "$DEV_KIT_HOME/bin/dev-kit" "$TARGET"
120+
echo "Installed dev.kit"
121+
echo "binary: $target"
122+
echo "home: $DEV_KIT_HOME"
123+
if dev_kit_install_path_contains_bin_dir; then
124+
echo "shell: PATH already includes $DEV_KIT_BIN_DIR"
125+
echo "next: run dev.kit"
126+
else
127+
echo "shell: unchanged"
128+
echo "next: export PATH=\"$DEV_KIT_BIN_DIR:\$PATH\""
129+
echo "then: dev.kit"
130+
fi
131+
}
27132

28-
echo "Installed dev.kit"
29-
echo "binary: $TARGET"
30-
echo "home: $DEV_KIT_HOME"
31-
if dev_kit_path_contains_bin_dir; then
32-
echo "shell: PATH already includes $DEV_KIT_BIN_DIR"
33-
else
34-
echo "shell: unchanged"
35-
echo "next: export PATH=\"$DEV_KIT_BIN_DIR:\$PATH\""
36-
echo "then: source \"$DEV_KIT_HOME/bin/env/dev-kit.sh\""
37-
fi
133+
main "$@"

bin/scripts/uninstall.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
5-
# shellcheck disable=SC1091
6-
. "$REPO_DIR/lib/modules/bootstrap.sh"
7-
dev_kit_bootstrap
8-
4+
DEV_KIT_BIN_DIR="${DEV_KIT_BIN_DIR:-$HOME/.local/bin}"
5+
DEV_KIT_HOME="${DEV_KIT_HOME:-$HOME/.udx/dev.kit}"
96
TARGET="${DEV_KIT_BIN_DIR}/dev.kit"
107

8+
confirm_uninstall() {
9+
local reply=""
10+
printf 'Remove dev.kit from %s and %s? [y/N] ' "$TARGET" "$DEV_KIT_HOME" >&2
11+
read -r reply || true
12+
case "$reply" in
13+
y|Y|yes|YES) return 0 ;;
14+
*) echo "Cancelled." >&2; return 1 ;;
15+
esac
16+
}
17+
18+
if [ "${1:-}" = "--yes" ]; then
19+
:
20+
elif [ "$#" -gt 0 ]; then
21+
echo "Usage: uninstall.sh [--yes]" >&2
22+
exit 1
23+
else
24+
confirm_uninstall || exit 1
25+
fi
26+
1127
if [ -L "$TARGET" ] || [ -f "$TARGET" ]; then
1228
rm -f "$TARGET"
1329
echo "Removed binary: $TARGET"

lib/commands/uninstall.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
# @description: Remove the local dev.kit installation
4+
5+
dev_kit_cmd_uninstall() {
6+
local format="${1:-text}"
7+
shift || true
8+
9+
if [ "$format" = "json" ]; then
10+
echo "JSON output is not supported for uninstall" >&2
11+
return 1
12+
fi
13+
14+
"$REPO_DIR/bin/scripts/uninstall.sh" "$@"
15+
}

0 commit comments

Comments
 (0)