devswitch-cli 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +182 -0
  2. package/bin/devswitch.cjs +2440 -0
  3. package/package.json +49 -0
package/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # devswitch — CLI
2
+
3
+ The `devswitch` command-line tool manages multiple Git profiles and SSH keys
4
+ from your terminal. It is part of [DevSwitch](../README.md) and **shares its
5
+ database with the DevSwitch desktop app** — profiles you create in one show up
6
+ in the other automatically, with no conflicts.
7
+
8
+ The CLI is fully standalone: it runs on any machine with **Node.js ≥ 18** and
9
+ does not require the desktop app to be installed.
10
+
11
+ ---
12
+
13
+ ## Supported platforms
14
+
15
+ The CLI is a Node.js program, so it runs on **Windows, macOS, and Linux** — any
16
+ system with **Node.js ≥ 18**. It is not Linux-only.
17
+
18
+ ## Installation
19
+
20
+ You can install the CLI **with the app** or **separately** — in any order. Both
21
+ share the same data store, so they always stay in sync.
22
+
23
+ > **You never edit PATH manually.** All the recommended methods below put the
24
+ > `devswitch` command on your PATH for you:
25
+ >
26
+ > - **npm** (`install -g` / `link`) creates the correct entry per OS inside npm's
27
+ > global bin dir, which is already on PATH — a symlink on macOS/Linux and a
28
+ > `.cmd`/`.ps1` shim on Windows.
29
+ > - The **desktop app** installers place the command for you on each OS.
30
+
31
+ ### Option A — npm (recommended, all OSes)
32
+
33
+ ```bash
34
+ npm install -g devswitch-cli
35
+ devswitch help
36
+ ```
37
+
38
+ ### Option B — Bundled with the desktop app
39
+
40
+ When you install DevSwitch, the app makes `devswitch` available system-wide:
41
+
42
+ - **Linux (.deb):** a post-install hook places the command in `/usr/local/bin`.
43
+ - **macOS / Windows:** the installer registers the command on PATH.
44
+
45
+ ```bash
46
+ devswitch help
47
+ ```
48
+
49
+ If you had already installed the CLI via npm, the app won't overwrite it.
50
+
51
+ ### Option C — Standalone, one-line install (no npm)
52
+
53
+ For machines without npm. Requires Node.js ≥ 18.
54
+
55
+ ```bash
56
+ curl -sSL https://<your-app-host>/init/cli.sh | bash
57
+ ```
58
+
59
+ This downloads the bundled CLI and places a `devswitch` launcher into the first
60
+ writable directory on your PATH; it prints what to add to your shell profile if
61
+ none is writable.
62
+
63
+ ### Option D — From the repository (developers)
64
+
65
+ ```bash
66
+ # from the repo root
67
+ npm run cli:build # bundle the CLI → cli/bin/devswitch.cjs
68
+ npm run cli:link # builds + `npm link` so `devswitch` runs your local build
69
+ ```
70
+
71
+ `npm link` puts `devswitch` on your PATH automatically (same mechanism as a
72
+ global install), so there's no manual PATH setup on any OS.
73
+
74
+ ---
75
+
76
+ ## Commands
77
+
78
+ | Command | Aliases | Description |
79
+ | ----------------------------- | --------------- | ----------------------------------------------------- |
80
+ | `devswitch help [command]` | | Show help, optionally for one command |
81
+ | `devswitch version` | `-v` | Print the CLI version |
82
+ | `devswitch list` | `ls` | List all profiles |
83
+ | `devswitch use <profile>` | `switch` | Switch to a profile (SSH config + agent + global git) |
84
+ | `devswitch current` | `whoami` | Show the active profile |
85
+ | `devswitch add` | `create`, `new` | Create a new profile (interactive or flags) |
86
+ | `devswitch remove <profile>` | `rm`, `delete` | Delete a profile |
87
+ | `devswitch show <profile>` | `view`, `info` | Show full profile details |
88
+ | `devswitch sync` | | Import unmanaged SSH keys as profiles |
89
+ | `devswitch test <profile>` | | Test the SSH connection for a profile |
90
+ | `devswitch pubkey <profile>` | | Print a profile's public key (pipe-friendly) |
91
+ | `devswitch clone <url> [dir]` | | Clone a repo using a profile's identity |
92
+ | `devswitch logs` | `log` | Show recent activity (app + CLI) |
93
+ | `devswitch path` | | Show the shared data directory |
94
+ | `devswitch doctor` | | Diagnose environment & data store |
95
+
96
+ The `<profile>` argument accepts a profile **name**, **username**, **email**,
97
+ or **id** — partial, case-insensitive matches are allowed.
98
+
99
+ Most commands accept `--json` for scriptable output.
100
+
101
+ ---
102
+
103
+ ## Examples
104
+
105
+ ```bash
106
+ # List everything
107
+ devswitch list
108
+
109
+ # Switch to your work identity (updates ~/.ssh/config, ssh-agent, global git)
110
+ devswitch use work
111
+
112
+ # Switch without changing your global git user.name/email
113
+ devswitch use work --no-global-git
114
+
115
+ # Create a profile that generates a fresh ed25519 key
116
+ devswitch add \
117
+ --name "Work" --email me@work.com --username me-work \
118
+ --provider github --generate --algorithm ed25519 --key-name id_work
119
+
120
+ # Create a profile from an existing key
121
+ devswitch add --name "OSS" --email me@oss.dev --username me --existing ~/.ssh/id_oss
122
+
123
+ # Import any SSH keys not yet managed by DevSwitch
124
+ devswitch sync
125
+
126
+ # Verify a profile can authenticate
127
+ devswitch test work
128
+
129
+ # Copy a public key to the clipboard (Linux/Wayland example)
130
+ devswitch pubkey work | wl-copy
131
+
132
+ # Clone a repo using a specific profile's identity
133
+ devswitch clone git@github.com:acme/app.git ~/code --profile work
134
+ ```
135
+
136
+ ---
137
+
138
+ ## How the shared database works
139
+
140
+ Both the CLI and the desktop app read and write the same files:
141
+
142
+ | Platform | Location |
143
+ | -------- | ------------------------------------------------------------ |
144
+ | Linux | `$XDG_CONFIG_HOME/devswitch` (default `~/.config/devswitch`) |
145
+ | macOS | `~/Library/Application Support/devswitch` |
146
+ | Windows | `%APPDATA%\devswitch` |
147
+
148
+ - `profiles.json` — your profiles
149
+ - `logs.json` — activity log (each entry tagged `app` or `cli`)
150
+
151
+ Writes are atomic (write-temp-then-rename), and every read is fresh from disk,
152
+ so running the app and CLI at the same time is safe.
153
+
154
+ Override the location with the `DEVSWITCH_DATA_DIR` environment variable (handy
155
+ for testing or portable setups):
156
+
157
+ ```bash
158
+ DEVSWITCH_DATA_DIR=/tmp/ds-test devswitch list
159
+ ```
160
+
161
+ ### Migration from older versions
162
+
163
+ On first run, the CLI/app imports any existing profiles from the previous
164
+ electron-store locations (`~/.config/dev-switch`, `~/.config/Electron`, etc.)
165
+ into the shared directory. This runs once and never overwrites existing data.
166
+
167
+ ---
168
+
169
+ ## Environment variables
170
+
171
+ | Variable | Purpose |
172
+ | -------------------- | ---------------------------------- |
173
+ | `DEVSWITCH_DATA_DIR` | Override the shared data directory |
174
+ | `NO_COLOR` | Disable colored output |
175
+ | `DEVSWITCH_DEBUG` | Print full stack traces on error |
176
+
177
+ ---
178
+
179
+ ## Exit codes
180
+
181
+ `0` on success, `1` on error (profile not found, failed operation, invalid
182
+ arguments). Combine with `--json` for scripting.