leancpms-cli 0.1.4__tar.gz → 0.1.6__tar.gz

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.
@@ -0,0 +1,272 @@
1
+ Metadata-Version: 2.5
2
+ Name: leancpms-cli
3
+ Version: 0.1.6
4
+ Summary: The cpms command alone: a client of a LeanCPMS instance's JSON API
5
+ License-Expression: AGPL-3.0-or-later
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.14
8
+ Requires-Dist: httpx>=0.28.1
9
+ Requires-Dist: pydantic>=2.14.1
10
+ Requires-Dist: pyyaml>=6.0.3
11
+ Description-Content-Type: text/markdown
12
+
13
+ # `cpms`, the LeanCPMS command line
14
+
15
+ `cpms` manages your organization in LeanCPMS Cloud from your own computer:
16
+ live state, sessions, the monthly settlements, members and keys, and the
17
+ declared state (price list, sites) as YAML documents you export, edit and
18
+ apply. The same commands work for people and for AI agents.
19
+
20
+ It talks to LeanCPMS Cloud unless you tell it otherwise. Running your own
21
+ instance? Log in once with `cpms login --url https://…`
22
+ ([Running your own instance](../docs/self-hosting.md)).
23
+
24
+ This directory builds `leancpms-cli`, the command without the server. It
25
+ depends on httpx, pydantic and PyYAML only.
26
+
27
+ ## Install
28
+
29
+ With [uv](https://docs.astral.sh/uv/), from PyPI. uv also fetches
30
+ Python 3.14, which `cpms` needs, if your computer lacks it:
31
+
32
+ ```bash
33
+ curl -LsSf https://astral.sh/uv/install.sh | sh # if you do not have uv yet
34
+ uv tool install leancpms-cli
35
+ cpms --help
36
+ ```
37
+
38
+ - **Upgrade:** `uv tool upgrade leancpms-cli`. To pin a version:
39
+ `uv tool install leancpms-cli==0.1.6`.
40
+ - **pipx** works too, if Python 3.14 is already installed:
41
+ `pipx install leancpms-cli`.
42
+ - Do not install it where the LeanCPMS server is installed: the server
43
+ already contains `cpms`.
44
+
45
+ The examples assume a Unix shell (Linux or macOS).
46
+
47
+ ## Log in
48
+
49
+ Log in with the same e-mail address you use for the portal:
50
+
51
+ ```bash
52
+ cpms login
53
+ ```
54
+
55
+ It prints a code and opens the portal's page for it in your browser (or
56
+ prints the address only: `--no-browser`, or no display). Log in there if
57
+ you are not, check that the page shows the same code, choose your
58
+ organization and whether the key may act (`write`) or only look (`read`),
59
+ and approve. Your role as a member decides which you may choose: members
60
+ are `read` unless the operator, or a colleague with a `write` key, made
61
+ them `write`. `cpms login` waits for that and then saves a **personal
62
+ key**, yours and that organization's, in `~/.config/cpms/config.toml`,
63
+ readable only by you.
64
+
65
+ ```bash
66
+ cpms whoami # which key is in use, whose, for which organization
67
+ cpms logout # revokes the key on the server and forgets it
68
+ ```
69
+
70
+ The key stops working when you are removed as a member, and so does
71
+ every key you issued with it. Approve a code only if you just ran
72
+ `cpms login` yourself: whoever started it gets the key.
73
+ [Users and access](../docs/users-and-access.md) explains members, roles
74
+ and keys, with several computers, a lost computer, and common tasks.
75
+
76
+ ## Everyday commands
77
+
78
+ ```bash
79
+ cpms # live state: sites, fuse groups, outlets, current per phase
80
+ cpms sessions --since 2026-11-01 --status ended
81
+ cpms sessions --since 2026-11-01 --csv > november.csv
82
+ cpms session SIM-0001/42 # one session: <charge point>/<transaction>
83
+ cpms session SIM-0001/42 stop # acts at once, no confirmation
84
+ cpms report settlements --month 2026-10 # the month's settlements per site, with bookkeeping proposals
85
+ ```
86
+
87
+ **Who is a member, and with which role**
88
+
89
+ ```bash
90
+ cpms members list
91
+ cpms members add ben@example.com --org acme # read
92
+ cpms members add carla@example.com --org acme --role write
93
+ cpms members set-role ben@example.com --org acme --role write
94
+ cpms members remove ben@example.com --org acme
95
+ ```
96
+
97
+ `--org acme` is needed even though your key is already for `acme`.
98
+
99
+ **Keys**
100
+
101
+ ```bash
102
+ cpms keys list # every key of the organization, revoked ones too
103
+ cpms keys issue --name dashboard --scope read # prints the secret once
104
+ cpms keys revoke 7b2d90aa
105
+ ```
106
+
107
+ Every command takes `--json` for machine-readable output.
108
+ `cpms --help` and `cpms <command> --help` list the rest.
109
+
110
+ ## Managing your documents
111
+
112
+ Your organization's price list and each of its sites are YAML documents
113
+ on the server. You change one by exporting it, editing the file, and
114
+ applying it. No git repository is needed:
115
+
116
+ 1. **Export** the document into a file:
117
+
118
+ ```bash
119
+ cpms manifest export acme --site main-street > site.yaml
120
+ ```
121
+
122
+ `--pricelist` exports the price list instead, `--organization` the
123
+ organization document, and with none of them you get every document
124
+ in one file.
125
+
126
+ 2. **Edit** the file in any text editor.
127
+
128
+ 3. **Check it, see what would change, and apply it:**
129
+
130
+ ```bash
131
+ cpms manifest validate site.yaml # offline: the schema; needs no key
132
+ cpms manifest plan site.yaml # the server: the diff, references, live warnings
133
+ cpms manifest apply site.yaml -m "Fused up to 50 A"
134
+ ```
135
+
136
+ `apply` shows the plan again and asks before it applies. `-m`, the
137
+ reason, is required and stored with the version.
138
+
139
+ **The server keeps every version.** Each apply is stored with its message,
140
+ who applied it and when, so you can always see what changed and get an
141
+ older version back:
142
+
143
+ ```bash
144
+ cpms manifest history acme --site main-street # every version, with its message
145
+ cpms manifest export acme --site main-street --version 3 > v3.yaml
146
+ cpms manifest diff acme --site main-street v3 # from version 3 to the current one
147
+ ```
148
+
149
+ Some things to know:
150
+
151
+ - `plan` and `apply` need a `write` key; exporting and history need only
152
+ `read`.
153
+ - Someone else may apply the same document while you edit. Your `plan`
154
+ then shows that your file would undo their change: export again and
155
+ redo your edit. `apply` applies exactly the plan it showed you, and
156
+ refuses if the document changed on the server before you confirmed;
157
+ run it again and read the new plan.
158
+ - Removing anything (a charge point, an outlet, a tariff) needs `--prune`
159
+ on `plan` and `apply`.
160
+ - The organization document is changed by the operator. An organization's
161
+ key applies the price list and the site documents, so export them one at
162
+ a time when you mean to apply them.
163
+ - An outlet's `public_id` is the id in its QR code (`/c/<public_id>`).
164
+ Leave it out and the server makes one up on first apply and keeps it.
165
+ Once the codes are printed, write the ids into the site file
166
+ (`- {connector: 1, key: s1-1, public_id: h7k2m9pq}`): a declared id
167
+ applies, also on a new server, and `plan` warns before an outlet's id
168
+ changes.
169
+
170
+ ### Keeping the files in a repository
171
+
172
+ For a team, keeping the files in a git repository of your own is a good
173
+ habit: you review each other's changes before they are applied, and CI can
174
+ check every change. It is not required; the server's history is the record
175
+ either way. One file per document works well:
176
+
177
+ ```
178
+ organization.yaml
179
+ pricelist.yaml
180
+ sites/main-street.yaml
181
+ sites/harbour.yaml
182
+ ```
183
+
184
+ Edit a file, run `validate` and `plan`, commit, then run `apply` with the
185
+ commit's reason as `-m`. The server holds the truth and the files are a
186
+ way to say things: if someone else applied a change, `plan` shows that
187
+ applying your file would undo it, and `export` brings the file up to date.
188
+ `validate` needs no key, so CI can run it on every pull request; `plan`
189
+ needs one.
190
+
191
+ ## In your editor: the JSON Schema
192
+
193
+ The documents have a JSON Schema, so an editor can complete field names
194
+ and flag mistakes as you type. That works in editors that use
195
+ yaml-language-server: VS Code with Red Hat's YAML extension, Neovim,
196
+ Helix, Zed. Add this line at the top of each file:
197
+
198
+ ```yaml
199
+ # yaml-language-server: $schema=https://raw.githubusercontent.com/forsslund/leancpms/main/schema/manifest.cpms-v1.schema.json
200
+ ```
201
+
202
+ That URL works once the repository is public; replace `main` with a tag
203
+ to pin a version. Until then, use a local copy, written by the command
204
+ itself and kept next to your files:
205
+
206
+ ```bash
207
+ cpms manifest schema > cpms-v1.schema.json
208
+ ```
209
+
210
+ ```yaml
211
+ # yaml-language-server: $schema=cpms-v1.schema.json
212
+ ```
213
+
214
+ The path is relative to the YAML file (`../cpms-v1.schema.json` from
215
+ `sites/`). `export` does not write the line, so add it again after an
216
+ export.
217
+
218
+ The schema checks types, required and unknown fields, allowed values,
219
+ key spelling, and that amounts are quoted (`"4.70"`, not `4.70`). It does
220
+ not check anything that spans several fields: a budget above the fuse,
221
+ duplicate keys, ocpp ids or public ids, a plan naming a missing tariff, or
222
+ an unknown time zone. `validate` and `plan` check those. Only `plan`
223
+ knows whether another outlet on the server already has a public id.
224
+
225
+ ## Scripts, CI and agents
226
+
227
+ A pipeline, a dashboard or an agent of its own gets a key for an
228
+ integration, which records who issued it: `cpms keys issue --name ci
229
+ --scope read` with your personal `write` key. It is shown only once. A key
230
+ you issue lives only as long as your membership: when you leave, it is
231
+ revoked with your own. An integration that must outlive you gets its key
232
+ from the operator.
233
+
234
+ Give the script the key in the environment variable `CPMS_API_KEY`, never
235
+ on the command line, where it ends up in shell history and process lists.
236
+ That is all LeanCPMS Cloud needs; against another instance, set `CPMS_URL`
237
+ too. Without `--profile`, the environment wins over your own login. A
238
+ command that finds no key exits 2 and says what to set. `cpms logout`
239
+ with a key from `CPMS_API_KEY` revokes it but cannot remove it from the
240
+ environment; unset it.
241
+
242
+ - `--json` works on every command, before or after the subcommand.
243
+ - Exit codes: 0 ok, 1 the action failed (the server said no, the server
244
+ could not be reached, a plan has errors), 2 usage or configuration.
245
+ - `cpms manifest apply` never prompts without a TTY. It prints the plan
246
+ and exits 2 unless you pass `--yes`. Show the plan to a person first,
247
+ then apply with `--yes -m "why"`.
248
+ - `session … stop|close` acts at once, with no confirmation step.
249
+ - Pass the key in the environment or the config file, never on the
250
+ command line or in a transcript.
251
+
252
+ ## Releasing (maintainers)
253
+
254
+ Raise `version` in both `cli/pyproject.toml` and the root `pyproject.toml`
255
+ (a test keeps them equal), then tag and push:
256
+
257
+ ```bash
258
+ git tag cli-v0.1.6 && git push origin cli-v0.1.6
259
+ ```
260
+
261
+ `.github/workflows/release-cli.yml` builds the wheel and sdist, smoke-tests
262
+ the wheel, and attaches both to a GitHub release. It also publishes to PyPI
263
+ when the repository variable `PYPI_PUBLISH` is `true`. That needs, once:
264
+ a PyPI account with two-factor authentication; a *pending trusted
265
+ publisher* on PyPI for the project `leancpms-cli` (owner `forsslund`,
266
+ repository `leancpms`, workflow `release-cli.yml`, environment `pypi`);
267
+ and an environment `pypi` in the GitHub repository's settings. A pending
268
+ publisher does not reserve the name: if someone else registers
269
+ `leancpms-cli` first, it becomes invalid. The first release creates the
270
+ project and so reserves the name. Trusted publishing uses GitHub's OIDC
271
+ token, so no PyPI token is stored anywhere. A file published to PyPI cannot be replaced,
272
+ only yanked: a wrong release is fixed with a new version.
@@ -0,0 +1,260 @@
1
+ # `cpms`, the LeanCPMS command line
2
+
3
+ `cpms` manages your organization in LeanCPMS Cloud from your own computer:
4
+ live state, sessions, the monthly settlements, members and keys, and the
5
+ declared state (price list, sites) as YAML documents you export, edit and
6
+ apply. The same commands work for people and for AI agents.
7
+
8
+ It talks to LeanCPMS Cloud unless you tell it otherwise. Running your own
9
+ instance? Log in once with `cpms login --url https://…`
10
+ ([Running your own instance](../docs/self-hosting.md)).
11
+
12
+ This directory builds `leancpms-cli`, the command without the server. It
13
+ depends on httpx, pydantic and PyYAML only.
14
+
15
+ ## Install
16
+
17
+ With [uv](https://docs.astral.sh/uv/), from PyPI. uv also fetches
18
+ Python 3.14, which `cpms` needs, if your computer lacks it:
19
+
20
+ ```bash
21
+ curl -LsSf https://astral.sh/uv/install.sh | sh # if you do not have uv yet
22
+ uv tool install leancpms-cli
23
+ cpms --help
24
+ ```
25
+
26
+ - **Upgrade:** `uv tool upgrade leancpms-cli`. To pin a version:
27
+ `uv tool install leancpms-cli==0.1.6`.
28
+ - **pipx** works too, if Python 3.14 is already installed:
29
+ `pipx install leancpms-cli`.
30
+ - Do not install it where the LeanCPMS server is installed: the server
31
+ already contains `cpms`.
32
+
33
+ The examples assume a Unix shell (Linux or macOS).
34
+
35
+ ## Log in
36
+
37
+ Log in with the same e-mail address you use for the portal:
38
+
39
+ ```bash
40
+ cpms login
41
+ ```
42
+
43
+ It prints a code and opens the portal's page for it in your browser (or
44
+ prints the address only: `--no-browser`, or no display). Log in there if
45
+ you are not, check that the page shows the same code, choose your
46
+ organization and whether the key may act (`write`) or only look (`read`),
47
+ and approve. Your role as a member decides which you may choose: members
48
+ are `read` unless the operator, or a colleague with a `write` key, made
49
+ them `write`. `cpms login` waits for that and then saves a **personal
50
+ key**, yours and that organization's, in `~/.config/cpms/config.toml`,
51
+ readable only by you.
52
+
53
+ ```bash
54
+ cpms whoami # which key is in use, whose, for which organization
55
+ cpms logout # revokes the key on the server and forgets it
56
+ ```
57
+
58
+ The key stops working when you are removed as a member, and so does
59
+ every key you issued with it. Approve a code only if you just ran
60
+ `cpms login` yourself: whoever started it gets the key.
61
+ [Users and access](../docs/users-and-access.md) explains members, roles
62
+ and keys, with several computers, a lost computer, and common tasks.
63
+
64
+ ## Everyday commands
65
+
66
+ ```bash
67
+ cpms # live state: sites, fuse groups, outlets, current per phase
68
+ cpms sessions --since 2026-11-01 --status ended
69
+ cpms sessions --since 2026-11-01 --csv > november.csv
70
+ cpms session SIM-0001/42 # one session: <charge point>/<transaction>
71
+ cpms session SIM-0001/42 stop # acts at once, no confirmation
72
+ cpms report settlements --month 2026-10 # the month's settlements per site, with bookkeeping proposals
73
+ ```
74
+
75
+ **Who is a member, and with which role**
76
+
77
+ ```bash
78
+ cpms members list
79
+ cpms members add ben@example.com --org acme # read
80
+ cpms members add carla@example.com --org acme --role write
81
+ cpms members set-role ben@example.com --org acme --role write
82
+ cpms members remove ben@example.com --org acme
83
+ ```
84
+
85
+ `--org acme` is needed even though your key is already for `acme`.
86
+
87
+ **Keys**
88
+
89
+ ```bash
90
+ cpms keys list # every key of the organization, revoked ones too
91
+ cpms keys issue --name dashboard --scope read # prints the secret once
92
+ cpms keys revoke 7b2d90aa
93
+ ```
94
+
95
+ Every command takes `--json` for machine-readable output.
96
+ `cpms --help` and `cpms <command> --help` list the rest.
97
+
98
+ ## Managing your documents
99
+
100
+ Your organization's price list and each of its sites are YAML documents
101
+ on the server. You change one by exporting it, editing the file, and
102
+ applying it. No git repository is needed:
103
+
104
+ 1. **Export** the document into a file:
105
+
106
+ ```bash
107
+ cpms manifest export acme --site main-street > site.yaml
108
+ ```
109
+
110
+ `--pricelist` exports the price list instead, `--organization` the
111
+ organization document, and with none of them you get every document
112
+ in one file.
113
+
114
+ 2. **Edit** the file in any text editor.
115
+
116
+ 3. **Check it, see what would change, and apply it:**
117
+
118
+ ```bash
119
+ cpms manifest validate site.yaml # offline: the schema; needs no key
120
+ cpms manifest plan site.yaml # the server: the diff, references, live warnings
121
+ cpms manifest apply site.yaml -m "Fused up to 50 A"
122
+ ```
123
+
124
+ `apply` shows the plan again and asks before it applies. `-m`, the
125
+ reason, is required and stored with the version.
126
+
127
+ **The server keeps every version.** Each apply is stored with its message,
128
+ who applied it and when, so you can always see what changed and get an
129
+ older version back:
130
+
131
+ ```bash
132
+ cpms manifest history acme --site main-street # every version, with its message
133
+ cpms manifest export acme --site main-street --version 3 > v3.yaml
134
+ cpms manifest diff acme --site main-street v3 # from version 3 to the current one
135
+ ```
136
+
137
+ Some things to know:
138
+
139
+ - `plan` and `apply` need a `write` key; exporting and history need only
140
+ `read`.
141
+ - Someone else may apply the same document while you edit. Your `plan`
142
+ then shows that your file would undo their change: export again and
143
+ redo your edit. `apply` applies exactly the plan it showed you, and
144
+ refuses if the document changed on the server before you confirmed;
145
+ run it again and read the new plan.
146
+ - Removing anything (a charge point, an outlet, a tariff) needs `--prune`
147
+ on `plan` and `apply`.
148
+ - The organization document is changed by the operator. An organization's
149
+ key applies the price list and the site documents, so export them one at
150
+ a time when you mean to apply them.
151
+ - An outlet's `public_id` is the id in its QR code (`/c/<public_id>`).
152
+ Leave it out and the server makes one up on first apply and keeps it.
153
+ Once the codes are printed, write the ids into the site file
154
+ (`- {connector: 1, key: s1-1, public_id: h7k2m9pq}`): a declared id
155
+ applies, also on a new server, and `plan` warns before an outlet's id
156
+ changes.
157
+
158
+ ### Keeping the files in a repository
159
+
160
+ For a team, keeping the files in a git repository of your own is a good
161
+ habit: you review each other's changes before they are applied, and CI can
162
+ check every change. It is not required; the server's history is the record
163
+ either way. One file per document works well:
164
+
165
+ ```
166
+ organization.yaml
167
+ pricelist.yaml
168
+ sites/main-street.yaml
169
+ sites/harbour.yaml
170
+ ```
171
+
172
+ Edit a file, run `validate` and `plan`, commit, then run `apply` with the
173
+ commit's reason as `-m`. The server holds the truth and the files are a
174
+ way to say things: if someone else applied a change, `plan` shows that
175
+ applying your file would undo it, and `export` brings the file up to date.
176
+ `validate` needs no key, so CI can run it on every pull request; `plan`
177
+ needs one.
178
+
179
+ ## In your editor: the JSON Schema
180
+
181
+ The documents have a JSON Schema, so an editor can complete field names
182
+ and flag mistakes as you type. That works in editors that use
183
+ yaml-language-server: VS Code with Red Hat's YAML extension, Neovim,
184
+ Helix, Zed. Add this line at the top of each file:
185
+
186
+ ```yaml
187
+ # yaml-language-server: $schema=https://raw.githubusercontent.com/forsslund/leancpms/main/schema/manifest.cpms-v1.schema.json
188
+ ```
189
+
190
+ That URL works once the repository is public; replace `main` with a tag
191
+ to pin a version. Until then, use a local copy, written by the command
192
+ itself and kept next to your files:
193
+
194
+ ```bash
195
+ cpms manifest schema > cpms-v1.schema.json
196
+ ```
197
+
198
+ ```yaml
199
+ # yaml-language-server: $schema=cpms-v1.schema.json
200
+ ```
201
+
202
+ The path is relative to the YAML file (`../cpms-v1.schema.json` from
203
+ `sites/`). `export` does not write the line, so add it again after an
204
+ export.
205
+
206
+ The schema checks types, required and unknown fields, allowed values,
207
+ key spelling, and that amounts are quoted (`"4.70"`, not `4.70`). It does
208
+ not check anything that spans several fields: a budget above the fuse,
209
+ duplicate keys, ocpp ids or public ids, a plan naming a missing tariff, or
210
+ an unknown time zone. `validate` and `plan` check those. Only `plan`
211
+ knows whether another outlet on the server already has a public id.
212
+
213
+ ## Scripts, CI and agents
214
+
215
+ A pipeline, a dashboard or an agent of its own gets a key for an
216
+ integration, which records who issued it: `cpms keys issue --name ci
217
+ --scope read` with your personal `write` key. It is shown only once. A key
218
+ you issue lives only as long as your membership: when you leave, it is
219
+ revoked with your own. An integration that must outlive you gets its key
220
+ from the operator.
221
+
222
+ Give the script the key in the environment variable `CPMS_API_KEY`, never
223
+ on the command line, where it ends up in shell history and process lists.
224
+ That is all LeanCPMS Cloud needs; against another instance, set `CPMS_URL`
225
+ too. Without `--profile`, the environment wins over your own login. A
226
+ command that finds no key exits 2 and says what to set. `cpms logout`
227
+ with a key from `CPMS_API_KEY` revokes it but cannot remove it from the
228
+ environment; unset it.
229
+
230
+ - `--json` works on every command, before or after the subcommand.
231
+ - Exit codes: 0 ok, 1 the action failed (the server said no, the server
232
+ could not be reached, a plan has errors), 2 usage or configuration.
233
+ - `cpms manifest apply` never prompts without a TTY. It prints the plan
234
+ and exits 2 unless you pass `--yes`. Show the plan to a person first,
235
+ then apply with `--yes -m "why"`.
236
+ - `session … stop|close` acts at once, with no confirmation step.
237
+ - Pass the key in the environment or the config file, never on the
238
+ command line or in a transcript.
239
+
240
+ ## Releasing (maintainers)
241
+
242
+ Raise `version` in both `cli/pyproject.toml` and the root `pyproject.toml`
243
+ (a test keeps them equal), then tag and push:
244
+
245
+ ```bash
246
+ git tag cli-v0.1.6 && git push origin cli-v0.1.6
247
+ ```
248
+
249
+ `.github/workflows/release-cli.yml` builds the wheel and sdist, smoke-tests
250
+ the wheel, and attaches both to a GitHub release. It also publishes to PyPI
251
+ when the repository variable `PYPI_PUBLISH` is `true`. That needs, once:
252
+ a PyPI account with two-factor authentication; a *pending trusted
253
+ publisher* on PyPI for the project `leancpms-cli` (owner `forsslund`,
254
+ repository `leancpms`, workflow `release-cli.yml`, environment `pypi`);
255
+ and an environment `pypi` in the GitHub repository's settings. A pending
256
+ publisher does not reserve the name: if someone else registers
257
+ `leancpms-cli` first, it becomes invalid. The first release creates the
258
+ project and so reserves the name. Trusted publishing uses GitHub's OIDC
259
+ token, so no PyPI token is stored anywhere. A file published to PyPI cannot be replaced,
260
+ only yanked: a wrong release is fixed with a new version.
@@ -1,21 +1,23 @@
1
1
  """Configuration and the HTTP client of the `cpms` command. No framework.
2
2
 
3
3
  The CLI is a thin client of the JSON API (architecture §3), so it works the
4
- same against a local and a hosted instance. Credentials come from
5
- `CPMS_URL` and `CPMS_API_KEY`, or from a profile in
6
- `~/.config/cpms/config.toml`:
4
+ same against a local and a hosted instance. Without anything else saying
5
+ which instance, it is LeanCPMS Cloud (`DEFAULT_URL`), the way `gh` defaults
6
+ to github.com. Credentials come from `CPMS_URL` and `CPMS_API_KEY`, or from
7
+ a profile in `~/.config/cpms/config.toml`:
7
8
 
8
9
  [default]
9
- url = "http://localhost:8000"
10
- api_key = "lcp_…"
10
+ api_key = "lcp_…" # url left out: LeanCPMS Cloud
11
11
 
12
- [hosted]
12
+ [own]
13
13
  url = "https://cpms.example.com"
14
14
  api_key = "lcp_…"
15
15
 
16
- `--profile NAME` (or `CPMS_PROFILE`) picks a profile; without one the
17
- environment wins, then `[default]`. `cpms login` writes a profile
18
- (`cpms.cli.login`).
16
+ The instance is, first to last: `cpms login --url`, `CPMS_URL`, the
17
+ profile's `url`, `DEFAULT_URL`. One exception: in a profile picked by name
18
+ (`--profile NAME` or `CPMS_PROFILE`) the profile's `url` wins over
19
+ `CPMS_URL`, as its key does over `CPMS_API_KEY`, so its key is not sent to
20
+ another instance. `cpms login` writes a profile (`cpms.cli.login`).
19
21
  """
