yoobi-cli 0.1.2__tar.gz → 0.1.3__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.
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/Cargo.lock +1 -1
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/Cargo.toml +2 -2
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/PKG-INFO +9 -51
- yoobi_cli-0.1.3/README.md +56 -0
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/pyproject.toml +1 -1
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/src/api.rs +19 -162
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/src/error.rs +1 -8
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/src/lib.rs +2 -2
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/src/main.rs +6 -81
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/src/output.rs +0 -44
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/src/schema.rs +8 -40
- yoobi_cli-0.1.3/src/timesheet.rs +75 -0
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/src/tui.rs +32 -226
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/tests/cli.rs +11 -41
- yoobi_cli-0.1.3/tests/http.rs +163 -0
- yoobi_cli-0.1.3/tests/timesheet.rs +28 -0
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/tests/tui.rs +5 -1
- yoobi_cli-0.1.2/README.md +0 -98
- yoobi_cli-0.1.2/src/plan.rs +0 -290
- yoobi_cli-0.1.2/tests/http.rs +0 -355
- yoobi_cli-0.1.2/tests/planning.rs +0 -156
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/LICENSE +0 -0
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/schemas/clispec-v0.3.json +0 -0
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/src/auth.rs +0 -0
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/src/config.rs +0 -0
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/tests/auth.rs +0 -0
- {yoobi_cli-0.1.2 → yoobi_cli-0.1.3}/tests/conformance.rs +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "yoobi-cli"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.3"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
rust-version = "1.100"
|
|
6
|
-
description = "Read
|
|
6
|
+
description = "Read and browse Yoobi timesheets from the command line"
|
|
7
7
|
authors = ["Ruben J. Jongejan <ruben.jongejan@gmail.com>"]
|
|
8
8
|
license = "MIT"
|
|
9
9
|
repository = "https://github.com/rvben/yoobi-cli"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: yoobi-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Classifier: Development Status :: 3 - Alpha
|
|
5
5
|
Classifier: Environment :: Console
|
|
6
6
|
Classifier: Intended Audience :: Developers
|
|
@@ -9,7 +9,7 @@ Classifier: Operating System :: OS Independent
|
|
|
9
9
|
Classifier: Programming Language :: Rust
|
|
10
10
|
Classifier: Topic :: Utilities
|
|
11
11
|
License-File: LICENSE
|
|
12
|
-
Summary: Read
|
|
12
|
+
Summary: Read and browse Yoobi timesheets from the command line
|
|
13
13
|
Author: Ruben J. Jongejan <ruben.jongejan@gmail.com>
|
|
14
14
|
License: MIT
|
|
15
15
|
Requires-Python: >=3.8
|
|
@@ -19,7 +19,7 @@ Project-URL: Repository, https://github.com/rvben/yoobi-cli
|
|
|
19
19
|
|
|
20
20
|
# yoobi-cli
|
|
21
21
|
|
|
22
|
-
A native Rust CLI for Yoobi's classic timesheet
|
|
22
|
+
A native Rust CLI for Yoobi's classic timesheet. Browse booked hours, activities and locked dates in your terminal, or read them as JSON for scripts. Save a login securely in your OS credential store.
|
|
23
23
|
|
|
24
24
|
Build and install locally:
|
|
25
25
|
|
|
@@ -52,67 +52,25 @@ yoobi-cli projects --month 2026-11
|
|
|
52
52
|
yoobi-cli timesheet --month 2026-11
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
Use an activity ID returned by `projects` as `project_id`. Create `work.json` with actual durations in integer minutes:
|
|
56
|
-
|
|
57
|
-
```json
|
|
58
|
-
{
|
|
59
|
-
"month": "2026-11",
|
|
60
|
-
"project_id": "activity-id-from-projects",
|
|
61
|
-
"opening_balance_minutes": 450,
|
|
62
|
-
"days": [
|
|
63
|
-
{"date": "2026-11-02", "actual_minutes": 360},
|
|
64
|
-
{"date": "2026-11-03", "actual_minutes": 345, "hours": 8},
|
|
65
|
-
{"date": "2026-11-04", "actual_minutes": 240}
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
By default, positive work under 6 hours rounds to 4; 6 hours or more rounds to 8. Set `hours` explicitly to choose 4 or 8, including the 5h45 → 8h exception. Omit zero-work days. A plan replaces that activity's daily total; it does not add another booking.
|
|
71
|
-
|
|
72
|
-
```sh
|
|
73
|
-
yoobi-cli plan work.json --output json > plan.json
|
|
74
|
-
yoobi-cli apply plan.json --dry-run
|
|
75
|
-
yoobi-cli balance plan.json --output text
|
|
76
|
-
# After reviewing the plan:
|
|
77
|
-
yoobi-cli apply plan.json --yes
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
Plans record the origin, employee, and previous daily values. Apply reads fresh data, refuses stale or locked changes, skips already matching entries, then reads again to verify all bookings in the month. It only writes the selected activity and dates. Closing/approving timesheets, overtime, mandatory notes, alternative booking types, and creating activities are unsupported. Existing note/reference values are preserved. The native adapter follows the observed classic Yoobi 2.30.2 routes; format changes fail closed.
|
|
81
|
-
|
|
82
|
-
Yoobi offers no atomic compare-and-save in this protocol: a concurrent edit between the preflight read and save can race. Avoid editing the same timesheet elsewhere while applying. A network error may occur after a save; inspect the timesheet before retrying. Writes are never automatically retried.
|
|
83
|
-
|
|
84
|
-
Balance is `opening balance + actual − booked`: positive is surplus, negative is debt. To calculate an independent balance offline, pass a ledger instead of a plan:
|
|
85
|
-
|
|
86
|
-
```json
|
|
87
|
-
{
|
|
88
|
-
"opening_balance_minutes": 450,
|
|
89
|
-
"days": [
|
|
90
|
-
{"date": "2026-11-02", "actual_minutes": 345, "booked_minutes": 480}
|
|
91
|
-
]
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
|
|
96
55
|
## Interactive review
|
|
97
56
|
|
|
98
57
|
```sh
|
|
99
|
-
yoobi-cli tui --demo # offline sample
|
|
58
|
+
yoobi-cli tui --demo # offline sample timesheet
|
|
100
59
|
yoobi-cli tui --month 2026-11 # connected, read only
|
|
101
|
-
yoobi-cli tui --plan plan.json # account-bound plan preview
|
|
102
60
|
yoobi-cli tui --demo --snapshot --month 2026-11 --width 120 --height 36
|
|
103
61
|
```
|
|
104
62
|
|
|
105
|
-
The TUI shows activities,
|
|
63
|
+
The default TUI shows activities, daily booked hours and locked dates. It adapts from 40-column terminals to a three-pane workspace. The demo is always labelled and does not read credentials or send requests. Connected reads happen in a background worker. If a refresh fails, its error stays visible and can be retried.
|
|
106
64
|
|
|
107
|
-
Use **↑/↓** or **j/k** for days, **Tab/Shift-Tab** for activities, **Enter** for day detail/back, **[ / ]** for months, **/** to find a date, **r** to refresh, **?** for help, and **q** or **Ctrl-C** to quit. Home/End and Page Up/Down work too. In day detail,
|
|
65
|
+
Use **↑/↓** or **j/k** for days, **Tab/Shift-Tab** for activities, **Enter** for day detail/back, **[ / ]** for months, **/** to find a date, **r** to refresh, **?** for help, and **q** or **Ctrl-C** to quit. Home/End and Page Up/Down work too. In day detail, movement keys scroll the details in short terminals. Press **e** to expand an error and read its recovery instructions. The TUI never writes bookings.
|
|
108
66
|
|
|
109
67
|
Interactive use requires terminal stdin and stdout. Piped calls fail before authentication. The bounded, plain-text snapshot mode requires `--demo`; JSON output is available through the regular commands. Human text output uses tables rather than raw JSON. Error code **6** means a terminal is required.
|
|
110
68
|
|
|
111
|
-
Output is JSON when piped and readable text on a terminal. Override with `--output json|text`. `schema` prints the clispec v0.3 contract; `completions zsh` generates shell completion definitions.
|
|
69
|
+
Output is JSON when piped and readable text on a terminal. Override with `--output json|text`. `schema` prints the clispec v0.3 contract; `completions zsh` generates shell completion definitions. Timesheet output contains account identifiers and should be kept private.
|
|
112
70
|
|
|
113
|
-
Exit codes: 0 success; 1 input/network/protocol/I/O error; 3 usage error; 4 authentication error
|
|
71
|
+
Exit codes: 0 success; 1 input/network/protocol/I/O error; 3 usage error; 4 authentication error. Errors are JSON envelopes on stderr.
|
|
114
72
|
|
|
115
|
-
Requires Rust 1.100 or later. Development: `cargo test`, `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`. `uv run --no-project --with pyte scripts/check_tui.py` exercises help, filtering, month navigation,
|
|
73
|
+
Requires Rust 1.100 or later. Development: `cargo test`, `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`. `uv run --no-project --with pyte scripts/check_tui.py` exercises help, filtering, month navigation, day detail, scrolling, Ctrl-C and terminal restoration in real pseudo-terminals at 120×36 and 40×16. CI runs this check too. HTTP tests use synthetic fixtures and a local mock server; no real timesheets are changed by tests.
|
|
116
74
|
|
|
117
75
|
MIT licensed.
|
|
118
76
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# yoobi-cli
|
|
2
|
+
|
|
3
|
+
A native Rust CLI for Yoobi's classic timesheet. Browse booked hours, activities and locked dates in your terminal, or read them as JSON for scripts. Save a login securely in your OS credential store.
|
|
4
|
+
|
|
5
|
+
Build and install locally:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
cargo install --path . --locked
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Log in once. The command prompts for your URL, username and hidden password, verifies the login with Yoobi, then saves the password in the OS credential store (macOS Keychain, Windows Credential Manager or Linux Secret Service):
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
yoobi-cli auth login
|
|
15
|
+
# Or supply the non-secret fields and enter only your password:
|
|
16
|
+
yoobi-cli auth login --base-url https://your-company.yoobi.nl --username your-login
|
|
17
|
+
yoobi-cli auth status
|
|
18
|
+
yoobi-cli tui --month 2026-11
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Every later command reuses that login automatically. Only identity metadata is written to the platform's user config directory under `yoobi-cli/login.json`; the password stays in the OS credential store. `YOOBI_CONFIG_DIR` overrides that directory. `auth status` inspects local configuration without reading the keychain or contacting Yoobi; it does not verify that the saved password still exists or is accepted. `timesheet` verifies access. SSO/MFA-only login is not supported.
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
yoobi-cli auth logout # removes the saved password and login metadata
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
For scripts/CI, explicit `YOOBI_BASE_URL`, `YOOBI_USERNAME` and `YOOBI_PASSWORD` or `YOOBI_PASSWORD_FILE` remain supported. Set only one password source. Password files must be regular files with no group/world permissions (`chmod 600`). Identity fields default to the saved profile, but a saved password is never reused for a different URL or username. Logout leaves environment variables untouched. With no OS credential store available, keep using explicit environment credentials; the CLI does not silently write a plaintext password file.
|
|
28
|
+
|
|
29
|
+
To save credentials noninteractively, set those environment variables and run `auth login`, or pipe a password manager's output to `auth login --base-url URL --username USER --password-stdin`. Password input is bounded to 16 KiB; `--password-stdin` conflicts with environment password sources. There is no password command-line argument. Prompts and errors stay on stderr; passwords are never printed.
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
yoobi-cli projects --month 2026-11
|
|
33
|
+
yoobi-cli timesheet --month 2026-11
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Interactive review
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
yoobi-cli tui --demo # offline sample timesheet
|
|
40
|
+
yoobi-cli tui --month 2026-11 # connected, read only
|
|
41
|
+
yoobi-cli tui --demo --snapshot --month 2026-11 --width 120 --height 36
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The default TUI shows activities, daily booked hours and locked dates. It adapts from 40-column terminals to a three-pane workspace. The demo is always labelled and does not read credentials or send requests. Connected reads happen in a background worker. If a refresh fails, its error stays visible and can be retried.
|
|
45
|
+
|
|
46
|
+
Use **↑/↓** or **j/k** for days, **Tab/Shift-Tab** for activities, **Enter** for day detail/back, **[ / ]** for months, **/** to find a date, **r** to refresh, **?** for help, and **q** or **Ctrl-C** to quit. Home/End and Page Up/Down work too. In day detail, movement keys scroll the details in short terminals. Press **e** to expand an error and read its recovery instructions. The TUI never writes bookings.
|
|
47
|
+
|
|
48
|
+
Interactive use requires terminal stdin and stdout. Piped calls fail before authentication. The bounded, plain-text snapshot mode requires `--demo`; JSON output is available through the regular commands. Human text output uses tables rather than raw JSON. Error code **6** means a terminal is required.
|
|
49
|
+
|
|
50
|
+
Output is JSON when piped and readable text on a terminal. Override with `--output json|text`. `schema` prints the clispec v0.3 contract; `completions zsh` generates shell completion definitions. Timesheet output contains account identifiers and should be kept private.
|
|
51
|
+
|
|
52
|
+
Exit codes: 0 success; 1 input/network/protocol/I/O error; 3 usage error; 4 authentication error. Errors are JSON envelopes on stderr.
|
|
53
|
+
|
|
54
|
+
Requires Rust 1.100 or later. Development: `cargo test`, `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`. `uv run --no-project --with pyte scripts/check_tui.py` exercises help, filtering, month navigation, day detail, scrolling, Ctrl-C and terminal restoration in real pseudo-terminals at 120×36 and 40×16. CI runs this check too. HTTP tests use synthetic fixtures and a local mock server; no real timesheets are changed by tests.
|
|
55
|
+
|
|
56
|
+
MIT licensed.
|
|
@@ -5,7 +5,7 @@ build-backend = "maturin"
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "yoobi-cli"
|
|
7
7
|
dynamic = ["version"]
|
|
8
|
-
description = "Read
|
|
8
|
+
description = "Read and browse Yoobi timesheets from the command line"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|
|
11
11
|
license = { text = "MIT" }
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
use crate::{
|
|
3
3
|
Error,
|
|
4
4
|
config::Config,
|
|
5
|
-
|
|
5
|
+
timesheet::{Project, Timesheet},
|
|
6
6
|
};
|
|
7
7
|
use regex::Regex;
|
|
8
8
|
use reqwest::{
|
|
@@ -22,29 +22,11 @@ pub struct Client {
|
|
|
22
22
|
config: Config,
|
|
23
23
|
employee_id: String,
|
|
24
24
|
}
|
|
25
|
-
#[derive(Clone)]
|
|
26
|
-
struct Cell {
|
|
27
|
-
project: String,
|
|
28
|
-
p: usize,
|
|
29
|
-
a: usize,
|
|
30
|
-
d: usize,
|
|
31
|
-
value: Value,
|
|
32
|
-
writable: bool,
|
|
33
|
-
}
|
|
34
|
-
struct Snapshot {
|
|
35
|
-
sheet: Timesheet,
|
|
36
|
-
cells: BTreeMap<(String, String), Cell>,
|
|
37
|
-
}
|
|
38
25
|
fn protocol(message: impl Into<String>) -> Error {
|
|
39
26
|
Error::Protocol {
|
|
40
27
|
message: message.into(),
|
|
41
28
|
}
|
|
42
29
|
}
|
|
43
|
-
fn conflict(message: impl Into<String>) -> Error {
|
|
44
|
-
Error::Conflict {
|
|
45
|
-
message: message.into(),
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
30
|
fn selector(s: &str) -> Selector {
|
|
49
31
|
Selector::parse(s).expect("constant CSS selector")
|
|
50
32
|
}
|
|
@@ -146,10 +128,10 @@ impl Client {
|
|
|
146
128
|
body(r, "read")
|
|
147
129
|
}
|
|
148
130
|
pub fn timesheet(&self, month: &str) -> Result<Timesheet, Error> {
|
|
149
|
-
|
|
131
|
+
self.snapshot(month)
|
|
150
132
|
}
|
|
151
|
-
fn snapshot(&self, month: &str) -> Result<
|
|
152
|
-
crate::
|
|
133
|
+
fn snapshot(&self, month: &str) -> Result<Timesheet, Error> {
|
|
134
|
+
crate::timesheet::validate_month(month)?;
|
|
153
135
|
let (year, m) = month
|
|
154
136
|
.split_once('-')
|
|
155
137
|
.ok_or_else(|| protocol("invalid month"))?;
|
|
@@ -175,112 +157,9 @@ impl Client {
|
|
|
175
157
|
let html = body(r, "timesheet read")?;
|
|
176
158
|
parse_grid(&html, &self.config.base_url, &self.employee_id, month)
|
|
177
159
|
}
|
|
178
|
-
pub fn apply(&self, plan: &Plan) -> Result<ApplyResult, Error> {
|
|
179
|
-
plan.validate()?;
|
|
180
|
-
if plan.base_url != self.config.base_url || plan.employee_id != self.employee_id {
|
|
181
|
-
return Err(conflict(
|
|
182
|
-
"plan belongs to a different Yoobi origin or employee",
|
|
183
|
-
));
|
|
184
|
-
}
|
|
185
|
-
let before = self.snapshot(&plan.month)?;
|
|
186
|
-
let project = before
|
|
187
|
-
.sheet
|
|
188
|
-
.projects
|
|
189
|
-
.iter()
|
|
190
|
-
.find(|p| p.id == plan.project_id)
|
|
191
|
-
.ok_or_else(|| conflict("booking activity no longer exists"))?;
|
|
192
|
-
let mut payload = Vec::new();
|
|
193
|
-
for day in &plan.days {
|
|
194
|
-
let cell = before
|
|
195
|
-
.cells
|
|
196
|
-
.get(&(plan.project_id.clone(), day.date.clone()))
|
|
197
|
-
.ok_or_else(|| conflict(format!("{} is missing from the timesheet", day.date)))?;
|
|
198
|
-
let minutes = *project
|
|
199
|
-
.days
|
|
200
|
-
.get(&day.date)
|
|
201
|
-
.ok_or_else(|| conflict("missing day"))?;
|
|
202
|
-
let desired = u32::from(day.hours) * 60;
|
|
203
|
-
if minutes == desired {
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
if minutes != day.before_minutes {
|
|
207
|
-
return Err(conflict(format!(
|
|
208
|
-
"{} changed since the plan was created",
|
|
209
|
-
day.date
|
|
210
|
-
)));
|
|
211
|
-
}
|
|
212
|
-
if !cell.writable {
|
|
213
|
-
return Err(conflict(format!(
|
|
214
|
-
"{} is locked or requires unsupported booking details",
|
|
215
|
-
day.date
|
|
216
|
-
)));
|
|
217
|
-
}
|
|
218
|
-
let diff = f64::from(desired) / 60.0 - f64::from(minutes) / 60.0;
|
|
219
|
-
payload.push(json!({"key":format!("{}-{}",plan.project_id,day.date),"value":[{
|
|
220
|
-
"time":day.hours,"timeMsg":cell.value.get("timeMsg").cloned().unwrap_or(json!("")),
|
|
221
|
-
"p":cell.p,"a":cell.a,"d":cell.d,"ref":cell.value.get("ref").cloned().unwrap_or(json!("")),
|
|
222
|
-
"timediff":diff,"pID":cell.project,"bFromPlanning":false,"timedifforiginal":diff
|
|
223
|
-
}]}));
|
|
224
|
-
}
|
|
225
|
-
let count = payload.len();
|
|
226
|
-
if count > 0 {
|
|
227
|
-
let response=self.http.post(format!("{}/declaration/saveDeclarations",self.config.base_url))
|
|
228
|
-
.form(&[("json",json!(payload).to_string()),("employeeID",self.employee_id.clone()),("directSave","true".into())])
|
|
229
|
-
.send().map_err(|_|Error::Network {message:"Yoobi save was interrupted; some entries may have been saved. Read the timesheet before retrying".into()})?;
|
|
230
|
-
let value: Value =
|
|
231
|
-
serde_json::from_str(&body(response, "save (entries may already have changed)")?)
|
|
232
|
-
.map_err(|_| {
|
|
233
|
-
protocol("unrecognized save response; read the timesheet before retrying")
|
|
234
|
-
})?;
|
|
235
|
-
let messages = value["messages"]
|
|
236
|
-
.as_array()
|
|
237
|
-
.filter(|m| !m.is_empty())
|
|
238
|
-
.ok_or_else(|| {
|
|
239
|
-
protocol(
|
|
240
|
-
"save response has no acknowledgement; read the timesheet before retrying",
|
|
241
|
-
)
|
|
242
|
-
})?;
|
|
243
|
-
if messages.iter().any(|m| m["type"] != "success") {
|
|
244
|
-
return Err(conflict(
|
|
245
|
-
"Yoobi rejected all or part of the save; read the timesheet before retrying",
|
|
246
|
-
));
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
let after = self.snapshot(&plan.month)?.sheet;
|
|
250
|
-
let mut expected = before.sheet;
|
|
251
|
-
let project = expected
|
|
252
|
-
.projects
|
|
253
|
-
.iter_mut()
|
|
254
|
-
.find(|p| p.id == plan.project_id)
|
|
255
|
-
.expect("validated project");
|
|
256
|
-
for day in &plan.days {
|
|
257
|
-
project
|
|
258
|
-
.days
|
|
259
|
-
.insert(day.date.clone(), u32::from(day.hours) * 60);
|
|
260
|
-
}
|
|
261
|
-
// Names and lock states can change independently. Check every booking, including untargeted days.
|
|
262
|
-
if after.projects.len() != expected.projects.len()
|
|
263
|
-
|| after.projects.iter().any(|p| {
|
|
264
|
-
expected
|
|
265
|
-
.projects
|
|
266
|
-
.iter()
|
|
267
|
-
.find(|e| e.id == p.id)
|
|
268
|
-
.is_none_or(|e| e.days != p.days)
|
|
269
|
-
})
|
|
270
|
-
{
|
|
271
|
-
return Err(conflict(
|
|
272
|
-
"saved timesheet does not match the plan or another booking changed; inspect it before retrying",
|
|
273
|
-
));
|
|
274
|
-
}
|
|
275
|
-
Ok(ApplyResult {
|
|
276
|
-
verified: true,
|
|
277
|
-
changed_days: count,
|
|
278
|
-
timesheet: after,
|
|
279
|
-
})
|
|
280
|
-
}
|
|
281
160
|
}
|
|
282
161
|
|
|
283
|
-
fn parse_grid(html: &str, base: &str, employee: &str, month: &str) -> Result<
|
|
162
|
+
fn parse_grid(html: &str, base: &str, employee: &str, month: &str) -> Result<Timesheet, Error> {
|
|
284
163
|
let doc = Html::parse_document(html);
|
|
285
164
|
let node = doc.select(&selector("#stData")).next().ok_or_else(|| {
|
|
286
165
|
protocol("Yoobi did not return timesheet data; session expired or format changed")
|
|
@@ -292,7 +171,7 @@ fn parse_grid(html: &str, base: &str, employee: &str, month: &str) -> Result<Sna
|
|
|
292
171
|
.ok_or_else(|| protocol("missing timesheet projects"))?;
|
|
293
172
|
let date_re = Regex::new(r"date:\s*'(\d{4}-\d{2}-\d{2})'").expect("constant date regex");
|
|
294
173
|
let mut projects = Vec::new();
|
|
295
|
-
let mut
|
|
174
|
+
let mut activity_dates = BTreeSet::new();
|
|
296
175
|
let mut total = 0u32;
|
|
297
176
|
for (p, raw) in raw_projects.iter().enumerate().skip(1) {
|
|
298
177
|
let project_id = raw["pID"]
|
|
@@ -324,10 +203,6 @@ fn parse_grid(html: &str, base: &str, employee: &str, month: &str) -> Result<Sna
|
|
|
324
203
|
"only hour-based timesheet activities are supported",
|
|
325
204
|
));
|
|
326
205
|
}
|
|
327
|
-
let restricted = act["allowOvertime"].as_i64().unwrap_or(0) != 0
|
|
328
|
-
|| !act["defaultOvertimeID"].as_str().unwrap_or("").is_empty()
|
|
329
|
-
|| cls.contains("bNoteRequired:true")
|
|
330
|
-
|| !cls.contains("alttype:[]");
|
|
331
206
|
let mut locks = BTreeSet::new();
|
|
332
207
|
let mut seen = BTreeSet::new();
|
|
333
208
|
for cell in row.select(&selector("div.cell")) {
|
|
@@ -339,10 +214,9 @@ fn parse_grid(html: &str, base: &str, employee: &str, month: &str) -> Result<Sna
|
|
|
339
214
|
if !seen.insert(date.clone()) {
|
|
340
215
|
return Err(protocol("duplicate timesheet day"));
|
|
341
216
|
}
|
|
342
|
-
if
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
.any(|c| matches!(c, "disabled" | "closed" | "approved" | "wasApproved"))
|
|
217
|
+
if class
|
|
218
|
+
.split_whitespace()
|
|
219
|
+
.any(|c| matches!(c, "disabled" | "closed" | "approved" | "wasApproved"))
|
|
346
220
|
|| cell
|
|
347
221
|
.value()
|
|
348
222
|
.attr("data-warn")
|
|
@@ -352,11 +226,10 @@ fn parse_grid(html: &str, base: &str, employee: &str, month: &str) -> Result<Sna
|
|
|
352
226
|
}
|
|
353
227
|
}
|
|
354
228
|
let mut days = BTreeMap::new();
|
|
355
|
-
for
|
|
229
|
+
for entry in act["decl"]
|
|
356
230
|
.as_array()
|
|
357
231
|
.ok_or_else(|| protocol("missing declarations"))?
|
|
358
232
|
.iter()
|
|
359
|
-
.enumerate()
|
|
360
233
|
.skip(1)
|
|
361
234
|
{
|
|
362
235
|
let date = entry["dtdate"]
|
|
@@ -365,7 +238,7 @@ fn parse_grid(html: &str, base: &str, employee: &str, month: &str) -> Result<Sna
|
|
|
365
238
|
if !date.starts_with(&format!("{month}-")) {
|
|
366
239
|
continue;
|
|
367
240
|
}
|
|
368
|
-
crate::
|
|
241
|
+
crate::timesheet::validate_date(date)?;
|
|
369
242
|
if !seen.contains(date) {
|
|
370
243
|
return Err(protocol("declaration missing from rendered grid"));
|
|
371
244
|
}
|
|
@@ -376,24 +249,11 @@ fn parse_grid(html: &str, base: &str, employee: &str, month: &str) -> Result<Sna
|
|
|
376
249
|
total = total
|
|
377
250
|
.checked_add(minutes)
|
|
378
251
|
.ok_or_else(|| protocol("timesheet total overflow"))?;
|
|
379
|
-
if
|
|
380
|
-
.insert(
|
|
381
|
-
(id.clone(), date.to_owned()),
|
|
382
|
-
Cell {
|
|
383
|
-
project: project_id.to_owned(),
|
|
384
|
-
p,
|
|
385
|
-
a,
|
|
386
|
-
d,
|
|
387
|
-
value: entry.clone(),
|
|
388
|
-
writable: !locks.contains(date),
|
|
389
|
-
},
|
|
390
|
-
)
|
|
391
|
-
.is_some()
|
|
392
|
-
{
|
|
252
|
+
if !activity_dates.insert((id.clone(), date.to_owned())) {
|
|
393
253
|
return Err(protocol("ambiguous activity ID"));
|
|
394
254
|
}
|
|
395
255
|
}
|
|
396
|
-
let month_days = crate::
|
|
256
|
+
let month_days = crate::timesheet::days_in_month(month)?;
|
|
397
257
|
if days.len() != month_days as usize {
|
|
398
258
|
return Err(protocol(
|
|
399
259
|
"timesheet grid does not cover the requested month",
|
|
@@ -426,14 +286,11 @@ fn parse_grid(html: &str, base: &str, employee: &str, month: &str) -> Result<Sna
|
|
|
426
286
|
if total != official || visible != official {
|
|
427
287
|
return Err(protocol("Yoobi month total disagrees with daily entries"));
|
|
428
288
|
}
|
|
429
|
-
Ok(
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
projects,
|
|
436
|
-
},
|
|
437
|
-
cells,
|
|
289
|
+
Ok(Timesheet {
|
|
290
|
+
base_url: base.into(),
|
|
291
|
+
employee_id: employee.into(),
|
|
292
|
+
month: month.into(),
|
|
293
|
+
total_minutes: official,
|
|
294
|
+
projects,
|
|
438
295
|
})
|
|
439
296
|
}
|
|
@@ -16,8 +16,6 @@ pub enum Error {
|
|
|
16
16
|
#[error("{message}")]
|
|
17
17
|
Protocol { message: String },
|
|
18
18
|
#[error("{message}")]
|
|
19
|
-
Conflict { message: String },
|
|
20
|
-
#[error("{message}")]
|
|
21
19
|
Io { message: String },
|
|
22
20
|
}
|
|
23
21
|
|
|
@@ -30,7 +28,6 @@ impl Error {
|
|
|
30
28
|
Self::Auth { .. } => "auth",
|
|
31
29
|
Self::Network { .. } => "network",
|
|
32
30
|
Self::Protocol { .. } => "protocol",
|
|
33
|
-
Self::Conflict { .. } => "conflict",
|
|
34
31
|
Self::Io { .. } => "io",
|
|
35
32
|
}
|
|
36
33
|
}
|
|
@@ -40,11 +37,8 @@ impl Error {
|
|
|
40
37
|
Self::Auth { .. } => Some(
|
|
41
38
|
"run `yoobi-cli auth login`, or set YOOBI_BASE_URL, YOOBI_USERNAME, and a password source",
|
|
42
39
|
),
|
|
43
|
-
Self::Conflict { .. } => {
|
|
44
|
-
Some("read the timesheet and generate a new plan; do not blindly retry a write")
|
|
45
|
-
}
|
|
46
40
|
Self::Network { .. } | Self::Protocol { .. } => {
|
|
47
|
-
Some("
|
|
41
|
+
Some("check the connection and Yoobi availability before retrying")
|
|
48
42
|
}
|
|
49
43
|
Self::TtyRequired { .. } => Some(
|
|
50
44
|
"run the interactive command in a terminal; scripts can use auth login --password-stdin or tui --demo --snapshot",
|
|
@@ -57,7 +51,6 @@ impl Error {
|
|
|
57
51
|
Self::Usage { .. } => 3,
|
|
58
52
|
Self::TtyRequired { .. } => 6,
|
|
59
53
|
Self::Auth { .. } => 4,
|
|
60
|
-
Self::Conflict { .. } => 5,
|
|
61
54
|
_ => 1,
|
|
62
55
|
}
|
|
63
56
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
//! Yoobi timesheets
|
|
1
|
+
//! Read-only Yoobi timesheets and secure authentication.
|
|
2
2
|
pub mod api;
|
|
3
3
|
pub mod config;
|
|
4
4
|
mod error;
|
|
5
|
-
pub mod plan;
|
|
6
5
|
pub mod schema;
|
|
6
|
+
pub mod timesheet;
|
|
7
7
|
pub use error::Error;
|
|
8
8
|
|
|
9
9
|
pub mod output;
|
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
//! Agent-friendly command interface: text on a terminal, JSON when piped.
|
|
2
2
|
use clap::error::ErrorKind as ClapErrorKind;
|
|
3
3
|
use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
|
|
4
|
-
use serde::de::DeserializeOwned;
|
|
5
4
|
use serde_json::{Value, json};
|
|
6
5
|
use std::io::{IsTerminal, Write};
|
|
7
|
-
use std::path::Path;
|
|
8
6
|
use std::process::ExitCode;
|
|
9
|
-
use yoobi_cli::{
|
|
10
|
-
Error,
|
|
11
|
-
api::Client,
|
|
12
|
-
config::Config,
|
|
13
|
-
plan::{Ledger, Plan, WorkInput, validate_month},
|
|
14
|
-
schema,
|
|
15
|
-
};
|
|
7
|
+
use yoobi_cli::{Error, api::Client, config::Config, schema, timesheet::validate_month};
|
|
16
8
|
|
|
17
9
|
#[derive(Parser)]
|
|
18
10
|
#[command(
|
|
19
11
|
name = "yoobi-cli",
|
|
20
12
|
version,
|
|
21
|
-
about = "Read
|
|
22
|
-
long_about = "Read
|
|
13
|
+
about = "Read and browse Yoobi timesheets",
|
|
14
|
+
long_about = "Read and browse Yoobi timesheets.\n\nRun `yoobi-cli schema` for the machine-readable contract."
|
|
23
15
|
)]
|
|
24
16
|
struct Cli {
|
|
25
17
|
#[command(subcommand)]
|
|
@@ -46,20 +38,6 @@ enum Command {
|
|
|
46
38
|
#[arg(long)]
|
|
47
39
|
month: String,
|
|
48
40
|
},
|
|
49
|
-
/// Read actual work records and produce a reviewed plan against a fresh timesheet.
|
|
50
|
-
Plan { file: std::path::PathBuf },
|
|
51
|
-
/// Apply a plan with stale-state checks and a fresh verification read.
|
|
52
|
-
Apply {
|
|
53
|
-
file: std::path::PathBuf,
|
|
54
|
-
/// Explicitly authorize the writes in this plan.
|
|
55
|
-
#[arg(long, conflicts_with = "dry_run")]
|
|
56
|
-
yes: bool,
|
|
57
|
-
/// Validate the plan locally and show its totals; send no requests.
|
|
58
|
-
#[arg(long)]
|
|
59
|
-
dry_run: bool,
|
|
60
|
-
},
|
|
61
|
-
/// Calculate actual minus booked minutes from a ledger or booking plan, offline.
|
|
62
|
-
Balance { file: std::path::PathBuf },
|
|
63
41
|
/// Save, inspect or remove a login in the OS credential store.
|
|
64
42
|
Auth {
|
|
65
43
|
#[command(subcommand)]
|
|
@@ -67,13 +45,11 @@ enum Command {
|
|
|
67
45
|
},
|
|
68
46
|
/// Print the machine-readable clispec contract.
|
|
69
47
|
Schema,
|
|
70
|
-
/// Browse
|
|
48
|
+
/// Browse booked hours and locked dates in a read-only keyboard workspace.
|
|
71
49
|
Tui {
|
|
72
50
|
#[arg(long)]
|
|
73
51
|
month: Option<String>,
|
|
74
52
|
#[arg(long)]
|
|
75
|
-
plan: Option<std::path::PathBuf>,
|
|
76
|
-
#[arg(long)]
|
|
77
53
|
demo: bool,
|
|
78
54
|
#[arg(long, requires = "demo")]
|
|
79
55
|
snapshot: bool,
|
|
@@ -105,14 +81,6 @@ enum AuthCommand {
|
|
|
105
81
|
Status,
|
|
106
82
|
}
|
|
107
83
|
|
|
108
|
-
fn read<T: DeserializeOwned>(path: &Path) -> Result<T, Error> {
|
|
109
|
-
let bytes = std::fs::read(path).map_err(|_| Error::Io {
|
|
110
|
-
message: "cannot read the input file".into(),
|
|
111
|
-
})?;
|
|
112
|
-
serde_json::from_slice(&bytes).map_err(|_| Error::InvalidInput {
|
|
113
|
-
message: "input file does not match the command's JSON format".into(),
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
84
|
fn client() -> Result<Client, Error> {
|
|
117
85
|
Client::new(&Config::load()?)
|
|
118
86
|
}
|
|
@@ -129,43 +97,6 @@ fn dispatch(command: Command) -> Result<Value, Error> {
|
|
|
129
97
|
json!({"month":sheet.month,"employee_id":sheet.employee_id,"projects":sheet.projects.iter().map(|p|json!({"id":p.id,"name":p.name})).collect::<Vec<_>>()}),
|
|
130
98
|
)
|
|
131
99
|
}
|
|
132
|
-
Command::Plan { file } => {
|
|
133
|
-
let input: WorkInput = read(&file)?;
|
|
134
|
-
validate_month(&input.month)?;
|
|
135
|
-
let sheet = client()?.timesheet(&input.month)?;
|
|
136
|
-
Ok(json!(Plan::build(input, &sheet)?))
|
|
137
|
-
}
|
|
138
|
-
Command::Apply { file, yes, dry_run } => {
|
|
139
|
-
if !yes && !dry_run {
|
|
140
|
-
return Err(Error::Usage {
|
|
141
|
-
message: "apply requires --yes or --dry-run".into(),
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
let plan: Plan = read(&file)?;
|
|
145
|
-
plan.validate()?;
|
|
146
|
-
if dry_run {
|
|
147
|
-
Ok(json!({"dry_run":true,"plan":plan,"balance":plan.balance()?}))
|
|
148
|
-
} else {
|
|
149
|
-
Ok(json!(client()?.apply(&plan)?))
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
Command::Balance { file } => {
|
|
153
|
-
let value: Value = read(&file)?;
|
|
154
|
-
let balance = if value.get("version").is_some() {
|
|
155
|
-
serde_json::from_value::<Plan>(value)
|
|
156
|
-
.map_err(|_| Error::InvalidInput {
|
|
157
|
-
message: "invalid booking plan".into(),
|
|
158
|
-
})?
|
|
159
|
-
.balance()?
|
|
160
|
-
} else {
|
|
161
|
-
serde_json::from_value::<Ledger>(value)
|
|
162
|
-
.map_err(|_| Error::InvalidInput {
|
|
163
|
-
message: "invalid balance ledger".into(),
|
|
164
|
-
})?
|
|
165
|
-
.balance()?
|
|
166
|
-
};
|
|
167
|
-
Ok(json!(balance))
|
|
168
|
-
}
|
|
169
100
|
Command::Auth {
|
|
170
101
|
command:
|
|
171
102
|
AuthCommand::Login {
|
|
@@ -192,7 +123,6 @@ fn main() -> ExitCode {
|
|
|
192
123
|
};
|
|
193
124
|
if let Command::Tui {
|
|
194
125
|
month,
|
|
195
|
-
plan,
|
|
196
126
|
demo,
|
|
197
127
|
snapshot,
|
|
198
128
|
width,
|
|
@@ -200,19 +130,14 @@ fn main() -> ExitCode {
|
|
|
200
130
|
} = &cli.command
|
|
201
131
|
{
|
|
202
132
|
let result = (|| {
|
|
203
|
-
// Refuse piped interactive input before credentials
|
|
133
|
+
// Refuse piped interactive input before credentials are read.
|
|
204
134
|
if !snapshot && (!std::io::stdin().is_terminal() || !std::io::stdout().is_terminal()) {
|
|
205
135
|
return Err(Error::TtyRequired {
|
|
206
136
|
message: "tui requires terminal stdin and stdout".into(),
|
|
207
137
|
});
|
|
208
138
|
}
|
|
209
|
-
let plan = plan.as_ref().map(|p| read::<Plan>(p)).transpose()?;
|
|
210
139
|
let options = yoobi_cli::tui::Options {
|
|
211
|
-
month: month
|
|
212
|
-
.clone()
|
|
213
|
-
.or_else(|| plan.as_ref().map(|p| p.month.clone()))
|
|
214
|
-
.unwrap_or_else(yoobi_cli::tui::current_month),
|
|
215
|
-
plan,
|
|
140
|
+
month: month.clone().unwrap_or_else(yoobi_cli::tui::current_month),
|
|
216
141
|
demo: *demo,
|
|
217
142
|
snapshot: *snapshot,
|
|
218
143
|
width: *width,
|