mydev/README.md
Victor Abrell 47bb2d3a69 Use Gitea module path, add MIT license
Set module to git.abrell.se/victor/mydev so it installs from the
private Gitea host, and add an MIT LICENSE.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-12 14:41:20 +02:00

145 lines
5.8 KiB
Markdown

# MyDev
Local dev-environment monitor. AWS auth state, docker containers, git repo status.
Two modes: one-shot commands, or a live refreshing TUI dashboard.
## Build
```sh
go build -o mydev .
# optional: put it on PATH
mv mydev ~/go/bin/ # or /usr/local/bin
```
## Configure (required for `status` / `dash`)
Repo locations live in a config file — no default, no flag. First run:
```sh
mydev config init # writes a starter config
mydev config path # prints its location
```
Config lives at `~/.config/mydev/config.yaml` (honors `$XDG_CONFIG_HOME`):
```yaml
repos_roots: # scanned one level deep for git repos
- /Users/you/code
- /Users/you/work # multiple roots allowed
dev_dir: /Users/you/code/dev # commands/awsmfa, docker-compose.yml, bin/*.sh
legacy_dir: /Users/you/code/legacy # rundev.sh for prod-data tools
```
If the file is missing, commands that need it exit with an error telling you to
run `config init`. New settings get added as keys here later.
## Use
```sh
# AWS MFA (via dev/commands/awsmfa — the real session, not `aws sts`)
mydev auth # status: account + expiry
mydev auth login # re-authenticate (MFA prompt)
# Dev docker-compose stack (dev/docker-compose.yml)
mydev dev start # auths first, then up -d --force-recreate
mydev dev stop | restart | remove
mydev dev status # are running containers current with the dev repo?
mydev dev status --fetch=false # skip the git fetch (no network)
# Prod data via legacy rundev.sh (mystore:devtool:*)
mydev data table <args>
mydev data snapshot <args>
mydev data userfiles <args>
# DB access requests (dev/bin/*.sh)
mydev db bast # request_bast_access.sh
mydev db grant <arg> # grant_request.sh
mydev db list [arg] # grant_list.sh
# Misc
mydev port 3306 # what's listening on a port (lsof)
mydev docker # container table
mydev status # one-shot overview (auth + docker + repos)
mydev dash [--interval 5] # live TUI dashboard
```
In the dashboard you can run actions without leaving it:
| key | action |
|-----|--------|
| `r` | refresh now |
| `a` | `auth login` (MFA prompt) |
| `s` / `x` / `R` | dev `start` / `stop` / `restart` |
| `:` | command palette — run **any** subcommand, with args |
| `q` / `ctrl+c` | quit |
Quick keys cover the common no-arg actions and show a `y`/`n` confirm first.
For anything that takes arguments, press `:` to open the command palette and
type a full command line, e.g. `data table mytenant`, `db grant 1234`,
`port 3306` — Enter runs it, Esc cancels.
The palette browses the live command tree as you type: it lists the root
commands first, the subcommands once you pick a group (`dev ` → start/stop/…),
and the usage hint for a leaf command (`port ` → `port <number>`). `Tab`
completes the first match. The list is generated from cobra itself, so it always
matches the real commands — no separate help text to keep in sync.
Commands whose output is already on the dashboard are hidden and refused: the
top-level `status` and the bare `auth` status. `auth login`, `docker`, and
`dev status` stay (actions, or more detail than the panels show).
Commands run in one of two modes, chosen automatically:
- **Interactive** (`auth login`, `dev start`/`restart`, all `data …` fetches) —
need stdin or produce long live logs/prompts. The dashboard suspends and hands
over the full terminal, then resumes.
- **Captured** (everything else: `status`, `db grant`, `db list`, `port`, …) —
the dashboard stays up showing `running <cmd>… [c]ancel`. While it runs, other
launches are blocked (so you can't stack commands); `c` cancels it (kills the
process and returns to the menu, no result shown). When it finishes normally,
the output shows in a scrollable result pane.
`↑/↓` scroll, `esc`/`enter` close. Long lines wrap to the terminal width (so
things like a generated password aren't cut off), and re-wrap when you resize.
Either way it re-invokes this same binary's subcommands, so behavior matches the
CLI exactly. The terminal is cleared when the dashboard starts, before each
interactive command, and on exit — so you never see stale output from a previous
command (or after quitting).
The AWS panel turns red
(`⚠ expiring`) when the session has under 30 min left. The DOCKER header shows a
container-freshness badge (`✓ all N current` / `⚠ N/M stale`) — computed locally
each refresh, no network. `dev status` adds a git-fetch check on top (is the dev
repo itself behind origin); the dashboard deliberately omits that to stay fast.
## How it works
Shells out to the real `aws`, `docker`, `git` CLIs — no SDKs, no creds handling
of its own. All probe logic lives in `internal/checks/` as plain functions; both
the one-shot commands and the TUI call the same functions, so behavior never drifts.
```
main.go entrypoint
cmd/ cobra subcommands (auth, dev, data, db, port, docker, status, dash, config)
internal/checks/ auth.go, docker.go, repos.go — read-only probes (capture output)
internal/config/ config.go — load/init the YAML config + path accessors
internal/run/ run.go — stream a command's stdio to the terminal (auth/compose/data)
```
Probes (`internal/checks`) capture output for display; actions that prompt or
stream (MFA, compose, data fetch) go through `internal/run` so they reach the
terminal directly. The `dev start`/`restart` commands auto re-auth first,
mirroring the old `myd` shell function.
## Extend
Add a probe: write a func in `internal/checks/`, then either a new file in `cmd/`
for a one-shot subcommand, or wire it into `dashModel` in `cmd/dash.go` (add a
field, a `fetchX` command, a message type, and a panel).
Ideas: ECS/EKS context, VPN state, kubectl context, disk space, brew outdated.
## License
MIT — see [LICENSE](LICENSE).