20
22
 
21
23
  from __future__ import annotations
@@ -29,6 +31,10 @@ from typing import Any
29
31
  import httpx
30
32
 
31
33
 
34
+ # LeanCPMS Cloud's API, the instance when nothing else names one.
35
+ DEFAULT_URL = "https://api.leancpms.com"
36
+
37
+
32
38
  class UsageError(Exception):
33
39
  """Exit code 2: the command line or the configuration is wrong."""
34
40
 
@@ -55,10 +61,23 @@ class Config:
55
61
  api_key: str
56
62
 
57
63
 
64
+ def instance_url(flag: str | None = None, profile_url: str = "", named_profile: bool = False) -> str:
65
+ """The instance to talk to: `flag` (`cpms login --url`), then `CPMS_URL`, then the profile's `url`, then
66
+ LeanCPMS Cloud. A profile picked by name is used whole: its `url` wins over `CPMS_URL`."""
67
+ env = os.environ.get("CPMS_URL", "")
68
+ found = (profile_url or env) if named_profile else (env or profile_url)
69
+ return (flag or found or DEFAULT_URL).rstrip("/")
70
+
71
+
72
+ def describe(url: str) -> str:
73
+ """The instance as the person reads it."""
74
+ return f"LeanCPMS Cloud ({url})" if url == DEFAULT_URL else url
75
+
76
+
58
77
  def load_config(profile: str | None) -> Config:
