Skip to content

Commit 8cc78ae

Browse files
authored
feat: add global CLI options and environment variable support (#5)
Add --no-color, --quiet, --mode/--live/--sandbox flags and env var support for --json (MEMBERSTACK_JSON) and --mode (MEMBERSTACK_MODE). Replaces the boolean --live flag with a --mode <mode> option while maintaining backwards compatibility via --live and --sandbox shorthands. Disables cli-table3 ANSI codes when color is off. Updates docs and adds comprehensive tests. Co-authored-by: Ben Sabic <bensabic@users.noreply.github.com>
1 parent 7e9d373 commit 8cc78ae

File tree

14 files changed

+379
-124
lines changed

14 files changed

+379
-124
lines changed

AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This file provides guidance to AI agents when working with code in this reposito
66

77
```bash
88
pnpm build # Build CLI with tsup (output: dist/)
9+
pnpm dev # Run CLI from source via tsx (e.g. pnpm dev -- members list)
910
pnpm test # Run all tests with vitest
1011
pnpm check # Lint and format check (Biome via ultracite)
1112
pnpm fix # Auto-fix lint and format issues
@@ -41,4 +42,5 @@ Write code that is **accessible, performant, type-safe, and maintainable**. Focu
4142
## Resources
4243

4344
[ARCHITECTURE.md](./ARCHITECTURE.md): Detailed Project Architecture
44-
[CONTRIBUTING.md](.github/CONTRIBUTING.md): Project Contribution Guidelines
45+
[CONTRIBUTING.md](.github/CONTRIBUTING.md): Project Contribution Guidelines
46+
[Memberstack CLI Documentation](https://memberstack-cli.flashbrew.digital/llms.txt): Memberstack CLI Documentation

ARCHITECTURE.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ memberstack-cli/
5050
│ └── core/ # Core library tests
5151
│ ├── auth.test.ts
5252
│ ├── graphql-client.test.ts
53+
│ ├── no-color.test.ts
5354
│ ├── oauth.test.ts
55+
│ ├── program-options.test.ts
56+
│ ├── quiet.test.ts
5457
│ └── utils.test.ts
5558
5659
├── dist/ # Compiled output (ESM)
@@ -64,14 +67,17 @@ memberstack-cli/
6467

6568
### Entry Point (`src/index.ts`)
6669

67-
Prints the ASCII banner to stderr, registers all command groups on the shared `program` instance, and calls `parseAsync()`.
70+
Propagates `--no-color` / `NO_COLOR` to all color libraries before imports, conditionally prints the ASCII banner (suppressed by `--quiet`), registers all command groups on the shared `program` instance, and calls `parseAsync()`.
6871

6972
### Program (`src/lib/program.ts`)
7073

71-
A shared Commander instance with two global options:
74+
A shared Commander instance with global options:
7275

73-
- `--json` — output raw JSON instead of formatted tables
74-
- `--live` — use live environment instead of sandbox (appended as `?mode=live` or `?mode=sandbox` to the GraphQL URL)
76+
- `-j, --json` — output raw JSON instead of formatted tables (env: `MEMBERSTACK_JSON`)
77+
- `-q, --quiet` — suppress banner and non-essential output
78+
- `--no-color` — disable color output (respects the `NO_COLOR` standard)
79+
- `--mode <mode>` — set environment mode: `sandbox` (default) or `live` (env: `MEMBERSTACK_MODE`)
80+
- `--live` / `--sandbox` — shorthands for `--mode live` and `--mode sandbox`
7581

7682
### Commands (`src/commands/`)
7783

@@ -118,7 +124,7 @@ Tokens are stored in `~/.memberstack/auth.json` with restrictive file permission
118124
- `printTable()` — renders data as a `cli-table3` table to stderr (or JSON to stdout with `--json`)
119125
- `printRecord()` — renders a single object as a vertical key-value table
120126
- `printJson()` — writes raw JSON to stdout
121-
- `printSuccess()` / `printError()` — colored status messages to stderr
127+
- `printSuccess()` / `printError()` — colored status messages to stderr (`printSuccess` is suppressed by `--quiet`)
122128
- `parseKeyValuePairs()` — parses `key=value` strings for `--data` options
123129
- `parseWhereClause()` — parses `field operator value` filter syntax for `--where`
124130
- `parseJsonString()` — parses raw JSON strings for `--query`
@@ -154,7 +160,7 @@ All user-facing output (tables, spinners, messages) goes to **stderr**. JSON out
154160
| `open` | Opens browser for OAuth login |
155161
| `papaparse` | CSV parsing and generation |
156162

157-
Dev: `tsup` (bundler), `typescript`, `vitest` (tests), `biome` via `ultracite` (lint/format).
163+
Dev: `tsup` (bundler), `tsx` (dev runner), `typescript`, `vitest` (tests), `biome` via `ultracite` (lint/format).
158164

159165
## Build & CI
160166

README.md

Lines changed: 24 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -42,106 +42,30 @@ memberstack skills add memberstack-cli
4242

4343
### Global Options
4444

45-
| Option | Description |
46-
|---|---|
47-
| `--json` | Output raw JSON instead of formatted tables |
48-
| `--live` | Use live environment instead of sandbox |
45+
| Option | Env Var | Description |
46+
|---|---|---|
47+
| `-j, --json` | `MEMBERSTACK_JSON` | Output raw JSON instead of formatted tables |
48+
| `-q, --quiet` | | Suppress banner and non-essential output |
49+
| `--no-color` | `NO_COLOR` | Disable color output (respects the [NO_COLOR standard](https://no-color.org)) |
50+
| `--mode <mode>` | `MEMBERSTACK_MODE` | Set environment mode (`sandbox` or `live`, default: `sandbox`) |
51+
| `--live` | | Shorthand for `--mode live` |
52+
| `--sandbox` | | Shorthand for `--mode sandbox` |
4953

5054
### Commands
5155

52-
#### `auth` — Authentication
53-
54-
| Subcommand | Description |
55-
|---|---|
56-
| `login` | Authenticate with Memberstack via OAuth |
57-
| `logout` | Remove stored authentication tokens |
58-
| `status` | Show current authentication status |
59-
60-
#### `whoami` — Identity
61-
62-
Show the current authenticated app and user.
63-
64-
#### `apps` — App Management
65-
66-
| Subcommand | Description |
67-
|---|---|
68-
| `current` | Show the current app |
69-
| `create` | Create a new app |
70-
| `update` | Update the current app |
71-
| `delete` | Delete an app |
72-
| `restore` | Restore a deleted app |
73-
74-
#### `members` — Member Management
75-
76-
| Subcommand | Description |
77-
|---|---|
78-
| `list` | List members (with pagination) |
79-
| `get <id_or_email>` | Get a member by ID or email |
80-
| `create` | Create a new member |
81-
| `update <id>` | Update a member |
82-
| `delete <id>` | Delete a member |
83-
| `add-plan <id>` | Add a free plan to a member |
84-
| `remove-plan <id>` | Remove a free plan from a member |
85-
| `count` | Show total member count |
86-
| `find` | Find members by field values or plan |
87-
| `stats` | Show member statistics |
88-
| `export` | Export all members to CSV or JSON |
89-
| `import` | Import members from a CSV or JSON file |
90-
| `bulk-update` | Bulk update members from a file |
91-
| `bulk-add-plan` | Add a plan to multiple members |
92-
93-
#### `plans` — Plan Management
94-
95-
| Subcommand | Description |
96-
|---|---|
97-
| `list` | List all plans |
98-
| `get <id>` | Get a plan by ID |
99-
| `create` | Create a new plan |
100-
| `update <id>` | Update a plan (name, status, redirects, permissions, etc.) |
101-
| `delete <id>` | Delete a plan |
102-
| `order` | Reorder plans by priority |
103-
104-
#### `tables` — Data Table Management
105-
106-
| Subcommand | Description |
56+
| Command | Functionality |
10757
|---|---|
108-
| `list` | List all data tables |
109-
| `get <table_key>` | Get a data table by key or ID |
110-
| `describe <table_key>` | Show table schema and access rules |
111-
| `create` | Create a new data table |
112-
| `update <id>` | Update a data table |
113-
| `delete <id>` | Delete a data table |
114-
115-
#### `records` — Record Management
116-
117-
| Subcommand | Description |
118-
|---|---|
119-
| `create <table_key>` | Create a new record |
120-
| `update <table_key> <record_id>` | Update a record |
121-
| `delete <table_key> <record_id>` | Delete a record |
122-
| `query <table_key>` | Query records with a JSON filter |
123-
| `count <table_key>` | Count records in a table |
124-
| `find <table_key>` | Find records with friendly filter syntax |
125-
| `export <table_key>` | Export all records to CSV or JSON |
126-
| `import <table_key>` | Import records from a CSV or JSON file |
127-
| `bulk-update` | Bulk update records from a file |
128-
| `bulk-delete <table_key>` | Bulk delete records matching a filter |
129-
130-
#### `custom-fields` — Custom Field Management
131-
132-
| Subcommand | Description |
133-
|---|---|
134-
| `list` | List all custom fields |
135-
| `create` | Create a custom field |
136-
| `update <id>` | Update a custom field |
137-
| `delete <id>` | Delete a custom field |
138-
139-
#### `skills` — Agent Skill Management
140-
141-
| Subcommand | Description |
142-
|---|---|
143-
| `add <skill>` | Add a Memberstack agent skill |
144-
| `remove <skill>` | Remove a Memberstack agent skill |
58+
| `auth` | Login, logout, and check authentication status |
59+
| `whoami` | Show current authenticated app and user |
60+
| `apps` | View, create, update, delete, and restore apps |
61+
| `members` | List, create, update, delete, import/export, bulk ops |
62+
| `plans` | List, create, update, delete, and reorder plans |
63+
| `tables` | List, create, update, delete, and describe schema |
64+
| `records` | CRUD, query, import/export, bulk ops |
65+
| `custom-fields` | List, create, update, and delete custom fields |
66+
| `skills` | Add/remove agent skills for Claude Code and Codex |
67+
68+
For full command details and usage, see the [Command Reference](https://memberstack-cli.flashbrew.digital/docs/commands).
14569

14670
## Examples
14771

@@ -162,6 +86,7 @@ memberstack members export --format csv --output members.csv
16286
memberstack records import my_table --file data.json
16387

16488
# Use live environment
89+
memberstack members list --mode live
16590
memberstack members list --live
16691
```
16792

@@ -171,6 +96,9 @@ memberstack members list --live
17196
# Install dependencies
17297
pnpm install
17398

99+
# Run locally (via tsx, no build needed)
100+
pnpm dev -- members list --json
101+
174102
# Build
175103
pnpm build
176104

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"packageManager": "pnpm@10.29.3",
5050
"scripts": {
5151
"build": "tsup",
52+
"dev": "tsx src/index.ts",
5253
"test": "vitest run",
5354
"type-check": "tsc --noEmit",
5455
"check": "ultracite check",
@@ -70,6 +71,7 @@
7071
"@types/papaparse": "^5.5.2",
7172
"lint-staged": "^16.2.7",
7273
"tsup": "^8.5.1",
74+
"tsx": "^4.21.0",
7375
"typescript": "^5.9.3",
7476
"ultracite": "7.2.3",
7577
"vitest": "^4.0.18"

pnpm-lock.yaml

Lines changed: 40 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)