59
78
  profile = profile or os.environ.get("CPMS_PROFILE") or None
60
- url, key = os.environ.get("CPMS_URL", ""), os.environ.get("CPMS_API_KEY", "")
61
- if profile or not (url and key):
79
+ url, key = "", os.environ.get("CPMS_API_KEY", "")
80
+ if profile or not (os.environ.get("CPMS_URL") and key):
62
81
  path = config_path()
63
82
  section: dict[str, Any] = {}
64
83
  if path.exists():
@@ -71,13 +90,14 @@ def load_config(profile: str | None) -> Config:
71
90
  raise UsageError(f"no profile [{profile}] in {path}")
72
91
  elif profile:
73
92
  raise UsageError(f"no profile [{profile}]: {path} does not exist")
74
- if profile:
75
- url, key = str(section.get("url", "")), str(section.get("api_key", ""))
76
- else:
77
- url, key = url or str(section.get("url", "")), key or str(section.get("api_key", ""))
78
- if not url or not key:
79
- raise UsageError(f"set CPMS_URL and CPMS_API_KEY, or a profile in {config_path()}")
80
- return Config(url.rstrip("/"), key)
93
+ url = str(section.get("url", ""))
94
+ key = str(section.get("api_key", "")) if profile else key or str(section.get("api_key", ""))
95
+ url = instance_url(None, url, named_profile=bool(profile))
96
+ if not key:
97
+ login = f"cpms login --profile {profile}" if profile else "cpms login"
98
+ raise UsageError(f"no API key for {describe(url)}: run {login}, or set CPMS_API_KEY "
99
+ f"(or a profile in {config_path()})")
100
+ return Config(url, key)
81
101
 
82
102
 
83
103
  class Api:
@@ -97,7 +117,7 @@ class Api:
97
117
  try:
98
118
  r = self._http.request(method, path, json=json, params=clean)
99
119
  except httpx.HTTPError as e:
100
- raise ApiError(f"{method} {path}: {e}") from None
120
+ raise ApiError(f"{method} {path} on {self.config.url}: {e}") from None
101
121
  try:
102
122
  body = r.json() if r.content else None
103
123
  except ValueError:
@@ -113,7 +133,7 @@ class Api:
113
133
  try:
114
134
  r = self._http.request(method, path, json=json)
115
135
  except httpx.HTTPError as e:
116
- raise ApiError(f"{method} {path}: {e}") from None
136
+ raise ApiError(f"{method} {path} on {self.config.url}: {e}") from None
117
137
  try:
118
138
  return r.status_code, r.json() if r.content else None
119
139
  except ValueError:
@@ -18,7 +18,7 @@ from typing import Any, Callable
18
18
  from cpms.manifest.documents import ManifestError, diff, json_schema, parse_yaml, to_data, to_yaml
19
19
 
20
20
  from . import login
21
- from .client import Api, ApiError, UsageError, config_path, load_config
21
+ from .client import DEFAULT_URL, Api, ApiError, UsageError, config_path, describe, instance_url, load_config
22
22
 
23
23
  Out = Callable[[str], None]
24
24
 
@@ -565,12 +565,15 @@ def cmd_keys_revoke(api: Api, a: argparse.Namespace) -> int:
565
565
  def cmd_login(api: None, a: argparse.Namespace) -> int:
566
566
  """The device flow: approve in the portal, get a personal key, save it as a profile."""
567
567
  path = config_path()
568
- name = login.profile_name(getattr(a, "profile", None) or os.environ.get("CPMS_PROFILE") or "default")
568
+ named = getattr(a, "profile", None) or os.environ.get("CPMS_PROFILE")
569
+ name = login.profile_name(named or "default")
569
570
  text = login.read(path)
570
- url = (a.url or login.profile_value(path, text, name, "url") or os.environ.get("CPMS_URL", "")).rstrip("/")
571
+ url = instance_url(a.url, login.profile_value(path, text, name, "url"), named_profile=bool(named))
571
572
  if not url.startswith(("https://", "http://")):
572
- raise UsageError(f"not an http(s) address: {url!r}" if url else "give the instance: cpms login --url https://…")
573
+ raise UsageError(f"not an http(s) address: {url!r}")
573
574
  login.set_profile(path, text, name, url, "lcp_check") # refuse now rather than after a key is issued
575
+ _err(f"Logging in to {describe(url)}." + (" Your own instance: cpms login --url https://…"
576
+ if url == DEFAULT_URL and not a.url else ""))
574
577
  http, started = login.start(url, a.scope)
575
578
  try:
576
579
  page = login.verification_url(url, str(started.get("user_code", "")))
@@ -595,8 +598,8 @@ def cmd_login(api: None, a: argparse.Namespace) -> int:
595
598
  _dump(result)
596
599
  else:
597
600
  whose = f"organization {key['organization']}" if key["organization"] else "the operator"
598
- _print(f"logged in: a personal {key['scope']} key {key['prefix']} for {whose}, saved as profile [{name}] "
599
- f"in {path}")
601
+ _print(f"logged in: a personal {key['scope']} key {key['prefix']} for {whose} on {describe(url)}, "
602
+ f"saved as profile [{name}] in {path}")
600
603
  return 0
601
604
 
602
605
 
@@ -633,11 +636,11 @@ def cmd_logout(api: Api, a: argparse.Namespace) -> int:
633
636
  def cmd_whoami(api: Api, a: argparse.Namespace) -> int:
634
637
  r = api.get("/auth/me")
635
638
  if a.json:
636
- _dump(r)
639
+ _dump({**r, "url": api.config.url})
637
640
  return 0
638
641
  who = r["email"] if r["personal"] else "a machine key"
639
642
  whose = f"organization {r['organization']}" if r["organization"] else "the operator (every organization)"
640
- _print(f"{who}: {r['scope']} key {r['prefix']} ({r['name']}) for {whose}")
643
+ _print(f"{who}: {r['scope']} key {r['prefix']} ({r['name']}) for {whose} on {describe(api.config.url)}")
641
644
  return 0
642
645
 
643
646
 
@@ -787,7 +790,15 @@ def parser() -> argparse.ArgumentParser:
787
790
  common.add_argument("--json", action="store_true", default=argparse.SUPPRESS, help="machine-readable output")
788
791
  common.add_argument("--profile", default=argparse.SUPPRESS, help="profile in ~/.config/cpms/config.toml")
789
792
  p = _Parser(prog="cpms", parents=[common], description="LeanCPMS from the command line. "
790
- "Alone, prints the live state.")
793
+ "Alone, prints the live state. Talks to LeanCPMS Cloud unless told otherwise.",
794
+ formatter_class=argparse.RawDescriptionHelpFormatter,
795
+ epilog=f"The instance: cpms login --url (saved in the profile), else CPMS_URL, else the profile's "
796
+ f"url,\nelse LeanCPMS Cloud ({DEFAULT_URL}).\n\n"
797
+ "environment:\n"
798
+ " CPMS_URL the instance, e.g. https://cpms.example.com\n"
799
+ " CPMS_API_KEY the key, instead of a profile's (scripts, CI, agents)\n"
800
+ " CPMS_PROFILE the profile, as --profile\n"
801
+ " CPMS_CONFIG the config file (default ~/.config/cpms/config.toml)")
791
802
  sub = p.add_subparsers(dest="command", parser_class=_Parser)
792
803
 
793
804
  def cmd(name: str, fn: Callable[..., int], help: str, **kw: Any) -> argparse.ArgumentParser:
@@ -890,9 +901,10 @@ def parser() -> argparse.ArgumentParser:
890
901
  s.add_argument("org")
891
902
  s.add_argument("site")
892
903
 
893
- s = cmd("login", cmd_login, "log in with your portal login: approve in the browser, get a personal key, "
894
- "saved as a profile (--profile, default [default])")
895
- s.add_argument("--url", help="the instance, e.g. https://cpms.example.com (default: the profile's)")
904
+ s = cmd("login", cmd_login, "log in to LeanCPMS Cloud (or --url) with your portal login: approve in the "
905
+ "browser, get a personal key, saved as a profile (--profile, default [default])")
906
+ s.add_argument("--url", help="your own instance, e.g. https://cpms.example.com, saved in the profile "
907
+ f"(default: CPMS_URL, the profile's url, else LeanCPMS Cloud, {DEFAULT_URL})")
896
908
  s.add_argument("--scope", choices=["read", "write"], default="write",
897
909
  help="what to ask for; you decide when approving (default write)")
898
910
  s.add_argument("--no-browser", action="store_true", help="only print the address to open")
@@ -70,6 +70,12 @@ def _not_reserved(value: str) -> str:
70
70
 
71
71
 
72
72
  OrganizationKey = Annotated[Key, AfterValidator(_not_reserved)]
73
+
74
+ # An outlet's public id, the last part of its QR code's URL (/c/<public_id>). The server generates
75
+ # one from this alphabet (no 0, 1, i, l or o, which read alike) unless the site document declares it.
76
+ PUBLIC_ID_ALPHABET = "23456789abcdefghjkmnpqrstuvwxyz"
77
+ PUBLIC_ID_LENGTH = 8
78
+ PublicId = Annotated[str, StringConstraints(pattern=rf"^[{PUBLIC_ID_ALPHABET}]{{{PUBLIC_ID_LENGTH}}}$")]
73
79
  Rate = Annotated[Decimal, BeforeValidator(_no_float), Field(ge=0, le=1), _DECIMAL_TEXT]
74
80
 
75
81
 
@@ -344,6 +350,11 @@ class Outlet(Strict):
344
350
  plug: Literal["type2_socket", "type2_cable"] | None = None
345
351
  phases: Literal[1, 3] | None = None
346
352
  evse_id: Annotated[str, StringConstraints(max_length=48)] | None = None # overrides the derived eMI3 id
353
+ # The id in the printed QR code, a physical fact once printed. Left out, the server generates one
354
+ # on first apply and keeps it; declared, it applies, also over one generated before.
355
+ public_id: PublicId | None = Field(default=None, description=(
356
+ f"the id in the outlet's printed QR code (/c/<public_id>): {PUBLIC_ID_LENGTH} characters from "
357
+ f"{PUBLIC_ID_ALPHABET}; left out, the server generates one on first apply and keeps it"))
347
358
 
348
359
 
349
360
  class ChargePoint(Strict):
@@ -415,7 +426,9 @@ class Site(Strict):
415
426
  cps = [cp for fg in self.fuse_groups for cp in fg.charge_points]
416
427
  _unique(cps, "key", "charge point")
417
428
  _unique(cps, "ocpp_id", "ocpp_id")
418
- _unique([o for cp in cps for o in cp.outlets], "key", "outlet")
429
+ outlets = [o for cp in cps for o in cp.outlets]
430
+ _unique(outlets, "key", "outlet")
431
+ _unique([o for o in outlets if o.public_id], "public_id", "public_id")
419
432
  return self
420
433
 
421
434
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "leancpms-cli"
3
- version = "0.1.4"
3
+ version = "0.1.6"
4
4
  description = "The cpms command alone: a client of a LeanCPMS instance's JSON API"
5
5
  readme = "README.md"
6
6
  license = "AGPL-3.0-or-later"
@@ -1,211 +0,0 @@
1
- Metadata-Version: 2.5
2
- Name: leancpms-cli
3
- Version: 0.1.4
4
- Summary: The cpms command alone: a client of a LeanCPMS instance's JSON API
5
- License-Expression: AGPL-3.0-or-later
6
- License-File: LICENSE
7
- Requires-Python: >=3.14
8
- Requires-Dist: httpx>=0.28.1
9
- Requires-Dist: pydantic>=2.14.1
10
- Requires-Dist: pyyaml>=6.0.3
11
- Description-Content-Type: text/markdown
12
-
13
- # `cpms`, the LeanCPMS command line
14
-
15
- `cpms` manages an organization in a LeanCPMS instance from your own
16
- machine: live state, sessions, the monthly settlements, and the declared
17
- state (organization, price list, sites) as YAML documents you can keep in
18
- a git repository. It talks to the instance's JSON API over HTTPS with an
19
- API key, and the same commands work for people and for AI agents.
20
-
21
- This directory builds `leancpms-cli`, the command without the server. It
22
- depends on httpx, pydantic and PyYAML only.
23
-
24
- ## Install
25
-
26
- With [uv](https://docs.astral.sh/uv/), from PyPI once it is published there:
27
-
28
- ```bash
29
- uv tool install leancpms-cli
30
- cpms --help
31
- ```
32
-
33
- Until then, from a GitHub release (a tag `cli-v<version>`) or straight
34
- from the repository:
35
-
36
- ```bash
37
- gh release download cli-v0.1.4 --repo forsslund/leancpms --pattern '*.whl'
38
- uv tool install ./leancpms_cli-0.1.4-py3-none-any.whl
39
- # or
40
- uv tool install "git+https://github.com/forsslund/leancpms#subdirectory=cli"
41
- ```
42
-
43
- - The repository is private for now, so both need read access to it on
44
- GitHub; over SSH the URL is
45
- `git+ssh://git@github.com/forsslund/leancpms#subdirectory=cli`.
46
- - It needs Python 3.14. uv downloads it if your machine lacks it.
47
- - To get a newer version, run `uv tool upgrade leancpms-cli`. To pin a
48
- version, add `@<tag or commit>` after the repository URL.
49
- - `pipx install "git+…#subdirectory=cli"` works too.
50
- - Do not install it into an environment that already has the server
51
- (`leancpms`). The server already includes `cpms`, and both packages
52
- carry the same files, so uninstalling one breaks the other.
53
-
54
- ## Configure
55
-
56
- Log in with the same e-mail address you use for the instance's portal:
57
-
58
- ```bash
59
- cpms login --url https://cpms.example.com
60
- ```
61
-
62
- It prints a code and opens the portal's page for it in your browser (or
63
- prints the address only: `--no-browser`, or no display). Log in there if
64
- you are not, check that the page shows the same code, choose your
65
- organization and whether the key may act (`write`) or only look (`read`),
66
- and approve. Your role as a member decides which you may choose: members
67
- are `read` unless the operator, or a colleague with a `write` key, made
68
- them `write` (`cpms members set-role`). `cpms login` waits for that and then saves a
69
- **personal key**, yours and that organization's, as the profile
70
- `[default]` (`--profile NAME` for another) in `~/.config/cpms/config.toml`,
71
- readable only by you. Other profiles in the file stay as they were.
72
-
73
- ```bash
74
- cpms whoami # which key is in use, whose, for which organization
75
- cpms logout # revokes the key on the server and removes the profile
76
- ```
77
-
78
- The key stops working when you are removed as a member, and so does
79
- every key you issued with it. Approve a code only if you just ran
80
- `cpms login` yourself: whoever started it gets the key.
81
-
82
- ### Machine keys, for CI and agents
83
-
84
- A pipeline or an agent of its own gets a machine key instead, which
85
- records who issued it: `cpms keys issue --name ci --scope read` with your
86
- personal `write` key. It is shown only once. An organization key sees only
87
- its own organization. A key you issue lives only as long as your
88
- membership: when you leave, it is revoked with your own. An integration
89
- that must outlive you gets its key from the operator. Members you add do
90
- stay when you leave; `cpms members list` shows who added whom.
91
-
92
- Put the URL and the key in `~/.config/cpms/config.toml` (or
93
- `$XDG_CONFIG_HOME/cpms/`, or the path in `CPMS_CONFIG`), readable only by
94
- you (`chmod 600`):
95
-
96
- ```toml
97
- [default]
98
- url = "https://cpms.example.com"
99
- api_key = "lcp_…"
100
-
101
- [test]
102
- url = "http://localhost:8000"
103
- api_key = "lcp_…"
104
- ```
105
-
106
- Alternatively, set `CPMS_URL` and `CPMS_API_KEY` in the environment, which
107
- suits CI and agents. `--profile test` (or `CPMS_PROFILE=test`) picks a
108
- profile. Without a profile, the environment wins, then `[default]`.
109
- A networked command that has neither exits 2 and says what to set.
110
-
111
- ## Use
112
-
113
- ```bash
114
- cpms # live state: sites, fuse groups, outlets, current per phase
115
- cpms sessions --since 2026-10-01
116
- cpms report settlements --month 2026-10 # the month's settlements per site, with bookkeeping proposals
117
- cpms manifest export kvartersel > all.yaml
118
- cpms manifest export kvartersel --site odalvagen > sites/odalvagen.yaml
119
- cpms manifest validate sites/odalvagen.yaml # offline: the schema
120
- cpms manifest plan sites/odalvagen.yaml # the server: the diff, references, live warnings
121
- cpms manifest apply sites/odalvagen.yaml -m "Fused up to 50 A"
122
- cpms manifest history kvartersel --site odalvagen
123
- ```
124
-
125
- `cpms --help` and `cpms manifest --help` list the rest.
126
-
127
- ## A repository of manifests
128
-
129
- One file per document works well:
130
-
131
- ```
132
- organization.yaml
133
- pricelist.yaml
134
- sites/odalvagen.yaml
135
- sites/brotorp.yaml
136
- ```
137
-
138
- Edit a file, run `validate` and `plan`, commit, then run `apply` with the
139
- commit's reason as `-m`. The server holds the truth and the files are a
140
- way to say things: if someone changed a price in the portal, `plan` shows
141
- that applying your file would undo it, and `export` brings the file up to
142
- date. `apply` refuses a
143
- document that changed on the server since your plan; plan again. Removing
144
- anything needs `--prune`. `validate` needs no key, so CI can run it on
145
- every pull request; `plan` needs one.
146
-
147
- ## In your editor: the JSON Schema
148
-
149
- The documents have a JSON Schema, so an editor can complete field names
150
- and flag mistakes as you type. That works in editors that use
151
- yaml-language-server: VS Code with Red Hat's YAML extension, Neovim,
152
- Helix, Zed. Add this line at the top of each file:
153
-
154
- ```yaml
155
- # yaml-language-server: $schema=https://raw.githubusercontent.com/forsslund/leancpms/main/schema/manifest.cpms-v1.schema.json
156
- ```
157
-
158
- That URL works once the repository is public; replace `main` with a tag
159
- to pin a version. Until then, use a local copy, written by the command
160
- itself and kept in your manifest repository:
161
-
162
- ```bash
163
- cpms manifest schema > cpms-v1.schema.json
164
- ```
165
-
166
- ```yaml
167
- # yaml-language-server: $schema=../cpms-v1.schema.json
168
- ```
169
-
170
- The path is relative to the YAML file. `export` does not write the
171
- line, so add it again after an export.
172
-
173
- The schema checks types, required and unknown fields, allowed values,
174
- key spelling, and that amounts are quoted (`"4.70"`, not `4.70`). It does
175
- not check anything that spans several fields: a budget above the fuse,
176
- duplicate keys or ocpp ids, a plan naming a missing tariff, or an unknown
177
- time zone. `validate` and `plan` check those.
178
-
179
- ## For agents
180
-
181
- - `--json` works on every command, before or after the subcommand.
182
- - Exit codes: 0 ok, 1 the action failed (the server said no, the server
183
- could not be reached, a plan has errors), 2 usage or configuration.
184
- - `cpms manifest apply` never prompts without a TTY. It prints the plan
185
- and exits 2 unless you pass `--yes`. Show the plan to a person first,
186
- then apply with `--yes -m "why"`.
187
- - `session … stop|close` acts at once, with no confirmation step.
188
- - Pass the key in the environment or the config file, never on the
189
- command line or in a transcript.
190
-
191
- ## Releasing (maintainers)
192
-
193
- Raise `version` in both `cli/pyproject.toml` and the root `pyproject.toml`
194
- (a test keeps them equal), then tag and push:
195
-
196
- ```bash
197
- git tag cli-v0.1.4 && git push origin cli-v0.1.4
198
- ```
199
-
200
- `.github/workflows/release-cli.yml` builds the wheel and sdist, smoke-tests
201
- the wheel, and attaches both to a GitHub release. It also publishes to PyPI
202
- when the repository variable `PYPI_PUBLISH` is `true`. That needs, once:
203
- a PyPI account with two-factor authentication; a *pending trusted
204
- publisher* on PyPI for the project `leancpms-cli` (owner `forsslund`,
205
- repository `leancpms`, workflow `release-cli.yml`, environment `pypi`);
206
- and an environment `pypi` in the GitHub repository's settings. A pending
207
- publisher does not reserve the name: if someone else registers
208
- `leancpms-cli` first, it becomes invalid. The first release creates the
209
- project and so reserves the name. Trusted publishing uses GitHub's OIDC
210
- token, so no PyPI token is stored anywhere. A file published to PyPI cannot be replaced,
211
- only yanked: a wrong release is fixed with a new version.
@@ -1,199 +0,0 @@
1
- # `cpms`, the LeanCPMS command line
2
-
3
- `cpms` manages an organization in a LeanCPMS instance from your own
4
- machine: live state, sessions, the monthly settlements, and the declared
5
- state (organization, price list, sites) as YAML documents you can keep in
6
- a git repository. It talks to the instance's JSON API over HTTPS with an
7
- API key, and the same commands work for people and for AI agents.
8
-
9
- This directory builds `leancpms-cli`, the command without the server. It
10
- depends on httpx, pydantic and PyYAML only.
11
-
12
- ## Install
13
-
14
- With [uv](https://docs.astral.sh/uv/), from PyPI once it is published there:
15
-
16
- ```bash
17
- uv tool install leancpms-cli
18
- cpms --help
19
- ```
20
-
21
- Until then, from a GitHub release (a tag `cli-v<version>`) or straight
22
- from the repository:
23
-
24
- ```bash
25
- gh release download cli-v0.1.4 --repo forsslund/leancpms --pattern '*.whl'
26
- uv tool install ./leancpms_cli-0.1.4-py3-none-any.whl
27
- # or
28
- uv tool install "git+https://github.com/forsslund/leancpms#subdirectory=cli"
29
- ```
30
-
31
- - The repository is private for now, so both need read access to it on
32
- GitHub; over SSH the URL is
33
- `git+ssh://git@github.com/forsslund/leancpms#subdirectory=cli`.
34
- - It needs Python 3.14. uv downloads it if your machine lacks it.
35
- - To get a newer version, run `uv tool upgrade leancpms-cli`. To pin a
36
- version, add `@<tag or commit>` after the repository URL.
37
- - `pipx install "git+…#subdirectory=cli"` works too.
38
- - Do not install it into an environment that already has the server
39
- (`leancpms`). The server already includes `cpms`, and both packages
40
- carry the same files, so uninstalling one breaks the other.
41
-
42
- ## Configure
43
-
44
- Log in with the same e-mail address you use for the instance's portal:
45
-
46
- ```bash
47
- cpms login --url https://cpms.example.com
48
- ```
49
-
50
- It prints a code and opens the portal's page for it in your browser (or
51
- prints the address only: `--no-browser`, or no display). Log in there if
52
- you are not, check that the page shows the same code, choose your
53
- organization and whether the key may act (`write`) or only look (`read`),
54
- and approve. Your role as a member decides which you may choose: members
55
- are `read` unless the operator, or a colleague with a `write` key, made
56
- them `write` (`cpms members set-role`). `cpms login` waits for that and then saves a
57
- **personal key**, yours and that organization's, as the profile
58
- `[default]` (`--profile NAME` for another) in `~/.config/cpms/config.toml`,
59
- readable only by you. Other profiles in the file stay as they were.
60
-
61
- ```bash
62
- cpms whoami # which key is in use, whose, for which organization
63
- cpms logout # revokes the key on the server and removes the profile
64
- ```
65
-
66
- The key stops working when you are removed as a member, and so does
67
- every key you issued with it. Approve a code only if you just ran
68
- `cpms login` yourself: whoever started it gets the key.
69
-
70
- ### Machine keys, for CI and agents
71
-
72
- A pipeline or an agent of its own gets a machine key instead, which
73
- records who issued it: `cpms keys issue --name ci --scope read` with your
74
- personal `write` key. It is shown only once. An organization key sees only
75
- its own organization. A key you issue lives only as long as your
76
- membership: when you leave, it is revoked with your own. An integration
77
- that must outlive you gets its key from the operator. Members you add do
78
- stay when you leave; `cpms members list` shows who added whom.
79
-
80
- Put the URL and the key in `~/.config/cpms/config.toml` (or
81
- `$XDG_CONFIG_HOME/cpms/`, or the path in `CPMS_CONFIG`), readable only by
82
- you (`chmod 600`):
83
-
84
- ```toml
85
- [default]
86
- url = "https://cpms.example.com"
87
- api_key = "lcp_…"
88
-
89
- [test]
90
- url = "http://localhost:8000"
91
- api_key = "lcp_…"
92
- ```
93
-
94
- Alternatively, set `CPMS_URL` and `CPMS_API_KEY` in the environment, which
95
- suits CI and agents. `--profile test` (or `CPMS_PROFILE=test`) picks a
96
- profile. Without a profile, the environment wins, then `[default]`.
97
- A networked command that has neither exits 2 and says what to set.
98
-
99
- ## Use
100
-
101
- ```bash
102
- cpms # live state: sites, fuse groups, outlets, current per phase
103
- cpms sessions --since 2026-10-01
104
- cpms report settlements --month 2026-10 # the month's settlements per site, with bookkeeping proposals
105
- cpms manifest export kvartersel > all.yaml
106
- cpms manifest export kvartersel --site odalvagen > sites/odalvagen.yaml
107
- cpms manifest validate sites/odalvagen.yaml # offline: the schema
108
- cpms manifest plan sites/odalvagen.yaml # the server: the diff, references, live warnings
109
- cpms manifest apply sites/odalvagen.yaml -m "Fused up to 50 A"
110
- cpms manifest history kvartersel --site odalvagen
111
- ```
112
-
113
- `cpms --help` and `cpms manifest --help` list the rest.
114
-
115
- ## A repository of manifests
116
-
117
- One file per document works well:
118
-
119
- ```
120
- organization.yaml
121
- pricelist.yaml
122
- sites/odalvagen.yaml
123
- sites/brotorp.yaml
124
- ```
125
-
126
- Edit a file, run `validate` and `plan`, commit, then run `apply` with the
127
- commit's reason as `-m`. The server holds the truth and the files are a
128
- way to say things: if someone changed a price in the portal, `plan` shows
129
- that applying your file would undo it, and `export` brings the file up to
130
- date. `apply` refuses a
131
- document that changed on the server since your plan; plan again. Removing
132
- anything needs `--prune`. `validate` needs no key, so CI can run it on
133
- every pull request; `plan` needs one.
134
-
135
- ## In your editor: the JSON Schema
136
-
137
- The documents have a JSON Schema, so an editor can complete field names
138
- and flag mistakes as you type. That works in editors that use
139
- yaml-language-server: VS Code with Red Hat's YAML extension, Neovim,
140
- Helix, Zed. Add this line at the top of each file:
141
-
142
- ```yaml
143
- # yaml-language-server: $schema=https://raw.githubusercontent.com/forsslund/leancpms/main/schema/manifest.cpms-v1.schema.json
144
- ```
145
-
146
- That URL works once the repository is public; replace `main` with a tag
147
- to pin a version. Until then, use a local copy, written by the command
148
- itself and kept in your manifest repository:
149
-
150
- ```bash
151
- cpms manifest schema > cpms-v1.schema.json
152
- ```
153
-
154
- ```yaml
155
- # yaml-language-server: $schema=../cpms-v1.schema.json
156
- ```
157
-
158
- The path is relative to the YAML file. `export` does not write the
159
- line, so add it again after an export.
160
-
161
- The schema checks types, required and unknown fields, allowed values,
162
- key spelling, and that amounts are quoted (`"4.70"`, not `4.70`). It does
163
- not check anything that spans several fields: a budget above the fuse,
164
- duplicate keys or ocpp ids, a plan naming a missing tariff, or an unknown
165
- time zone. `validate` and `plan` check those.
166
-
167
- ## For agents
168
-
169
- - `--json` works on every command, before or after the subcommand.
170
- - Exit codes: 0 ok, 1 the action failed (the server said no, the server
171
- could not be reached, a plan has errors), 2 usage or configuration.
172
- - `cpms manifest apply` never prompts without a TTY. It prints the plan
173
- and exits 2 unless you pass `--yes`. Show the plan to a person first,
174
- then apply with `--yes -m "why"`.
175
- - `session … stop|close` acts at once, with no confirmation step.
176
- - Pass the key in the environment or the config file, never on the
177
- command line or in a transcript.
178
-
179
- ## Releasing (maintainers)
180
-
181
- Raise `version` in both `cli/pyproject.toml` and the root `pyproject.toml`
182
- (a test keeps them equal), then tag and push:
183
-
184
- ```bash
185
- git tag cli-v0.1.4 && git push origin cli-v0.1.4
186
- ```
187
-
188
- `.github/workflows/release-cli.yml` builds the wheel and sdist, smoke-tests
189
- the wheel, and attaches both to a GitHub release. It also publishes to PyPI
190
- when the repository variable `PYPI_PUBLISH` is `true`. That needs, once:
191
- a PyPI account with two-factor authentication; a *pending trusted
192
- publisher* on PyPI for the project `leancpms-cli` (owner `forsslund`,
193
- repository `leancpms`, workflow `release-cli.yml`, environment `pypi`);
194
- and an environment `pypi` in the GitHub repository's settings. A pending
195
- publisher does not reserve the name: if someone else registers
196
- `leancpms-cli` first, it becomes invalid. The first release creates the
197
- project and so reserves the name. Trusted publishing uses GitHub's OIDC
198
- token, so no PyPI token is stored anywhere. A file published to PyPI cannot be replaced,
199
- only yanked: a wrong release is fixed with a new version.
File without changes
File without changes